Mercurial > ecos-v2_0-branch
annotate packages/kernel/current/include/bitmap.hxx @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children | 0ae0bc38e387 |
| rev | line source |
|---|---|
| 0 | 1 #ifndef CYGONCE_KERNEL_BITMAP_HXX |
| 2 #define CYGONCE_KERNEL_BITMAP_HXX | |
| 3 | |
| 4 //========================================================================== | |
| 5 // | |
| 2 | 6 // bitmap.hxx |
| 0 | 7 // |
| 2 | 8 // Bitmap scheduler class declaration(s) |
| 0 | 9 // |
| 10 //========================================================================== | |
| 11 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
12 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
13 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
14 // The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
15 // Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
16 // compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
17 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
19 // Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
21 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
22 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
24 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
25 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
26 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
27 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
28 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
29 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
30 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
31 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
32 // |
| 0 | 33 //####COPYRIGHTEND#### |
| 34 //========================================================================== | |
| 35 //#####DESCRIPTIONBEGIN#### | |
| 36 // | |
| 2 | 37 // Author(s): nickg |
| 38 // Contributors: nickg | |
| 39 // Date: 1997-09-10 | |
| 40 // Purpose: Define bitmap scheduler implementation | |
| 41 // Description: The classes defined here are used as base classes | |
| 0 | 42 // by the common classes that define schedulers and thread |
| 43 // things. | |
| 44 // Usage: Included according to configuration by | |
| 45 // <cyg/kernel/sched.hxx> | |
| 46 // | |
| 47 //####DESCRIPTIONEND#### | |
| 48 // | |
| 49 //========================================================================== | |
| 50 | |
| 51 #include <cyg/kernel/ktypes.h> | |
| 52 | |
| 53 // ------------------------------------------------------------------------- | |
| 54 // The macro CYGNUM_KERNEL_SCHED_BITMAP_SIZE contains the number of bits | |
| 55 // that the scheduler bitmap should contain. It is derived from the number | |
| 56 // of threads that the system is allowed to use during configuration. | |
| 57 | |
| 58 #ifndef CYGNUM_KERNEL_SCHED_BITMAP_SIZE | |
| 59 #define CYGNUM_KERNEL_SCHED_BITMAP_SIZE 32 | |
| 60 #endif | |
| 61 | |
| 62 #if CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 8 | |
| 63 typedef cyg_ucount8 cyg_sched_bitmap; | |
| 64 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 16 | |
| 65 typedef cyg_ucount16 cyg_sched_bitmap; | |
| 66 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 32 | |
| 67 typedef cyg_ucount32 cyg_sched_bitmap; | |
| 68 #else | |
| 69 #error Bitmaps greater than 32 bits not currently allowed | |
| 70 #endif | |
| 71 | |
| 72 // ------------------------------------------------------------------------- | |
| 73 // Customize the scheduler | |
| 74 | |
| 75 #define CYGIMP_THREAD_PRIORITY 1 | |
| 76 #define CYG_SCHED_UNIQUE_PRIORITIES 1 | |
| 77 | |
| 78 #define CYG_THREAD_MIN_PRIORITY (CYGNUM_KERNEL_SCHED_BITMAP_SIZE-1) | |
| 79 #define CYG_THREAD_MAX_PRIORITY 0 | |
| 80 | |
| 81 // set default scheduling info value for thread constructors. | |
| 82 #define CYG_SCHED_DEFAULT_INFO CYG_THREAD_MAX_PRIORITY | |
| 83 | |
| 84 // ------------------------------------------------------------------------- | |
| 85 // This class contains the implementation details of the scheduler, and | |
| 86 // provides a standard API for accessing it. | |
| 87 | |
| 88 class Cyg_Scheduler_Implementation | |
| 89 : public Cyg_Scheduler_Base | |
| 90 { | |
| 91 friend class Cyg_ThreadQueue_Implementation; | |
| 92 friend class Cyg_SchedThread_Implementation; | |
| 93 | |
| 94 cyg_sched_bitmap run_queue; | |
| 95 | |
| 96 Cyg_Thread *thread_table[CYGNUM_KERNEL_SCHED_BITMAP_SIZE]; | |
| 97 | |
| 98 | |
| 99 protected: | |
| 100 | |
| 101 Cyg_Scheduler_Implementation(); // Constructor | |
| 102 | |
| 103 // The following functions provide the scheduler implementation | |
| 104 // interface to the Cyg_Scheduler class. These are protected | |
| 105 // so that only the scheduler can call them. | |
| 106 | |
| 107 // choose a new thread | |
| 108 Cyg_Thread *schedule(); | |
| 109 | |
| 110 // make thread schedulable | |
| 111 void add_thread(Cyg_Thread *thread); | |
| 112 | |
| 113 // make thread un-schedulable | |
| 114 void rem_thread(Cyg_Thread *thread); | |
| 115 | |
| 116 // register thread with scheduler | |
| 117 void register_thread(Cyg_Thread *thread); | |
| 118 | |
| 119 // deregister thread | |
| 120 void deregister_thread(Cyg_Thread *thread); | |
| 121 | |
| 122 // Test the given priority for uniqueness | |
| 123 cyg_bool unique( cyg_priority priority); | |
| 124 | |
| 125 }; | |
| 126 | |
| 127 // ------------------------------------------------------------------------- | |
| 128 // Scheduler thread implementation. | |
| 129 // This class provides the implementation of the scheduler specific parts | |
| 130 // of each thread. | |
| 131 | |
| 132 class Cyg_SchedThread_Implementation | |
| 133 { | |
| 134 friend class Cyg_Scheduler_Implementation; | |
| 135 friend class Cyg_ThreadQueue_Implementation; | |
| 136 | |
| 137 protected: | |
| 138 | |
| 139 cyg_priority priority; // current thread priority | |
| 140 | |
| 141 Cyg_SchedThread_Implementation(CYG_ADDRWORD sched_info); | |
| 142 | |
| 143 void yield(); // Yield CPU to next thread | |
| 144 | |
| 2 | 145 // These are not applicable in a bitmap scheduler; placeholders: |
| 146 inline void rotate_queue( cyg_priority pri ) { }; | |
| 147 inline void to_queue_head( void ) { }; | |
| 0 | 148 }; |
| 149 | |
| 150 // ------------------------------------------------------------------------- | |
| 151 // Thread queue implementation. | |
| 152 // This class provides the (scheduler specific) implementation of the | |
| 153 // thread queue class. | |
| 154 | |
| 155 class Cyg_ThreadQueue_Implementation | |
| 156 { | |
| 157 cyg_sched_bitmap wait_queue; | |
| 158 | |
| 159 protected: | |
| 160 | |
| 161 // API used by Cyg_ThreadQueue | |
| 162 | |
| 163 Cyg_ThreadQueue_Implementation(); // Constructor | |
| 164 | |
| 165 // Add thread to queue | |
| 166 void enqueue(Cyg_Thread *thread); | |
| 167 | |
| 168 // return first thread on queue | |
| 169 Cyg_Thread *highpri(); | |
| 170 | |
| 171 // remove first thread on queue | |
| 172 Cyg_Thread *dequeue(); | |
| 173 | |
| 174 // remove specified thread from queue | |
| 175 void remove(Cyg_Thread *thread); | |
| 176 | |
| 177 // test if queue is empty | |
| 178 cyg_bool empty(); | |
| 179 | |
| 180 }; | |
| 181 | |
| 182 inline cyg_bool Cyg_ThreadQueue_Implementation::empty() | |
| 183 { | |
| 184 return wait_queue == 0; | |
| 185 } | |
| 186 | |
| 187 // ------------------------------------------------------------------------- | |
| 188 | |
| 189 #endif // ifndef CYGONCE_KERNEL_BITMAP_HXX | |
| 190 // EOF bitmap.hxx |
