Changes in / [3febb2d:3959595]


Ignore:
Location:
libcfa/src/concurrency
Files:
1 deleted
5 edited

Legend:

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

    r3febb2d r3959595  
    134134void ^?{}($coroutine& this) {
    135135        if(this.state != Halted && this.state != Start && this.state != Primed) {
    136                 $coroutine * src = TL_GET( this_thread )->curr_cor;
     136                $coroutine * src = active_coroutine();
    137137                $coroutine * dst = &this;
    138138
     
    240240
    241241        struct $coroutine * __cfactx_cor_finish(void) {
    242                 struct $coroutine * cor = kernelTLS.this_thread->curr_cor;
     242                struct $coroutine * cor = active_coroutine();
    243243
    244244                if(cor->state == Primed) {
  • libcfa/src/concurrency/coroutine.hfa

    r3febb2d r3959595  
    6363void prime(T & cor);
    6464
    65 static inline struct $coroutine * active_coroutine() { return TL_GET( this_thread )->curr_cor; }
     65static inline struct $coroutine * active_coroutine() { return active_thread()->curr_cor; }
    6666
    6767//-----------------------------------------------------------------------------
     
    8787
    8888        // set new coroutine that task is executing
    89         TL_GET( this_thread )->curr_cor = dst;
     89        active_thread()->curr_cor = dst;
    9090
    9191        // context switch to specified coroutine
     
    112112                // will also migrate which means this value will
    113113                // stay in syn with the TLS
    114                 $coroutine * src = TL_GET( this_thread )->curr_cor;
     114                $coroutine * src = active_coroutine();
    115115
    116116                assertf( src->last != 0,
     
    138138        // will also migrate which means this value will
    139139        // stay in syn with the TLS
    140         $coroutine * src = TL_GET( this_thread )->curr_cor;
     140        $coroutine * src = active_coroutine();
    141141        $coroutine * dst = get_coroutine(cor);
    142142
    143143        if( unlikely(dst->context.SP == 0p) ) {
    144                 TL_GET( this_thread )->curr_cor = dst;
     144                active_thread()->curr_cor = dst;
    145145                __stack_prepare(&dst->stack, 65000);
    146146                __cfactx_start(main, dst, cor, __cfactx_invoke_coroutine);
    147                 TL_GET( this_thread )->curr_cor = src;
     147                active_thread()->curr_cor = src;
    148148        }
    149149
     
    175175        // will also migrate which means this value will
    176176        // stay in syn with the TLS
    177         $coroutine * src = TL_GET( this_thread )->curr_cor;
     177        $coroutine * src = active_coroutine();
    178178
    179179        // not resuming self ?
  • libcfa/src/concurrency/exception.cfa

    r3febb2d r3959595  
    7272        void * stop_param;
    7373
    74         struct $thread * this_thread = TL_GET( this_thread );
     74        struct $thread * this_thread = active_thread();
    7575        if ( &this_thread->self_cor != this_thread->curr_cor ) {
    7676                struct $coroutine * cor = this_thread->curr_cor;
  • libcfa/src/concurrency/locks.cfa

    r3febb2d r3959595  
    7676
    7777void lock( blocking_lock & this ) with( this ) {
     78        $thread * thrd = active_thread();
    7879        lock( lock __cfaabi_dbg_ctx2 );
    79         if ( owner == kernelTLS.this_thread && !multi_acquisition) {
     80        if ( owner == thrd && !multi_acquisition) {
    8081                fprintf(stderr, "A single acquisition lock holder attempted to reacquire the lock resulting in a deadlock."); // Possibly throw instead
    8182        exit(EXIT_FAILURE);
    82         } else if ( owner != 0p && owner != kernelTLS.this_thread ) {
    83                 append( blocked_threads, kernelTLS.this_thread );
     83        } else if ( owner != 0p && owner != thrd ) {
     84                append( blocked_threads, thrd );
    8485                wait_count++;
    8586                unlock( lock );
    8687                park( );
    87         } else if ( owner == kernelTLS.this_thread && multi_acquisition ) {
     88        } else if ( owner == thrd && multi_acquisition ) {
    8889                recursion_count++;
    8990                unlock( lock );
    9091        } else {
    91                 owner = kernelTLS.this_thread;
     92                owner = thrd;
    9293                recursion_count = 1;
    9394                unlock( lock );
     
    9697
    9798bool try_lock( blocking_lock & this ) with( this ) {
     99        $thread * thrd = active_thread();
    98100        bool ret = false;
    99101        lock( lock __cfaabi_dbg_ctx2 );
    100102        if ( owner == 0p ) {
    101                 owner = kernelTLS.this_thread;
     103                owner = thrd;
    102104                if ( multi_acquisition ) recursion_count = 1;
    103105                ret = true;
    104         } else if ( owner == kernelTLS.this_thread && multi_acquisition ) {
     106        } else if ( owner == thrd && multi_acquisition ) {
    105107                recursion_count++;
    106108                ret = true;
     
    113115        lock( lock __cfaabi_dbg_ctx2 );
    114116        if ( owner == 0p ){ // no owner implies lock isn't held
    115                 fprintf( stderr, "There was an attempt to release a lock that isn't held" ); 
     117                fprintf( stderr, "There was an attempt to release a lock that isn't held" );
    116118                return;
    117         } else if ( strict_owner && owner != kernelTLS.this_thread ) {
    118                 fprintf( stderr, "A thread other than the owner attempted to release an owner lock" ); 
     119        } else if ( strict_owner && active_thread() ) {
     120                fprintf( stderr, "A thread other than the owner attempted to release an owner lock" );
    119121                return;
    120122        }
     
    163165    lock( lock __cfaabi_dbg_ctx2 );
    164166        if ( owner == 0p ){ // no owner implies lock isn't held
    165                 fprintf( stderr, "A lock that is not held was passed to a synchronization lock" ); 
    166         } else if ( strict_owner && owner != kernelTLS.this_thread ) {
    167                 fprintf( stderr, "A thread other than the owner of a lock passed it to a synchronization lock" ); 
     167                fprintf( stderr, "A lock that is not held was passed to a synchronization lock" );
     168        } else if ( strict_owner && active_thread() ) {
     169                fprintf( stderr, "A thread other than the owner of a lock passed it to a synchronization lock" );
    168170        } else {
    169171                $thread * thrd = pop_head( blocked_threads );
     
    246248                                unlock( cond->lock );
    247249                                #if !defined( __CFA_NO_STATISTICS__ )
     250                                        #warning unprotected access to tls TODO discuss this
    248251                                        kernelTLS.this_stats = copy->t->curr_cluster->stats;
    249252                                #endif
     
    338341                        remove_( *i.lock );
    339342                }
    340                
     343
    341344                unlock( lock );
    342345                park( ); // blocks here
     
    374377
    375378        void wait( condition_variable(L) & this ) with(this) {
    376                 info_thread( L ) i = { kernelTLS.this_thread };
     379                info_thread( L ) i = { active_thread() };
    377380                queue_info_thread( this, i );
    378381        }
    379382
    380383        void wait( condition_variable(L) & this, uintptr_t info ) with(this) {
    381                 info_thread( L ) i = { kernelTLS.this_thread, info };
     384                info_thread( L ) i = { active_thread(), info };
    382385                queue_info_thread( this, i );
    383386        }
    384        
     387
    385388        void wait( condition_variable(L) & this, Duration duration ) with(this) {
    386                 info_thread( L ) i = { kernelTLS.this_thread };
     389                info_thread( L ) i = { active_thread() };
    387390                queue_info_thread_timeout(this, i, __kernel_get_time() + duration );
    388391        }
    389392
    390         void wait( condition_variable(L) & this, uintptr_t info, Duration duration ) with(this) { 
    391                 info_thread( L ) i = { kernelTLS.this_thread, info };
     393        void wait( condition_variable(L) & this, uintptr_t info, Duration duration ) with(this) {
     394                info_thread( L ) i = { active_thread(), info };
    392395                queue_info_thread_timeout(this, i, __kernel_get_time() + duration );
    393396        }
    394397
    395398        void wait( condition_variable(L) & this, Time time ) with(this) {
    396                 info_thread( L ) i = { kernelTLS.this_thread };
     399                info_thread( L ) i = { active_thread() };
    397400                queue_info_thread_timeout(this, i, time);
    398401        }
    399402
    400403        void wait( condition_variable(L) & this, uintptr_t info, Time time ) with(this) {
    401                 info_thread( L ) i = { kernelTLS.this_thread, info };
     404                info_thread( L ) i = { active_thread(), info };
    402405                queue_info_thread_timeout(this, i, time);
    403406        }
    404407
    405408        void wait( condition_variable(L) & this, L & l ) with(this) {
    406                 info_thread(L) i = { kernelTLS.this_thread };
     409                info_thread(L) i = { active_thread() };
    407410                i.lock = &l;
    408411                queue_info_thread( this, i );
     
    410413
    411414        void wait( condition_variable(L) & this, L & l, uintptr_t info ) with(this) {
    412                 info_thread(L) i = { kernelTLS.this_thread, info };
     415                info_thread(L) i = { active_thread(), info };
    413416                i.lock = &l;
    414417                queue_info_thread( this, i );
    415418        }
    416        
     419
    417420        void wait( condition_variable(L) & this, L & l, Duration duration ) with(this) {
    418                 info_thread(L) i = { kernelTLS.this_thread };
     421                info_thread(L) i = { active_thread() };
    419422                i.lock = &l;
    420423                queue_info_thread_timeout(this, i, __kernel_get_time() + duration );
    421424        }
    422        
     425
    423426        void wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration ) with(this) {
    424                 info_thread(L) i = { kernelTLS.this_thread, info };
     427                info_thread(L) i = { active_thread(), info };
    425428                i.lock = &l;
    426429                queue_info_thread_timeout(this, i, __kernel_get_time() + duration );
    427430        }
    428        
     431
    429432        void wait( condition_variable(L) & this, L & l, Time time ) with(this) {
    430                 info_thread(L) i = { kernelTLS.this_thread };
     433                info_thread(L) i = { active_thread() };
    431434                i.lock = &l;
    432435                queue_info_thread_timeout(this, i, time );
    433436        }
    434        
     437
    435438        void wait( condition_variable(L) & this, L & l, uintptr_t info, Time time ) with(this) {
    436                 info_thread(L) i = { kernelTLS.this_thread, info };
     439                info_thread(L) i = { active_thread(), info };
    437440                i.lock = &l;
    438441                queue_info_thread_timeout(this, i, time );
  • libcfa/src/concurrency/mutex.cfa

    r3febb2d r3959595  
    4040        lock( lock __cfaabi_dbg_ctx2 );
    4141        if( is_locked ) {
    42                 append( blocked_threads, kernelTLS.this_thread );
     42                append( blocked_threads, active_thread() );
    4343                unlock( lock );
    4444                park();
     
    8686        lock( lock __cfaabi_dbg_ctx2 );
    8787        if( owner == 0p ) {
    88                 owner = kernelTLS.this_thread;
     88                owner = active_thread();
    8989                recursion_count = 1;
    9090                unlock( lock );
    9191        }
    92         else if( owner == kernelTLS.this_thread ) {
     92        else if( owner == active_thread() ) {
    9393                recursion_count++;
    9494                unlock( lock );
    9595        }
    9696        else {
    97                 append( blocked_threads, kernelTLS.this_thread );
     97                append( blocked_threads, active_thread() );
    9898                unlock( lock );
    9999                park();
     
    105105        lock( lock __cfaabi_dbg_ctx2 );
    106106        if( owner == 0p ) {
    107                 owner = kernelTLS.this_thread;
     107                owner = active_thread();
    108108                recursion_count = 1;
    109109                ret = true;
    110110        }
    111         else if( owner == kernelTLS.this_thread ) {
     111        else if( owner == active_thread() ) {
    112112                recursion_count++;
    113113                ret = true;
     
    159159void wait(condition_variable & this) {
    160160        lock( this.lock __cfaabi_dbg_ctx2 );
    161         append( this.blocked_threads, kernelTLS.this_thread );
     161        append( this.blocked_threads, active_thread() );
    162162        unlock( this.lock );
    163163        park();
     
    167167void wait(condition_variable & this, L & l) {
    168168        lock( this.lock __cfaabi_dbg_ctx2 );
    169         append( this.blocked_threads, kernelTLS.this_thread );
     169        append( this.blocked_threads, active_thread() );
    170170        unlock(l);
    171171        unlock(this.lock);
Note: See TracChangeset for help on using the changeset viewer.