Mercurial > ecos
comparison packages/kernel/current/include/bitmap.hxx @ 0:3111d98ba7b3 ecos-v1_1-release
Initial commit of eCos version 1.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 11:16:07 +0000 |
| parents | |
| children | 443894e2e912 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:3111d98ba7b3 |
|---|---|
| 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 //####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 | |
| 28 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. | |
| 29 // ------------------------------------------- | |
| 30 // | |
| 31 //####COPYRIGHTEND#### | |
| 32 //========================================================================== | |
| 33 //#####DESCRIPTIONBEGIN#### | |
| 34 // | |
| 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 | |
| 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 | |
| 143 }; | |
| 144 | |
| 145 // ------------------------------------------------------------------------- | |
| 146 // Thread queue implementation. | |
| 147 // This class provides the (scheduler specific) implementation of the | |
| 148 // thread queue class. | |
| 149 | |
| 150 class Cyg_ThreadQueue_Implementation | |
| 151 { | |
| 152 cyg_sched_bitmap wait_queue; | |
| 153 | |
| 154 protected: | |
| 155 | |
| 156 // API used by Cyg_ThreadQueue | |
| 157 | |
| 158 Cyg_ThreadQueue_Implementation(); // Constructor | |
| 159 | |
| 160 // Add thread to queue | |
| 161 void enqueue(Cyg_Thread *thread); | |
| 162 | |
| 163 // return first thread on queue | |
| 164 Cyg_Thread *highpri(); | |
| 165 | |
| 166 // remove first thread on queue | |
| 167 Cyg_Thread *dequeue(); | |
| 168 | |
| 169 // remove specified thread from queue | |
| 170 void remove(Cyg_Thread *thread); | |
| 171 | |
| 172 // test if queue is empty | |
| 173 cyg_bool empty(); | |
| 174 | |
| 175 }; | |
| 176 | |
| 177 inline cyg_bool Cyg_ThreadQueue_Implementation::empty() | |
| 178 { | |
| 179 return wait_queue == 0; | |
| 180 } | |
| 181 | |
| 182 // ------------------------------------------------------------------------- | |
| 183 | |
| 184 #endif // ifndef CYGONCE_KERNEL_BITMAP_HXX | |
| 185 // EOF bitmap.hxx |
