Changeset e15df4c for src/libcfa
- Timestamp:
- Jan 24, 2017, 4:50:45 PM (8 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, resolv-new, with_gc
- Children:
- ad56482
- Parents:
- 2cdf6dc
- Location:
- src/libcfa/concurrency
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/invoke.c
r2cdf6dc re15df4c 29 29 30 30 extern void __suspend_no_inline__F___1(void); 31 extern void __signal_termination__F_P9sthread_h__1(struct thread _h*);31 extern void __signal_termination__F_P9sthread_h__1(struct thread*); 32 32 33 33 void CtxInvokeCoroutine( … … 58 58 void CtxInvokeThread( 59 59 void (*main)(void *), 60 struct thread _h*(*get_thread)(void *),60 struct thread *(*get_thread)(void *), 61 61 void *this 62 62 ) { … … 65 65 __suspend_no_inline__F___1(); 66 66 67 struct thread _h* thrd = get_thread( this );67 struct thread* thrd = get_thread( this ); 68 68 struct coroutine* cor = &thrd->c; 69 69 cor->state = Active; -
src/libcfa/concurrency/invoke.h
r2cdf6dc re15df4c 31 31 32 32 struct simple_thread_list { 33 struct thread _h* head;34 struct thread _h** tail;33 struct thread * head; 34 struct thread ** tail; 35 35 }; 36 36 … … 38 38 extern "Cforall" { 39 39 void ?{}( struct simple_thread_list * ); 40 void append( struct simple_thread_list *, struct thread _h* );41 struct thread _h* pop_head( struct simple_thread_list * );40 void append( struct simple_thread_list *, struct thread * ); 41 struct thread * pop_head( struct simple_thread_list * ); 42 42 } 43 43 #endif … … 70 70 }; 71 71 72 struct thread _h{72 struct thread { 73 73 struct coroutine c; 74 74 struct simple_lock lock; 75 struct thread _h* next;75 struct thread * next; 76 76 }; 77 77 -
src/libcfa/concurrency/kernel
r2cdf6dc re15df4c 42 42 cluster * cltr; 43 43 coroutine * current_coroutine; 44 thread _h* current_thread;44 thread * current_thread; 45 45 pthread_t kernel_thread; 46 46 simple_lock lock; -
src/libcfa/concurrency/kernel.c
r2cdf6dc re15df4c 46 46 KERNEL_STORAGE(cluster, systemCluster); 47 47 KERNEL_STORAGE(processor, systemProcessor); 48 KERNEL_STORAGE(thread _h, mainThread);48 KERNEL_STORAGE(thread, mainThread); 49 49 KERNEL_STORAGE(machine_context_t, mainThread_context); 50 50 51 51 cluster * systemCluster; 52 52 processor * systemProcessor; 53 thread _h* mainThread;53 thread * mainThread; 54 54 55 55 void kernel_startup(void) __attribute__((constructor(101))); … … 69 69 } 70 70 71 thread _h* this_thread(void) {71 thread * this_thread(void) { 72 72 return this_processor->current_thread; 73 73 } … … 117 117 } 118 118 119 void ?{}( thread _h* this, current_stack_info_t * info) {119 void ?{}( thread * this, current_stack_info_t * info) { 120 120 (&this->c){ info }; 121 121 } … … 183 183 // Processor running routines 184 184 void main(processorCtx_t * ctx); 185 thread _h* nextThread(cluster * this);186 void runThread(processor * this, thread _h* dst);185 thread * nextThread(cluster * this); 186 void runThread(processor * this, thread * dst); 187 187 void spin(processor * this, unsigned int * spin_count); 188 188 … … 191 191 LIB_DEBUG_PRINTF("Kernel : core %p starting\n", this); 192 192 193 thread _h* readyThread = NULL;193 thread * readyThread = NULL; 194 194 for( unsigned int spin_count = 0; ! this->terminated; spin_count++ ) { 195 195 … … 209 209 } 210 210 211 void runThread(processor * this, thread _h* dst) {211 void runThread(processor * this, thread * dst) { 212 212 coroutine * proc_ctx = get_coroutine(this->ctx); 213 213 coroutine * thrd_ctx = get_coroutine(dst); … … 284 284 //----------------------------------------------------------------------------- 285 285 // Scheduler routines 286 void thread_schedule( thread _h* thrd ) {286 void thread_schedule( thread * thrd ) { 287 287 assertf( thrd->next == NULL, "Expected null got %p", thrd->next ); 288 288 … … 291 291 } 292 292 293 thread _h* nextThread(cluster * this) {293 thread * nextThread(cluster * this) { 294 294 pthread_spinlock_guard guard = { &this->lock }; 295 295 return pop_head( &this->ready_queue ); … … 314 314 315 315 // Start by initializing the main thread 316 mainThread = (thread _h*)&mainThread_storage;316 mainThread = (thread *)&mainThread_storage; 317 317 mainThread{ &info }; 318 318 … … 391 391 392 392 void unlock( simple_lock * this ) { 393 thread _h* it;393 thread * it; 394 394 while( it = pop_head( &this->blocked) ) { 395 395 thread_schedule( it ); … … 404 404 } 405 405 406 void append( simple_thread_list * this, thread _h* t ) {406 void append( simple_thread_list * this, thread * t ) { 407 407 assert( t->next == NULL ); 408 408 *this->tail = t; … … 410 410 } 411 411 412 thread _h* pop_head( simple_thread_list * this ) {413 thread _h* head = this->head;412 thread * pop_head( simple_thread_list * this ) { 413 thread * head = this->head; 414 414 if( head ) { 415 415 this->head = head->next; -
src/libcfa/concurrency/threads
r2cdf6dc re15df4c 29 29 trait is_thread(dtype T | sized(T)) { 30 30 void main(T* this); 31 thread _h* get_thread(T* this);31 thread* get_thread(T* this); 32 32 }; 33 33 34 #define DECL_THREAD(X) static inline thread _h* get_thread(X* this) { return &this->t; } void main(X* this);34 #define DECL_THREAD(X) static inline thread* get_thread(X* this) { return &this->t; } void main(X* this); 35 35 36 36 forall( dtype T | sized(T) | is_thread(T) ) … … 39 39 } 40 40 41 static inline coroutine* get_coroutine(thread _h* this) {41 static inline coroutine* get_coroutine(thread* this) { 42 42 return &this->c; 43 43 } 44 44 45 thread _h* this_thread(void);45 thread * this_thread(void); 46 46 47 47 //----------------------------------------------------------------------------- 48 48 // Ctors and dtors 49 void ?{}(thread _h* this);50 void ^?{}(thread _h* this);49 void ?{}(thread* this); 50 void ^?{}(thread* this); 51 51 52 52 //----------------------------------------------------------------------------- … … 54 54 // Structure that actually start and stop threads 55 55 forall( dtype T | sized(T) | is_thread(T) ) 56 struct thread {56 struct scoped { 57 57 T handle; 58 58 }; 59 59 60 60 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T*); } ) 61 void ?{}( thread(T)* this );61 void ?{}( scoped(T)* this ); 62 62 63 63 forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T*, P); } ) 64 void ?{}( thread(T)* this, P params );64 void ?{}( scoped(T)* this, P params ); 65 65 66 66 forall( dtype T | sized(T) | is_thread(T) | { void ^?{}(T*); } ) 67 void ^?{}( thread(T)* this );67 void ^?{}( scoped(T)* this ); 68 68 69 69 void yield(); -
src/libcfa/concurrency/threads.c
r2cdf6dc re15df4c 40 40 // Thread ctors and dtors 41 41 42 void ?{}(thread _h* this) {42 void ?{}(thread* this) { 43 43 (&this->c){}; 44 44 this->c.name = "Anonymous Coroutine"; … … 47 47 } 48 48 49 void ^?{}(thread _h* this) {49 void ^?{}(thread* this) { 50 50 ^(&this->c){}; 51 51 } 52 52 53 53 forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T*); } ) 54 void ?{}( thread(T)* this ) {54 void ?{}( scoped(T)* this ) { 55 55 (&this->handle){}; 56 56 start(&this->handle); … … 58 58 59 59 forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T*, P); } ) 60 void ?{}( thread(T)* this, P params ) {60 void ?{}( scoped(T)* this, P params ) { 61 61 (&this->handle){ params }; 62 62 start(&this->handle); … … 64 64 65 65 forall( dtype T | sized(T) | is_thread(T) | { void ^?{}(T*); } ) 66 void ^?{}( thread(T)* this ) {66 void ^?{}( scoped(T)* this ) { 67 67 stop(&this->handle); 68 68 ^(&this->handle){}; … … 76 76 } 77 77 78 extern void thread_schedule( thread _h* );78 extern void thread_schedule( thread * ); 79 79 80 80 forall( dtype T | sized(T) | is_thread(T) ) 81 81 void start( T* this ) { 82 82 coroutine* thrd_c = get_coroutine(this); 83 thread _h* thrd_h = get_thread (this);83 thread* thrd_h = get_thread (this); 84 84 thrd_c->last = this_coroutine(); 85 85 get_this_processor()->current_coroutine = thrd_c; … … 96 96 forall( dtype T | sized(T) | is_thread(T) ) 97 97 void stop( T* this ) { 98 thread _h* thrd = get_thread(this);98 thread* thrd = get_thread(this); 99 99 if( thrd->c.notHalted ) { 100 100 lock( &thrd->lock ); … … 102 102 } 103 103 104 void signal_termination( thread _h* this ) {104 void signal_termination( thread * this ) { 105 105 this->c.state = Halt; 106 106 this->c.notHalted = false;
Note: See TracChangeset
for help on using the changeset viewer.