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