Changeset 09800e9 for src/libcfa/concurrency
- Timestamp:
- May 29, 2018, 4:17:30 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 6c7099a
- Parents:
- 8ebbfc4
- Location:
- src/libcfa/concurrency
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel
r8ebbfc4 r09800e9 43 43 extern struct cluster * mainCluster; 44 44 45 enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule }; 45 enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule, Callback }; 46 47 typedef void (*__finish_callback_fptr_t)(void); 46 48 47 49 //TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI) 48 50 struct FinishAction { 49 51 FinishOpCode action_code; 52 /* 53 // Union of possible actions 54 union { 55 // Option 1 : locks and threads 56 struct { 57 // 1 thread or N thread 58 union { 59 thread_desc * thrd; 60 struct { 61 thread_desc ** thrds; 62 unsigned short thrd_count; 63 }; 64 }; 65 // 1 lock or N lock 66 union { 67 __spinlock_t * lock; 68 struct { 69 __spinlock_t ** locks; 70 unsigned short lock_count; 71 }; 72 }; 73 }; 74 // Option 2 : action pointer 75 __finish_callback_fptr_t callback; 76 }; 77 /*/ 50 78 thread_desc * thrd; 79 thread_desc ** thrds; 80 unsigned short thrd_count; 51 81 __spinlock_t * lock; 52 82 __spinlock_t ** locks; 53 83 unsigned short lock_count; 54 thread_desc ** thrds;55 unsigned short thrd_count;84 __finish_callback_fptr_t callback; 85 //*/ 56 86 }; 57 87 static inline void ?{}(FinishAction & this) { -
src/libcfa/concurrency/kernel.c
r8ebbfc4 r09800e9 49 49 thread_desc * mainThread; 50 50 51 struct { __dllist_t(cluster 51 struct { __dllist_t(cluster) list; __spinlock_t lock; } global_clusters; 52 52 53 53 //----------------------------------------------------------------------------- … … 257 257 // its final actions must be executed from the kernel 258 258 void finishRunning(processor * this) with( this->finish ) { 259 if( action_code == Release ) { 260 verify( ! kernelTLS.preemption_state.enabled ); 259 verify( ! kernelTLS.preemption_state.enabled ); 260 choose( action_code ) { 261 case No_Action: 262 break; 263 case Release: 261 264 unlock( *lock ); 262 } 263 else if( action_code == Schedule ) { 265 case Schedule: 264 266 ScheduleThread( thrd ); 265 } 266 else if( action_code == Release_Schedule ) { 267 verify( ! kernelTLS.preemption_state.enabled ); 267 case Release_Schedule: 268 268 unlock( *lock ); 269 269 ScheduleThread( thrd ); 270 } 271 else if( action_code == Release_Multi ) { 272 verify( ! kernelTLS.preemption_state.enabled ); 270 case Release_Multi: 273 271 for(int i = 0; i < lock_count; i++) { 274 272 unlock( *locks[i] ); 275 273 } 276 } 277 else if( action_code == Release_Multi_Schedule ) { 274 case Release_Multi_Schedule: 278 275 for(int i = 0; i < lock_count; i++) { 279 276 unlock( *locks[i] ); … … 282 279 ScheduleThread( thrds[i] ); 283 280 } 284 } 285 else { 286 assert(action_code == No_Action); 281 case Callback: 282 callback(); 283 default: 284 abort("KERNEL ERROR: Unexpected action to run after thread"); 287 285 } 288 286 } … … 497 495 } 498 496 497 void BlockInternal(__finish_callback_fptr_t callback) { 498 disable_interrupts(); 499 with( *kernelTLS.this_processor ) { 500 finish.action_code = Callback; 501 finish.callback = callback; 502 } 503 504 verify( ! kernelTLS.preemption_state.enabled ); 505 returnToKernel(); 506 verify( ! kernelTLS.preemption_state.enabled ); 507 508 enable_interrupts( __cfaabi_dbg_ctx ); 509 } 510 499 511 // KERNEL ONLY 500 512 void LeaveThread(__spinlock_t * lock, thread_desc * thrd) { -
src/libcfa/concurrency/kernel_private.h
r8ebbfc4 r09800e9 48 48 void BlockInternal(__spinlock_t * locks [], unsigned short count); 49 49 void BlockInternal(__spinlock_t * locks [], unsigned short count, thread_desc * thrds [], unsigned short thrd_count); 50 void BlockInternal(__finish_callback_fptr_t callback); 50 51 void LeaveThread(__spinlock_t * lock, thread_desc * thrd); 51 52 -
src/libcfa/concurrency/monitor.c
r8ebbfc4 r09800e9 297 297 this.count = count; 298 298 299 // Sort monitors based on address -> TODO use a sort specialized for small numbers299 // Sort monitors based on address 300 300 __libcfa_small_sort(this.m, count); 301 301
Note: See TracChangeset
for help on using the changeset viewer.