Mercurial > flash_v2
annotate packages/kernel/current/include/bitmap.hxx @ 132:0ae0bc38e387 ecos-sw-2000-10-31
Merge from eCos master repository on 2000-10-31-00:30:36-GMT
| author | jlarmour |
|---|---|
| date | Tue, 31 Oct 2000 20:53:09 +0000 |
| parents | bf00f99aec69 |
| children | 4c750ce71ae3 |
| 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 | |
| 77 #define CYG_THREAD_MIN_PRIORITY (CYGNUM_KERNEL_SCHED_BITMAP_SIZE-1) | |
| 78 #define CYG_THREAD_MAX_PRIORITY 0 | |
| 79 | |
| 80 // set default scheduling info value for thread constructors. | |
| 81 #define CYG_SCHED_DEFAULT_INFO CYG_THREAD_MAX_PRIORITY | |
| 82 | |
| 83 // ------------------------------------------------------------------------- | |
| 84 // This class contains the implementation details of the scheduler, and | |
| 85 // provides a standard API for accessing it. | |
| 86 | |
| 87 class Cyg_Scheduler_Implementation | |
| 88 : public Cyg_Scheduler_Base | |
| 89 { | |
| 90 friend class Cyg_ThreadQueue_Implementation; | |
| 91 friend class Cyg_SchedThread_Implementation; | |
| 92 | |
| 93 cyg_sched_bitmap run_queue; | |
| 94 | |
| 95 Cyg_Thread *thread_table[CYGNUM_KERNEL_SCHED_BITMAP_SIZE]; | |
| 96 | |
| 97 | |
| 98 protected: | |
| 99 | |
| 100 Cyg_Scheduler_Implementation(); // Constructor | |
| 101 | |
| 102 // The following functions provide the scheduler implementation | |
| 103 // interface to the Cyg_Scheduler class. These are protected | |
| 104 // so that only the scheduler can call them. | |
| 105 | |
| 106 // choose a new thread | |
| 107 Cyg_Thread *schedule(); | |
| 108 | |
| 109 // make thread schedulable | |
| 110 void add_thread(Cyg_Thread *thread); | |
| 111 | |
| 112 // make thread un-schedulable | |
| 113 void rem_thread(Cyg_Thread *thread); | |
| 114 | |
| 115 // register thread with scheduler | |
| 116 void register_thread(Cyg_Thread *thread); | |
| 117 | |
| 118 // deregister thread | |
| 119 void deregister_thread(Cyg_Thread *thread); | |
| 120 | |
| 121 // Test the given priority for uniqueness | |
| 122 cyg_bool unique( cyg_priority priority); | |
| 123 | |
| 124 }; | |
| 125 | |
| 126 // ------------------------------------------------------------------------- | |
| 127 // Scheduler thread implementation. | |
| 128 // This class provides the implementation of the scheduler specific parts | |
| 129 // of each thread. | |
| 130 | |
| 131 class Cyg_SchedThread_Implementation | |
| 132 { | |
| 133 friend class Cyg_Scheduler_Implementation; | |
| 134 friend class Cyg_ThreadQueue_Implementation; | |
| 135 | |
| 136 protected: | |
| 137 | |
| 138 cyg_priority priority; // current thread priority | |
| 139 | |
| 140 Cyg_SchedThread_Implementation(CYG_ADDRWORD sched_info); | |
| 141 | |
| 142 void yield(); // Yield CPU to next thread | |
| 143 | |
| 2 | 144 // These are not applicable in a bitmap scheduler; placeholders: |
| 145 inline void rotate_queue( cyg_priority pri ) { }; | |
| 146 inline void to_queue_head( void ) { }; | |
| 0 | 147 }; |
| 148 | |
| 149 // ------------------------------------------------------------------------- | |
| 150 // Thread queue implementation. | |
| 151 // This class provides the (scheduler specific) implementation of the | |
| 152 // thread queue class. | |
| 153 | |
| 154 class Cyg_ThreadQueue_Implementation | |
| 155 { | |
| 156 cyg_sched_bitmap wait_queue; | |
| 157 | |
| 158 protected: | |
| 159 | |
| 160 // API used by Cyg_ThreadQueue | |
| 161 | |
| 162 Cyg_ThreadQueue_Implementation(); // Constructor | |
| 163 | |
| 164 // Add thread to queue | |
| 165 void enqueue(Cyg_Thread *thread); | |
| 166 | |
| 167 // return first thread on queue | |
| 168 Cyg_Thread *highpri(); | |
| 169 | |
| 170 // remove first thread on queue | |
| 171 Cyg_Thread *dequeue(); | |
| 172 | |
| 173 // remove specified thread from queue | |
| 174 void remove(Cyg_Thread *thread); | |
| 175 | |
| 176 // test if queue is empty | |
| 177 cyg_bool empty(); | |
| 178 | |
| 179 }; | |
| 180 | |
| 181 inline cyg_bool Cyg_ThreadQueue_Implementation::empty() | |
| 182 { | |
| 183 return wait_queue == 0; | |
| 184 } | |
| 185 | |
| 186 // ------------------------------------------------------------------------- | |
| 187 | |
| 188 #endif // ifndef CYGONCE_KERNEL_BITMAP_HXX | |
| 189 // EOF bitmap.hxx |
