]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/kernel/v2_0/include/bitmap.hxx
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / kernel / v2_0 / include / bitmap.hxx
1 #ifndef CYGONCE_KERNEL_BITMAP_HXX
2 #define CYGONCE_KERNEL_BITMAP_HXX
3
4 //==========================================================================
5 //
6 //      bitmap.hxx
7 //
8 //      Bitmap scheduler class declaration(s)
9 //
10 //==========================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15 // Copyright (C) 2006 eCosCentric Limited
16 //
17 // eCos is free software; you can redistribute it and/or modify it under
18 // the terms of the GNU General Public License as published by the Free
19 // Software Foundation; either version 2 or (at your option) any later version.
20 //
21 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
22 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
23 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24 // for more details.
25 //
26 // You should have received a copy of the GNU General Public License along
27 // with eCos; if not, write to the Free Software Foundation, Inc.,
28 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 //
30 // As a special exception, if other files instantiate templates or use macros
31 // or inline functions from this file, or you compile this file and link it
32 // with other works to produce a work based on this file, this file does not
33 // by itself cause the resulting work to be covered by the GNU General Public
34 // License. However the source code for this file must still be made available
35 // in accordance with section (3) of the GNU General Public License.
36 //
37 // This exception does not invalidate any other reasons why a work based on
38 // this file might be covered by the GNU General Public License.
39 //
40 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
41 // at http://sources.redhat.com/ecos/ecos-license/
42 // -------------------------------------------
43 //####ECOSGPLCOPYRIGHTEND####
44 //==========================================================================
45 //#####DESCRIPTIONBEGIN####
46 //
47 // Author(s):   nickg
48 // Contributors:        nickg
49 // Date:        1997-09-10
50 // Purpose:     Define bitmap scheduler implementation
51 // Description: The classes defined here are used as base classes
52 //              by the common classes that define schedulers and thread
53 //              things.
54 // Usage:       Included according to configuration by
55 //              <cyg/kernel/sched.hxx>
56 //
57 //####DESCRIPTIONEND####
58 //
59 //==========================================================================
60
61 #include <cyg/kernel/ktypes.h>
62
63 // -------------------------------------------------------------------------
64 // The macro CYGNUM_KERNEL_SCHED_BITMAP_SIZE contains the number of bits 
65 // that the scheduler bitmap should contain. It is derived from the number
66 // of threads that the system is allowed to use during configuration.
67
68 #ifndef CYGNUM_KERNEL_SCHED_BITMAP_SIZE
69 #define CYGNUM_KERNEL_SCHED_BITMAP_SIZE 32
70 #endif
71
72 #if CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 8
73 typedef cyg_ucount8 cyg_sched_bitmap;
74 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 16
75 typedef cyg_ucount16 cyg_sched_bitmap;
76 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 32
77 typedef cyg_ucount32 cyg_sched_bitmap;
78 #else
79 #error Bitmaps greater than 32 bits not currently allowed
80 #endif
81
82 // -------------------------------------------------------------------------
83 // Customize the scheduler
84
85 #define CYGIMP_THREAD_PRIORITY  1
86
87 #define CYG_THREAD_MIN_PRIORITY (CYGNUM_KERNEL_SCHED_BITMAP_SIZE-1)
88 #define CYG_THREAD_MAX_PRIORITY 0
89
90 // set default scheduling info value for thread constructors.
91 #define CYG_SCHED_DEFAULT_INFO  CYG_THREAD_MAX_PRIORITY
92
93 // -------------------------------------------------------------------------
94 // This class contains the implementation details of the scheduler, and
95 // provides a standard API for accessing it.
96
97 class Cyg_Scheduler_Implementation
98     : public Cyg_Scheduler_Base
99 {
100     friend class Cyg_ThreadQueue_Implementation;
101     friend class Cyg_SchedThread_Implementation;
102     
103     cyg_sched_bitmap    run_queue;
104
105     Cyg_Thread          *thread_table[CYGNUM_KERNEL_SCHED_BITMAP_SIZE];
106
107     
108 protected:
109
110     Cyg_Scheduler_Implementation();     // Constructor
111     
112     // The following functions provide the scheduler implementation
113     // interface to the Cyg_Scheduler class. These are protected
114     // so that only the scheduler can call them.
115     
116     // choose a new thread
117     Cyg_Thread  *schedule();
118
119     // make thread schedulable
120     void        add_thread(Cyg_Thread *thread);
121
122     // make thread un-schedulable
123     void        rem_thread(Cyg_Thread *thread);
124
125     // register thread with scheduler
126     void        register_thread(Cyg_Thread *thread);
127
128     // deregister thread
129     void        deregister_thread(Cyg_Thread *thread);
130     
131     // Test the given priority for uniqueness
132     cyg_bool    unique( cyg_priority priority);
133
134 public:
135     void set_idle_thread( Cyg_Thread *thread, HAL_SMP_CPU_TYPE cpu );
136     
137 };
138
139 // -------------------------------------------------------------------------
140 // Scheduler thread implementation.
141 // This class provides the implementation of the scheduler specific parts
142 // of each thread.
143
144 class Cyg_SchedThread_Implementation
145 {
146     friend class Cyg_Scheduler_Implementation;
147     friend class Cyg_ThreadQueue_Implementation;
148     
149 protected:
150
151     cyg_priority        priority;       // current thread priority
152
153     Cyg_SchedThread_Implementation(CYG_ADDRWORD sched_info);
154
155     void yield();                       // Yield CPU to next thread
156
157     // These are not applicable in a bitmap scheduler; placeholders:
158     inline void rotate_queue( cyg_priority pri ) { };
159     inline void to_queue_head( void ) { };
160
161     inline void timeslice_save() {};
162     inline void timeslice_restore() {};
163     inline void timeslice_reset() {};
164     
165 };
166
167 // -------------------------------------------------------------------------
168 // Thread queue implementation.
169 // This class provides the (scheduler specific) implementation of the
170 // thread queue class.
171
172 class Cyg_ThreadQueue_Implementation
173 {
174     cyg_sched_bitmap    wait_queue;
175
176 protected:
177
178     // API used by Cyg_ThreadQueue
179
180     Cyg_ThreadQueue_Implementation();   // Constructor
181     
182                                         // Add thread to queue
183     void                enqueue(Cyg_Thread *thread);
184
185                                         // return first thread on queue
186     Cyg_Thread          *highpri();
187
188                                         // remove first thread on queue    
189     Cyg_Thread          *dequeue();
190
191                                         // remove specified thread from queue    
192     void                remove(Cyg_Thread *thread);
193
194                                         // test if queue is empty
195     cyg_bool            empty();
196
197 };
198
199 inline cyg_bool Cyg_ThreadQueue_Implementation::empty()
200 {
201     return wait_queue == 0;
202 }
203
204 // -------------------------------------------------------------------------
205
206 #endif // ifndef CYGONCE_KERNEL_BITMAP_HXX
207 // EOF bitmap.hxx