Changeset a5e7233
- Timestamp:
- Mar 17, 2021, 1:56:12 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- c407434e
- Parents:
- e0c072c
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/clib/cfathread.cfa
re0c072c ra5e7233 21 21 22 22 #include "cfathread.h" 23 24 extern void ?{}(processor &, const char[], cluster &, $thread *); 25 extern "C" { 26 extern void __cfactx_invoke_thread(void (*main)(void *), void * this); 27 } 28 29 //================================================================================ 30 // Thread run y the C Interface 23 31 24 32 struct cfathread_object { … … 65 73 } 66 74 67 processor * procs = 0p; 68 int proc_cnt = 1; 69 75 //================================================================================ 76 // Special Init Thread responsible for the initialization or processors 77 struct __cfainit { 78 $thread self; 79 void (*init)( void * ); 80 void * arg; 81 }; 82 void main(__cfainit & this); 83 void ^?{}(__cfainit & mutex this); 84 85 static inline $thread * get_thread( __cfainit & this ) { return &this.self; } 86 87 typedef ThreadCancelled(__cfainit) __cfainit_exception; 88 typedef ThreadCancelled_vtable(__cfainit) __cfainit_vtable; 89 90 void defaultResumptionHandler(ThreadCancelled(__cfainit) & except) { 91 abort | "The init thread was cancelled"; 92 } 93 94 __cfainit_vtable ___cfainit_vtable_instance; 95 96 __cfainit_vtable const & get_exception_vtable(__cfainit_exception *) { 97 return ___cfainit_vtable_instance; 98 } 99 100 static void ?{}( __cfainit & this, void (*init)( void * ), void * arg ) { 101 this.init = init; 102 this.arg = arg; 103 ((thread&)this){"Processir Init"}; 104 105 // Don't use __thrd_start! just prep the context manually 106 $thread * this_thrd = get_thread(this); 107 void (*main_p)(__cfainit &) = main; 108 109 disable_interrupts(); 110 __cfactx_start(main_p, get_coroutine(this), this, __cfactx_invoke_thread); 111 112 this_thrd->context.[SP, FP] = this_thrd->self_cor.context.[SP, FP]; 113 /* paranoid */ verify( this_thrd->context.SP ); 114 115 this_thrd->state = Ready; 116 enable_interrupts( __cfaabi_dbg_ctx ); 117 } 118 119 void ^?{}(__cfainit & mutex this) { 120 ^(this.self){}; 121 } 122 123 void main( __cfainit & this ) { 124 __attribute__((unused)) void * const thrd_obj = (void*)&this; 125 __attribute__((unused)) void * const thrd_hdl = (void*)active_thread(); 126 /* paranoid */ verify( thrd_obj == thrd_hdl ); 127 128 this.init( this.arg ); 129 } 130 131 //================================================================================ 132 // Main Api 70 133 extern "C" { 71 134 int cfathread_cluster_create(cfathread_cluster_t * cl) __attribute__((nonnull(1))) { … … 79 142 80 143 int cfathread_cluster_add_worker(cfathread_cluster_t cl, pthread_t* tid, void (*init_routine) (void *), void * arg) { 81 // processor * proc = new("C-processor", *cl, init_routine, arg); 144 __cfainit * it = 0p; 145 if(init_routine) { 146 it = alloc(); 147 (*it){init_routine, arg}; 148 } 82 149 processor * proc = alloc(); 83 (*proc){ "C-processor", *cl, init_routine, arg }; 150 (*proc){ "C-processor", *cl, get_thread(*it) }; 151 152 // Wait for the init thread to return before continuing 153 if(it) { 154 ^(*it){}; 155 free(it); 156 } 157 84 158 if(tid) *tid = proc->kernel_thread; 85 159 return 0; -
libcfa/src/concurrency/kernel.cfa
re0c072c ra5e7233 149 149 #endif 150 150 151 // if we need to run some special setup, now is the time to do it.152 if(this->init.fnc) {153 this->init.fnc(this->init.arg);154 }155 156 151 { 157 152 // Setup preemption data … … 162 157 #endif 163 158 159 // if we need to run some special setup, now is the time to do it. 160 if(this->init.thrd) { 161 this->init.thrd->curr_cluster = this->cltr; 162 __run_thread(this, this->init.thrd); 163 } 164 164 165 165 __cfadbg_print_safe(runtime_core, "Kernel : core %p started\n", this); -
libcfa/src/concurrency/kernel.hfa
re0c072c ra5e7233 112 112 // it is not a particularly safe scheme as it can make processors less homogeneous 113 113 struct { 114 void (*fnc) (void *); 115 void * arg; 114 $thread * thrd; 116 115 } init; 117 116 … … 127 126 }; 128 127 129 void ?{}(processor & this, const char name[], struct cluster & cltr , void (*init) (void *), void * arg);128 void ?{}(processor & this, const char name[], struct cluster & cltr); 130 129 void ^?{}(processor & this); 131 130 132 static inline void ?{}(processor & this) { this{ "Anonymous Processor", *mainCluster , 0p, 0p}; }133 static inline void ?{}(processor & this, struct cluster & cltr) { this{ "Anonymous Processor", cltr , 0p, 0p}; }134 static inline void ?{}(processor & this, const char name[]) { this{name, *mainCluster , 0p, 0p}; }131 static inline void ?{}(processor & this) { this{ "Anonymous Processor", *mainCluster}; } 132 static inline void ?{}(processor & this, struct cluster & cltr) { this{ "Anonymous Processor", cltr}; } 133 static inline void ?{}(processor & this, const char name[]) { this{name, *mainCluster}; } 135 134 136 135 DLISTED_MGD_IMPL_OUT(processor) -
libcfa/src/concurrency/kernel/startup.cfa
re0c072c ra5e7233 73 73 static void __kernel_first_resume( processor * this ); 74 74 static void __kernel_last_resume ( processor * this ); 75 static void init(processor & this, const char name[], cluster & _cltr, void (*fnc) (void *), void * arg);75 static void init(processor & this, const char name[], cluster & _cltr, $thread * initT); 76 76 static void deinit(processor & this); 77 77 static void doregister( struct cluster & cltr ); … … 198 198 ( this.terminated ){}; 199 199 ( this.runner ){}; 200 init( this, "Main Processor", *mainCluster, 0p , 0p);200 init( this, "Main Processor", *mainCluster, 0p ); 201 201 kernel_thread = pthread_self(); 202 202 … … 452 452 } 453 453 454 static void init(processor & this, const char name[], cluster & _cltr, void (*fnc) (void *), void * arg) with( this ) {454 static void init(processor & this, const char name[], cluster & _cltr, $thread * initT) with( this ) { 455 455 this.name = name; 456 456 this.cltr = &_cltr; … … 464 464 this.io.dirty = false; 465 465 466 this.init.fnc = fnc; 467 this.init.arg = arg; 466 this.init.thrd = initT; 468 467 469 468 this.idle = eventfd(0, 0); … … 516 515 } 517 516 518 void ?{}(processor & this, const char name[], cluster & _cltr, void (*fnc) (void *), void * arg) {517 void ?{}(processor & this, const char name[], cluster & _cltr, $thread * initT) { 519 518 ( this.terminated ){}; 520 519 ( this.runner ){}; 521 520 522 521 disable_interrupts(); 523 init( this, name, _cltr, fnc, arg);522 init( this, name, _cltr, initT ); 524 523 enable_interrupts( __cfaabi_dbg_ctx ); 525 524 … … 527 526 528 527 this.stack = __create_pthread( &this.kernel_thread, __invoke_processor, (void *)&this ); 529 528 } 529 530 void ?{}(processor & this, const char name[], cluster & _cltr) { 531 (this){name, _cltr, 0p}; 530 532 } 531 533 -
tests/concurrent/clib.c
re0c072c ra5e7233 62 62 cfathread_cluster_add_worker( cl, NULL, NULL, NULL ); 63 63 cfathread_cluster_add_worker( cl, NULL, NULL, NULL ); 64 65 cfathread_attr_t attr; 66 cfathread_attr_init(&attr); 67 cfathread_attr_setcluster(&attr, cl); 68 64 69 cfathread_t u; 65 cfathread_create( &u, NULL, Unparker, NULL );70 cfathread_create( &u, &attr, Unparker, NULL ); 66 71 { 67 72 cfathread_t t[20]; 68 73 for(int i = 0; i < 20; i++) { 69 cfathread_create( &t[i], NULL, Worker, NULL );74 cfathread_create( &t[i], &attr, Worker, NULL ); 70 75 } 71 76 for(int i = 0; i < 20; i++) { … … 75 80 stop = true; 76 81 cfathread_join(u, NULL); 82 cfathread_attr_destroy(&attr); 77 83 fflush(stdout); 78 84 _exit(0);
Note: See TracChangeset
for help on using the changeset viewer.