- File:
-
- 1 edited
-
libcfa/src/concurrency/kernel.hfa (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.hfa
r71c8b7e re3fea42 17 17 18 18 #include <stdbool.h> 19 #include <stdint.h>20 19 21 20 #include "invoke.h" … … 33 32 __spinlock_t lock; 34 33 int count; 35 __queue_t( $thread) waiting;34 __queue_t(thread_desc) waiting; 36 35 }; 37 36 38 37 void ?{}(semaphore & this, int count = 1); 39 38 void ^?{}(semaphore & this); 40 bool P (semaphore & this); 41 bool V (semaphore & this); 42 bool V (semaphore & this, unsigned count); 39 void P (semaphore & this); 40 void V (semaphore & this); 43 41 44 42 … … 46 44 // Processor 47 45 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 actions 56 union { 57 // Option 1 : locks and threads 58 struct { 59 // 1 thread or N thread 60 union { 61 thread_desc * thrd; 62 struct { 63 thread_desc ** thrds; 64 unsigned short thrd_count; 65 }; 66 }; 67 // 1 lock or N lock 68 union { 69 __spinlock_t * lock; 70 struct { 71 __spinlock_t ** locks; 72 unsigned short lock_count; 73 }; 74 }; 75 }; 76 // Option 2 : action pointer 77 __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 &) {} 48 95 49 96 // Processor … … 69 116 // RunThread data 70 117 // Action to do after a thread is ran 71 $thread * destroyer;118 struct FinishAction finish; 72 119 73 120 // Preemption data … … 78 125 bool pending_preemption; 79 126 80 // Idle lock (kernel semaphore)81 __bin_sem_t idle ;127 // Idle lock 128 __bin_sem_t idleLock; 82 129 83 130 // Termination … … 85 132 volatile bool do_terminate; 86 133 87 // Termination synchronisation (user semaphore)134 // Termination synchronisation 88 135 semaphore terminated; 89 136 … … 110 157 static inline void ?{}(processor & this, const char name[]) { this{name, *mainCluster }; } 111 158 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 159 static inline [processor *&, processor *& ] __get( processor & this ) { 160 return this.node.[next, prev]; 161 } 120 162 121 163 //----------------------------------------------------------------------------- … … 126 168 127 169 // Ready queue for threads 128 __queue_t( $thread) ready_queue;170 __queue_t(thread_desc) ready_queue; 129 171 130 172 // Name of the cluster … … 135 177 136 178 // List of processors 137 __spinlock_t idle_lock;179 __spinlock_t proc_list_lock; 138 180 __dllist_t(struct processor) procs; 139 181 __dllist_t(struct processor) idles; … … 142 184 // List of threads 143 185 __spinlock_t thread_list_lock; 144 __dllist_t(struct $thread) threads;186 __dllist_t(struct thread_desc) threads; 145 187 unsigned int nthreads; 146 188 … … 150 192 cluster * prev; 151 193 } node; 152 153 struct __io_data * io;154 155 #if !defined(__CFA_NO_STATISTICS__)156 bool print_stats;157 #endif158 194 }; 159 195 extern Duration default_preemption(); 160 196 161 void ?{} (cluster & this, const char name[], Duration preemption_rate , int flags);197 void ?{} (cluster & this, const char name[], Duration preemption_rate); 162 198 void ^?{}(cluster & this); 163 199 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}; } 170 171 static inline [cluster *&, cluster *& ] __get( cluster & this ) __attribute__((const)) { return this.node.[next, prev]; } 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()}; } 203 204 static inline [cluster *&, cluster *& ] __get( cluster & this ) { 205 return this.node.[next, prev]; 206 } 172 207 173 208 static inline struct processor * active_processor() { return TL_GET( this_processor ); } // UNSAFE 174 209 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 #endif181 210 182 211 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.