- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/kernel.hfa
rd4e68a6 r92e7631 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jun 22 11:39:17 201913 // Update Count : 1612 // Last Modified On : Tue Feb 4 12:29:26 2020 13 // Update Count : 22 14 14 // 15 15 … … 20 20 #include "invoke.h" 21 21 #include "time_t.hfa" 22 #include "coroutine.hfa" 22 23 23 24 extern "C" { … … 31 32 __spinlock_t lock; 32 33 int count; 33 __queue_t( thread_desc) waiting;34 __queue_t($thread) waiting; 34 35 }; 35 36 … … 37 38 void ^?{}(semaphore & this); 38 39 void P (semaphore & this); 39 voidV (semaphore & this);40 bool V (semaphore & this); 40 41 41 42 … … 43 44 // Processor 44 45 extern struct cluster * mainCluster; 45 46 enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule, Callback };47 48 typedef void (*__finish_callback_fptr_t)(void);49 50 //TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)51 struct FinishAction {52 FinishOpCode action_code;53 /*54 // Union of possible actions55 union {56 // Option 1 : locks and threads57 struct {58 // 1 thread or N thread59 union {60 thread_desc * thrd;61 struct {62 thread_desc ** thrds;63 unsigned short thrd_count;64 };65 };66 // 1 lock or N lock67 union {68 __spinlock_t * lock;69 struct {70 __spinlock_t ** locks;71 unsigned short lock_count;72 };73 };74 };75 // Option 2 : action pointer76 __finish_callback_fptr_t callback;77 };78 /*/79 thread_desc * thrd;80 thread_desc ** thrds;81 unsigned short thrd_count;82 __spinlock_t * lock;83 __spinlock_t ** locks;84 unsigned short lock_count;85 __finish_callback_fptr_t callback;86 //*/87 };88 static inline void ?{}(FinishAction & this) {89 this.action_code = No_Action;90 this.thrd = NULL;91 this.lock = NULL;92 }93 static inline void ^?{}(FinishAction &) {}94 46 95 47 // Processor … … 115 67 // RunThread data 116 68 // Action to do after a thread is ran 117 struct FinishAction finish;69 $thread * destroyer; 118 70 119 71 // Preemption data … … 124 76 bool pending_preemption; 125 77 126 // Idle lock 127 __bin_sem_t idle Lock;78 // Idle lock (kernel semaphore) 79 __bin_sem_t idle; 128 80 129 81 // Termination … … 131 83 volatile bool do_terminate; 132 84 133 // Termination synchronisation 85 // Termination synchronisation (user semaphore) 134 86 semaphore terminated; 87 88 // pthread Stack 89 void * stack; 135 90 136 91 // Link lists fields … … 146 101 }; 147 102 148 void ?{}(processor & this, const char * name, struct cluster & cltr);103 void ?{}(processor & this, const char name[], struct cluster & cltr); 149 104 void ^?{}(processor & this); 150 105 151 106 static inline void ?{}(processor & this) { this{ "Anonymous Processor", *mainCluster}; } 152 107 static inline void ?{}(processor & this, struct cluster & cltr) { this{ "Anonymous Processor", cltr}; } 153 static inline void ?{}(processor & this, const char * name) { this{name, *mainCluster }; }108 static inline void ?{}(processor & this, const char name[]) { this{name, *mainCluster }; } 154 109 155 static inline [processor *&, processor *& ] __get( processor & this ) { 156 return this.node.[next, prev]; 157 } 110 static inline [processor *&, processor *& ] __get( processor & this ) __attribute__((const)) { return this.node.[next, prev]; } 158 111 159 112 //----------------------------------------------------------------------------- … … 164 117 165 118 // Ready queue for threads 166 __queue_t( thread_desc) ready_queue;119 __queue_t($thread) ready_queue; 167 120 168 121 // Name of the cluster … … 173 126 174 127 // List of processors 175 __spinlock_t proc_list_lock;128 __spinlock_t idle_lock; 176 129 __dllist_t(struct processor) procs; 177 130 __dllist_t(struct processor) idles; … … 180 133 // List of threads 181 134 __spinlock_t thread_list_lock; 182 __dllist_t(struct thread_desc) threads;135 __dllist_t(struct $thread) threads; 183 136 unsigned int nthreads; 184 137 … … 191 144 extern Duration default_preemption(); 192 145 193 void ?{} (cluster & this, const char * name, Duration preemption_rate);146 void ?{} (cluster & this, const char name[], Duration preemption_rate); 194 147 void ^?{}(cluster & this); 195 148 196 149 static inline void ?{} (cluster & this) { this{"Anonymous Cluster", default_preemption()}; } 197 150 static inline void ?{} (cluster & this, Duration preemption_rate) { this{"Anonymous Cluster", preemption_rate}; } 198 static inline void ?{} (cluster & this, const char * name) { this{name, default_preemption()}; }151 static inline void ?{} (cluster & this, const char name[]) { this{name, default_preemption()}; } 199 152 200 static inline [cluster *&, cluster *& ] __get( cluster & this ) { 201 return this.node.[next, prev]; 202 } 153 static inline [cluster *&, cluster *& ] __get( cluster & this ) __attribute__((const)) { return this.node.[next, prev]; } 203 154 204 155 static inline struct processor * active_processor() { return TL_GET( this_processor ); } // UNSAFE
Note:
See TracChangeset
for help on using the changeset viewer.