Changeset 1f55a75 for libcfa/src/concurrency/clib
- Timestamp:
- Mar 23, 2021, 9:19:47 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- 98d9ce9
- Parents:
- f9c3100 (diff), e825c9d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- libcfa/src/concurrency/clib
- Files:
-
- 2 edited
-
cfathread.cfa (modified) (4 diffs)
-
cfathread.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/clib/cfathread.cfa
rf9c3100 r1f55a75 17 17 #include "locks.hfa" 18 18 #include "kernel.hfa" 19 #include "stats.hfa" 19 20 #include "thread.hfa" 20 21 #include "time.hfa" 21 22 22 23 #include "cfathread.h" 24 25 extern void ?{}(processor &, const char[], cluster &, $thread *); 26 extern "C" { 27 extern void __cfactx_invoke_thread(void (*main)(void *), void * this); 28 } 29 30 //================================================================================ 31 // Thread run y the C Interface 23 32 24 33 struct cfathread_object { … … 65 74 } 66 75 67 processor * procs = 0p; 68 int proc_cnt = 1; 69 76 //================================================================================ 77 // Special Init Thread responsible for the initialization or processors 78 struct __cfainit { 79 $thread self; 80 void (*init)( void * ); 81 void * arg; 82 }; 83 void main(__cfainit & this); 84 void ^?{}(__cfainit & mutex this); 85 86 static inline $thread * get_thread( __cfainit & this ) { return &this.self; } 87 88 typedef ThreadCancelled(__cfainit) __cfainit_exception; 89 typedef ThreadCancelled_vtable(__cfainit) __cfainit_vtable; 90 91 void defaultResumptionHandler(ThreadCancelled(__cfainit) & except) { 92 abort | "The init thread was cancelled"; 93 } 94 95 __cfainit_vtable ___cfainit_vtable_instance; 96 97 __cfainit_vtable const & get_exception_vtable(__cfainit_exception *) { 98 return ___cfainit_vtable_instance; 99 } 100 101 static void ?{}( __cfainit & this, void (*init)( void * ), void * arg ) { 102 this.init = init; 103 this.arg = arg; 104 ((thread&)this){"Processir Init"}; 105 106 // Don't use __thrd_start! just prep the context manually 107 $thread * this_thrd = get_thread(this); 108 void (*main_p)(__cfainit &) = main; 109 110 disable_interrupts(); 111 __cfactx_start(main_p, get_coroutine(this), this, __cfactx_invoke_thread); 112 113 this_thrd->context.[SP, FP] = this_thrd->self_cor.context.[SP, FP]; 114 /* paranoid */ verify( this_thrd->context.SP ); 115 116 this_thrd->state = Ready; 117 enable_interrupts( __cfaabi_dbg_ctx ); 118 } 119 120 void ^?{}(__cfainit & mutex this) { 121 ^(this.self){}; 122 } 123 124 void main( __cfainit & this ) { 125 __attribute__((unused)) void * const thrd_obj = (void*)&this; 126 __attribute__((unused)) void * const thrd_hdl = (void*)active_thread(); 127 /* paranoid */ verify( thrd_obj == thrd_hdl ); 128 129 this.init( this.arg ); 130 } 131 132 //================================================================================ 133 // Main Api 70 134 extern "C" { 71 135 int cfathread_cluster_create(cfathread_cluster_t * cl) __attribute__((nonnull(1))) { … … 78 142 } 79 143 144 int cfathread_cluster_print_stats( cfathread_cluster_t cl ) { 145 #if !defined(__CFA_NO_STATISTICS__) 146 print_stats_at_exit( *cl, CFA_STATS_READY_Q | CFA_STATS_IO ); 147 print_stats_now( *cl, CFA_STATS_READY_Q | CFA_STATS_IO ); 148 #endif 149 return 0; 150 } 151 80 152 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); 153 __cfainit * it = 0p; 154 if(init_routine) { 155 it = alloc(); 156 (*it){init_routine, arg}; 157 } 82 158 processor * proc = alloc(); 83 (*proc){ "C-processor", *cl, init_routine, arg }; 159 (*proc){ "C-processor", *cl, get_thread(*it) }; 160 161 // Wait for the init thread to return before continuing 162 if(it) { 163 ^(*it){}; 164 free(it); 165 } 166 84 167 if(tid) *tid = proc->kernel_thread; 85 168 return 0; … … 162 245 int cfathread_mutex_init(cfathread_mutex_t *restrict mut, const cfathread_mutexattr_t *restrict) __attribute__((nonnull (1))) { *mut = new(); return 0; } 163 246 int cfathread_mutex_destroy(cfathread_mutex_t *mut) __attribute__((nonnull (1))) { delete( *mut ); return 0; } 164 int cfathread_mutex_lock (cfathread_mutex_t *mut) __attribute__((nonnull (1))) { lock ( (*mut)->impl ); return 0; } 165 int cfathread_mutex_trylock(cfathread_mutex_t *mut) __attribute__((nonnull (1))) { try_lock( (*mut)->impl ); return 0; } 166 int cfathread_mutex_unlock (cfathread_mutex_t *mut) __attribute__((nonnull (1))) { unlock ( (*mut)->impl ); return 0; } 247 int cfathread_mutex_lock (cfathread_mutex_t *mut) __attribute__((nonnull (1))) { lock( (*mut)->impl ); return 0; } 248 int cfathread_mutex_unlock (cfathread_mutex_t *mut) __attribute__((nonnull (1))) { unlock( (*mut)->impl ); return 0; } 249 int cfathread_mutex_trylock(cfathread_mutex_t *mut) __attribute__((nonnull (1))) { 250 bool ret = try_lock( (*mut)->impl ); 251 if( ret ) return 0; 252 else return EBUSY; 253 } 167 254 168 255 //-------------------- -
libcfa/src/concurrency/clib/cfathread.h
rf9c3100 r1f55a75 13 13 // Update Count : 14 14 // 15 16 #include "stddef.h"17 #include "invoke.h"18 15 19 16 #if defined(__cforall) || defined(__cplusplus) … … 32 29 int cfathread_cluster_create(cfathread_cluster_t * cluster); 33 30 cfathread_cluster_t cfathread_cluster_self(void); 31 int cfathread_cluster_print_stats(cfathread_cluster_t cluster); 34 32 int cfathread_cluster_add_worker(cfathread_cluster_t cluster, pthread_t* tid, void (*init_routine) (void *), void * arg); 35 33 int cfathread_cluster_pause (cfathread_cluster_t cluster);
Note:
See TracChangeset
for help on using the changeset viewer.