- File:
-
- 1 edited
-
libcfa/src/concurrency/kernel.hfa (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.hfa
re3fea42 r71c8b7e 17 17 18 18 #include <stdbool.h> 19 #include <stdint.h> 19 20 20 21 #include "invoke.h" … … 32 33 __spinlock_t lock; 33 34 int count; 34 __queue_t( thread_desc) waiting;35 __queue_t($thread) waiting; 35 36 }; 36 37 37 38 void ?{}(semaphore & this, int count = 1); 38 39 void ^?{}(semaphore & this); 39 void P (semaphore & this); 40 void V (semaphore & this); 40 bool P (semaphore & this); 41 bool V (semaphore & this); 42 bool V (semaphore & this, unsigned count); 41 43 42 44 … … 44 46 // Processor 45 47 extern struct cluster * mainCluster; 46 47 enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule, Callback };48 49 typedef void (*__finish_callback_fptr_t)(void);50 51 //TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)52 struct FinishAction {53 FinishOpCode action_code;54 /*55 // Union of possible actions56 union {57 // Option 1 : locks and threads58 struct {59 // 1 thread or N thread60 union {61 thread_desc * thrd;62 struct {63 thread_desc ** thrds;64 unsigned short thrd_count;65 };66 };67 // 1 lock or N lock68 union {69 __spinlock_t * lock;70 struct {71 __spinlock_t ** locks;72 unsigned short lock_count;73 };74 };75 };76 // Option 2 : action pointer77 __finish_callback_fptr_t callback;78 };79 /*/80 thread_desc * thrd;81 thread_desc ** thrds;82 unsigned short thrd_count;83 __spinlock_t * lock;84 __spinlock_t ** locks;85 unsigned short lock_count;86 __finish_callback_fptr_t callback;87 //*/88 };89 static inline void ?{}(FinishAction & this) {90 this.action_code = No_Action;91 this.thrd = 0p;92 this.lock = 0p;93 }94 static inline void ^?{}(FinishAction &) {}95 48 96 49 // Processor … … 116 69 // RunThread data 117 70 // Action to do after a thread is ran 118 struct FinishAction finish;71 $thread * destroyer; 119 72 120 73 // Preemption data … … 125 78 bool pending_preemption; 126 79 127 // Idle lock 128 __bin_sem_t idle Lock;80 // Idle lock (kernel semaphore) 81 __bin_sem_t idle; 129 82 130 83 // Termination … … 132 85 volatile bool do_terminate; 133 86 134 // Termination synchronisation 87 // Termination synchronisation (user semaphore) 135 88 semaphore terminated; 136 89 … … 157 110 static inline void ?{}(processor & this, const char name[]) { this{name, *mainCluster }; } 158 111 159 static inline [processor *&, processor *& ] __get( processor & this ) { 160 return this.node.[next, prev]; 161 } 112 static inline [processor *&, processor *& ] __get( processor & this ) __attribute__((const)) { return this.node.[next, prev]; } 113 114 //----------------------------------------------------------------------------- 115 // I/O 116 struct __io_data; 117 118 #define CFA_CLUSTER_IO_POLLER_USER_THREAD 1 << 0 119 // #define CFA_CLUSTER_IO_POLLER_KERNEL_SIDE 1 << 1 162 120 163 121 //----------------------------------------------------------------------------- … … 168 126 169 127 // Ready queue for threads 170 __queue_t( thread_desc) ready_queue;128 __queue_t($thread) ready_queue; 171 129 172 130 // Name of the cluster … … 177 135 178 136 // List of processors 179 __spinlock_t proc_list_lock;137 __spinlock_t idle_lock; 180 138 __dllist_t(struct processor) procs; 181 139 __dllist_t(struct processor) idles; … … 184 142 // List of threads 185 143 __spinlock_t thread_list_lock; 186 __dllist_t(struct thread_desc) threads;144 __dllist_t(struct $thread) threads; 187 145 unsigned int nthreads; 188 146 … … 192 150 cluster * prev; 193 151 } node; 152 153 struct __io_data * io; 154 155 #if !defined(__CFA_NO_STATISTICS__) 156 bool print_stats; 157 #endif 194 158 }; 195 159 extern Duration default_preemption(); 196 160 197 void ?{} (cluster & this, const char name[], Duration preemption_rate );161 void ?{} (cluster & this, const char name[], Duration preemption_rate, int flags); 198 162 void ^?{}(cluster & this); 199 163 200 static inline void ?{} (cluster & this) { this{"Anonymous Cluster", default_preemption()}; } 201 static inline void ?{} (cluster & this, Duration preemption_rate) { this{"Anonymous Cluster", preemption_rate}; } 202 static inline void ?{} (cluster & this, const char name[]) { this{name, default_preemption()}; } 164 static inline void ?{} (cluster & this) { this{"Anonymous Cluster", default_preemption(), 0}; } 165 static inline void ?{} (cluster & this, Duration preemption_rate) { this{"Anonymous Cluster", preemption_rate, 0}; } 166 static inline void ?{} (cluster & this, const char name[]) { this{name, default_preemption(), 0}; } 167 static inline void ?{} (cluster & this, int flags) { this{"Anonymous Cluster", default_preemption(), flags}; } 168 static inline void ?{} (cluster & this, Duration preemption_rate, int flags) { this{"Anonymous Cluster", preemption_rate, flags}; } 169 static inline void ?{} (cluster & this, const char name[], int flags) { this{name, default_preemption(), flags}; } 203 170 204 static inline [cluster *&, cluster *& ] __get( cluster & this ) { 205 return this.node.[next, prev]; 206 } 171 static inline [cluster *&, cluster *& ] __get( cluster & this ) __attribute__((const)) { return this.node.[next, prev]; } 207 172 208 173 static inline struct processor * active_processor() { return TL_GET( this_processor ); } // UNSAFE 209 174 static inline struct cluster * active_cluster () { return TL_GET( this_processor )->cltr; } 175 176 #if !defined(__CFA_NO_STATISTICS__) 177 static inline void print_stats_at_exit( cluster & this ) { 178 this.print_stats = true; 179 } 180 #endif 210 181 211 182 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.