Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/clib/cfathread.cfa

    rd27b6be rf03e11d  
    1717#include "locks.hfa"
    1818#include "kernel.hfa"
    19 #include "stats.hfa"
    2019#include "thread.hfa"
    2120#include "time.hfa"
    2221
    2322#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
    3223
    3324struct cfathread_object {
     
    7465}
    7566
    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
     67processor * procs = 0p;
     68int proc_cnt = 1;
     69
    13470extern "C" {
    13571        int cfathread_cluster_create(cfathread_cluster_t * cl) __attribute__((nonnull(1))) {
     
    14278        }
    14379
    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 
    15280        int cfathread_cluster_add_worker(cfathread_cluster_t cl, pthread_t* tid, void (*init_routine) (void *), void * arg) {
    153                 __cfainit * it = 0p;
    154                 if(init_routine) {
    155                         it = alloc();
    156                         (*it){init_routine, arg};
    157                 }
     81                // processor * proc = new("C-processor", *cl, init_routine, arg);
    15882                processor * proc = alloc();
    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 
     83                (*proc){ "C-processor", *cl, init_routine, arg };
    16784                if(tid) *tid = proc->kernel_thread;
    16885                return 0;
     
    245162        int cfathread_mutex_init(cfathread_mutex_t *restrict mut, const cfathread_mutexattr_t *restrict) __attribute__((nonnull (1))) { *mut = new(); return 0; }
    246163        int cfathread_mutex_destroy(cfathread_mutex_t *mut) __attribute__((nonnull (1))) { delete( *mut ); 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         }
     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; }
    254167
    255168        //--------------------
Note: See TracChangeset for help on using the changeset viewer.