1 #ifndef CYGONCE_KERNEL_BITMAP_HXX
2 #define CYGONCE_KERNEL_BITMAP_HXX
4 //==========================================================================
8 // Bitmap scheduler class declaration(s)
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.
16 // eCos is free software; you can redistribute it and/or modify it under
17 // the terms of the GNU General Public License as published by the Free
18 // Software Foundation; either version 2 or (at your option) any later version.
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 //==========================================================================
44 //#####DESCRIPTIONBEGIN####
47 // Contributors: nickg
49 // Purpose: Define bitmap scheduler implementation
50 // Description: The classes defined here are used as base classes
51 // by the common classes that define schedulers and thread
53 // Usage: Included according to configuration by
54 // <cyg/kernel/sched.hxx>
56 //####DESCRIPTIONEND####
58 //==========================================================================
60 #include <cyg/kernel/ktypes.h>
62 // -------------------------------------------------------------------------
63 // The macro CYGNUM_KERNEL_SCHED_BITMAP_SIZE contains the number of bits
64 // that the scheduler bitmap should contain. It is derived from the number
65 // of threads that the system is allowed to use during configuration.
67 #ifndef CYGNUM_KERNEL_SCHED_BITMAP_SIZE
68 #define CYGNUM_KERNEL_SCHED_BITMAP_SIZE 32
71 #if CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 8
72 typedef cyg_ucount8 cyg_sched_bitmap;
73 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 16
74 typedef cyg_ucount16 cyg_sched_bitmap;
75 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 32
76 typedef cyg_ucount32 cyg_sched_bitmap;
78 #error Bitmaps greater than 32 bits not currently allowed
81 // -------------------------------------------------------------------------
82 // Customize the scheduler
84 #define CYGIMP_THREAD_PRIORITY 1
86 #define CYG_THREAD_MIN_PRIORITY (CYGNUM_KERNEL_SCHED_BITMAP_SIZE-1)
87 #define CYG_THREAD_MAX_PRIORITY 0
89 // set default scheduling info value for thread constructors.
90 #define CYG_SCHED_DEFAULT_INFO CYG_THREAD_MAX_PRIORITY
92 // -------------------------------------------------------------------------
93 // This class contains the implementation details of the scheduler, and
94 // provides a standard API for accessing it.
96 class Cyg_Scheduler_Implementation
97 : public Cyg_Scheduler_Base
99 friend class Cyg_ThreadQueue_Implementation;
100 friend class Cyg_SchedThread_Implementation;
102 cyg_sched_bitmap run_queue;
104 Cyg_Thread *thread_table[CYGNUM_KERNEL_SCHED_BITMAP_SIZE];
109 Cyg_Scheduler_Implementation(); // Constructor
111 // The following functions provide the scheduler implementation
112 // interface to the Cyg_Scheduler class. These are protected
113 // so that only the scheduler can call them.
115 // choose a new thread
116 Cyg_Thread *schedule();
118 // make thread schedulable
119 void add_thread(Cyg_Thread *thread);
121 // make thread un-schedulable
122 void rem_thread(Cyg_Thread *thread);
124 // register thread with scheduler
125 void register_thread(Cyg_Thread *thread);
128 void deregister_thread(Cyg_Thread *thread);
130 // Test the given priority for uniqueness
131 cyg_bool unique( cyg_priority priority);
134 void set_idle_thread( Cyg_Thread *thread, HAL_SMP_CPU_TYPE cpu );
138 // -------------------------------------------------------------------------
139 // Scheduler thread implementation.
140 // This class provides the implementation of the scheduler specific parts
143 class Cyg_SchedThread_Implementation
145 friend class Cyg_Scheduler_Implementation;
146 friend class Cyg_ThreadQueue_Implementation;
150 cyg_priority priority; // current thread priority
152 Cyg_SchedThread_Implementation(CYG_ADDRWORD sched_info);
154 void yield(); // Yield CPU to next thread
156 // These are not applicable in a bitmap scheduler; placeholders:
157 inline void rotate_queue( cyg_priority pri ) { };
158 inline void to_queue_head( void ) { };
161 // -------------------------------------------------------------------------
162 // Thread queue implementation.
163 // This class provides the (scheduler specific) implementation of the
164 // thread queue class.
166 class Cyg_ThreadQueue_Implementation
168 cyg_sched_bitmap wait_queue;
172 // API used by Cyg_ThreadQueue
174 Cyg_ThreadQueue_Implementation(); // Constructor
176 // Add thread to queue
177 void enqueue(Cyg_Thread *thread);
179 // return first thread on queue
180 Cyg_Thread *highpri();
182 // remove first thread on queue
183 Cyg_Thread *dequeue();
185 // remove specified thread from queue
186 void remove(Cyg_Thread *thread);
188 // test if queue is empty
193 inline cyg_bool Cyg_ThreadQueue_Implementation::empty()
195 return wait_queue == 0;
198 // -------------------------------------------------------------------------
200 #endif // ifndef CYGONCE_KERNEL_BITMAP_HXX