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