Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel.cfa

    r1805b1b r27f5f71  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Dec  1 17:52:57 2019
    13 // Update Count     : 45
     12// Last Modified On : Fri Nov 29 17:59:16 2019
     13// Update Count     : 35
    1414//
    1515
     
    4141//-----------------------------------------------------------------------------
    4242// Some assembly required
    43 #if defined( __i386 )
     43#if   defined( __i386 )
    4444        #define CtxGet( ctx )        \
    4545                __asm__ volatile (     \
     
    124124
    125125extern "C" {
    126         struct { __dllist_t(cluster) list; __spinlock_t lock; } __cfa_dbg_global_clusters;
     126struct { __dllist_t(cluster) list; __spinlock_t lock; } __cfa_dbg_global_clusters;
    127127}
    128128
     
    132132// Global state
    133133thread_local struct KernelThreadData kernelTLS __attribute__ ((tls_model ( "initial-exec" ))) = {
    134         NULL,                                                                                           // cannot use 0p
     134        NULL,
    135135        NULL,
    136136        { NULL, 1, false, false },
     
    141141// Struct to steal stack
    142142struct current_stack_info_t {
    143         __stack_t * storage;                                                            // pointer to stack object
    144         void * base;                                                                            // base of stack
    145         void * limit;                                                                           // stack grows towards stack limit
    146         void * context;                                                                         // address of cfa_context_t
     143        __stack_t * storage;            // pointer to stack object
     144        void *base;                             // base of stack
     145        void *limit;                    // stack grows towards stack limit
     146        void *context;                  // address of cfa_context_t
    147147};
    148148
     
    173173        name = "Main Thread";
    174174        state = Start;
    175         starter = 0p;
    176         last = 0p;
    177         cancellation = 0p;
     175        starter = NULL;
     176        last = NULL;
     177        cancellation = NULL;
    178178}
    179179
     
    186186        self_mon.recursion = 1;
    187187        self_mon_p = &self_mon;
    188         next = 0p;
    189 
    190         node.next = 0p;
    191         node.prev = 0p;
     188        next = NULL;
     189
     190        node.next = NULL;
     191        node.prev = NULL;
    192192        doregister(curr_cluster, this);
    193193
     
    213213        terminated{ 0 };
    214214        do_terminate = false;
    215         preemption_alarm = 0p;
     215        preemption_alarm = NULL;
    216216        pending_preemption = false;
    217217        runner.proc = &this;
     
    233233        }
    234234
    235         pthread_join( kernel_thread, 0p );
     235        pthread_join( kernel_thread, NULL );
    236236        free( this.stack );
    237237}
     
    280280                __cfaabi_dbg_print_safe("Kernel : core %p started\n", this);
    281281
    282                 thread_desc * readyThread = 0p;
     282                thread_desc * readyThread = NULL;
    283283                for( unsigned int spin_count = 0; ! __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST); spin_count++ )
    284284                {
     
    412412        processor * proc = (processor *) arg;
    413413        kernelTLS.this_processor = proc;
    414         kernelTLS.this_thread    = 0p;
     414        kernelTLS.this_thread    = NULL;
    415415        kernelTLS.preemption_state.[enabled, disable_count] = [false, 1];
    416416        // SKULLDUGGERY: We want to create a context for the processor coroutine
     
    425425
    426426        //Set global state
    427         kernelTLS.this_thread = 0p;
     427        kernelTLS.this_thread    = NULL;
    428428
    429429        //We now have a proper context from which to schedule threads
     
    441441        __cfaabi_dbg_print_safe("Kernel : core %p main ended (%p)\n", proc, &proc->runner);
    442442
    443         return 0p;
    444 }
    445 
    446 static void Abort( int ret, const char * func ) {
    447         if ( ret ) {
    448                 abort( "%s : internal error, error(%d) %s.", func, ret, strerror( ret ) );
    449         } // if
    450 } // Abort
    451 
    452 void * create_pthread( pthread_t * pthread, void * (*start)(void *), void * arg ) {
    453         pthread_attr_t attr;
    454 
    455         Abort( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
    456 
    457 #ifdef __CFA_DEBUG__
    458         size_t guardsize;
    459         Abort( pthread_attr_getguardsize( &attr, &guardsize ), "pthread_attr_getguardsize" );
    460         Abort( pthread_attr_setguardsize( &attr, guardsize ), "pthread_attr_setguardsize" );
    461 #endif
    462 
    463         size_t stacksize;
    464         Abort( pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" ); // default stack size, normally defined by shell limit
    465         assert( stacksize >= PTHREAD_STACK_MIN );
    466         void * stack = malloc( stacksize );
    467         Abort( pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" );
    468 
    469         Abort( pthread_create( pthread, &attr, start, arg ), "pthread_create" );
    470         return stack;
     443        return NULL;
    471444}
    472445
     
    474447        __cfaabi_dbg_print_safe("Kernel : Starting core %p\n", this);
    475448
    476         this->stack = create_pthread( &this->kernel_thread, CtxInvokeProcessor, (void *)this );
     449        pthread_attr_t attr;
     450        int ret;
     451        ret = pthread_attr_init( &attr );                                       // initialize attribute
     452        if ( ret ) {
     453                abort( "%s : internal error, pthread_attr_init failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) );
     454        } // if
     455
     456        size_t stacksize;
     457        ret = pthread_attr_getstacksize( &attr, &stacksize ); // default stack size, normally defined by shell limit
     458        if ( ret ) {
     459                abort( "%s : internal error, pthread_attr_getstacksize failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) );
     460        } // if
     461        assert( stacksize >= PTHREAD_STACK_MIN );
     462
     463        this->stack = malloc( stacksize );
     464        ret = pthread_attr_setstack( &attr, this->stack, stacksize );
     465        if ( ret ) {
     466                abort( "%s : internal error, pthread_attr_setstack failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) );
     467        } // if
     468
     469        ret = pthread_create( &this->kernel_thread, &attr, CtxInvokeProcessor, (void *)this );
     470        if ( ret ) {
     471                abort( "%s : internal error, pthread_create failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) );
     472        } // if
     473//      pthread_create( &this->kernel_thread, NULL, CtxInvokeProcessor, (void*)this );
    477474
    478475        __cfaabi_dbg_print_safe("Kernel : core %p started\n", this);
     
    531528        verify( ! kernelTLS.preemption_state.enabled );
    532529
    533         verifyf( thrd->next == 0p, "Expected null got %p", thrd->next );
     530        verifyf( thrd->next == NULL, "Expected null got %p", thrd->next );
    534531
    535532        with( *thrd->curr_cluster ) {
     
    710707        void ?{}(processorCtx_t & this, processor * proc) {
    711708                (this.__cor){ "Processor" };
    712                 this.__cor.starter = 0p;
     709                this.__cor.starter = NULL;
    713710                this.proc = proc;
    714711        }
     
    719716                terminated{ 0 };
    720717                do_terminate = false;
    721                 preemption_alarm = 0p;
     718                preemption_alarm = NULL;
    722719                pending_preemption = false;
    723720                kernel_thread = pthread_self();
     
    913910
    914911void V(semaphore & this) with( this ) {
    915         thread_desc * thrd = 0p;
     912        thread_desc * thrd = NULL;
    916913        lock( lock __cfaabi_dbg_ctx2 );
    917914        count += 1;
Note: See TracChangeset for help on using the changeset viewer.