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.
15 // Copyright (C) 2006 eCosCentric Limited
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.
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
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.
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.
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.
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####
48 // Contributors: nickg
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
54 // Usage: Included according to configuration by
55 // <cyg/kernel/sched.hxx>
57 //####DESCRIPTIONEND####
59 //==========================================================================
61 #include <cyg/kernel/ktypes.h>
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.
68 #ifndef CYGNUM_KERNEL_SCHED_BITMAP_SIZE
69 #define CYGNUM_KERNEL_SCHED_BITMAP_SIZE 32
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;
79 #error Bitmaps greater than 32 bits not currently allowed
82 // -------------------------------------------------------------------------
83 // Customize the scheduler
85 #define CYGIMP_THREAD_PRIORITY 1
87 #define CYG_THREAD_MIN_PRIORITY (CYGNUM_KERNEL_SCHED_BITMAP_SIZE-1)
88 #define CYG_THREAD_MAX_PRIORITY 0
90 // set default scheduling info value for thread constructors.
91 #define CYG_SCHED_DEFAULT_INFO CYG_THREAD_MAX_PRIORITY
93 // -------------------------------------------------------------------------
94 // This class contains the implementation details of the scheduler, and
95 // provides a standard API for accessing it.
97 class Cyg_Scheduler_Implementation
98 : public Cyg_Scheduler_Base
100 friend class Cyg_ThreadQueue_Implementation;
101 friend class Cyg_SchedThread_Implementation;
103 cyg_sched_bitmap run_queue;
105 Cyg_Thread *thread_table[CYGNUM_KERNEL_SCHED_BITMAP_SIZE];
110 Cyg_Scheduler_Implementation(); // Constructor
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.
116 // choose a new thread
117 Cyg_Thread *schedule();
119 // make thread schedulable
120 void add_thread(Cyg_Thread *thread);
122 // make thread un-schedulable
123 void rem_thread(Cyg_Thread *thread);
125 // register thread with scheduler
126 void register_thread(Cyg_Thread *thread);
129 void deregister_thread(Cyg_Thread *thread);
131 // Test the given priority for uniqueness
132 cyg_bool unique( cyg_priority priority);
135 void set_idle_thread( Cyg_Thread *thread, HAL_SMP_CPU_TYPE cpu );
139 // -------------------------------------------------------------------------
140 // Scheduler thread implementation.
141 // This class provides the implementation of the scheduler specific parts
144 class Cyg_SchedThread_Implementation
146 friend class Cyg_Scheduler_Implementation;
147 friend class Cyg_ThreadQueue_Implementation;
151 cyg_priority priority; // current thread priority
153 Cyg_SchedThread_Implementation(CYG_ADDRWORD sched_info);
155 void yield(); // Yield CPU to next thread
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 ) { };
161 inline void timeslice_save() {};
162 inline void timeslice_restore() {};
163 inline void timeslice_reset() {};
167 // -------------------------------------------------------------------------
168 // Thread queue implementation.
169 // This class provides the (scheduler specific) implementation of the
170 // thread queue class.
172 class Cyg_ThreadQueue_Implementation
174 cyg_sched_bitmap wait_queue;
178 // API used by Cyg_ThreadQueue
180 Cyg_ThreadQueue_Implementation(); // Constructor
182 // Add thread to queue
183 void enqueue(Cyg_Thread *thread);
185 // return first thread on queue
186 Cyg_Thread *highpri();
188 // remove first thread on queue
189 Cyg_Thread *dequeue();
191 // remove specified thread from queue
192 void remove(Cyg_Thread *thread);
194 // test if queue is empty
199 inline cyg_bool Cyg_ThreadQueue_Implementation::empty()
201 return wait_queue == 0;
204 // -------------------------------------------------------------------------
206 #endif // ifndef CYGONCE_KERNEL_BITMAP_HXX