Ignore:
Timestamp:
Jan 7, 2021, 2:55:57 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
58fe85a
Parents:
bdfc032 (diff), 44e37ef (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.
Message:

Merge branch 'master' into dkobets-vector

File:
1 edited

Legend:

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

    rbdfc032 reef8dfb  
    3030        this.lock{};
    3131        this.blocked_threads{};
     32        this.is_locked = false;
    3233}
    3334
     
    3940        lock( lock __cfaabi_dbg_ctx2 );
    4041        if( is_locked ) {
    41                 append( blocked_threads, kernelTLS.this_thread );
    42                 BlockInternal( &lock );
     42                append( blocked_threads, active_thread() );
     43                unlock( lock );
     44                park();
    4345        }
    4446        else {
     
    6264        lock( this.lock __cfaabi_dbg_ctx2 );
    6365        this.is_locked = (this.blocked_threads != 0);
    64         WakeThread(
     66        unpark(
    6567                pop_head( this.blocked_threads )
    6668        );
     
    8486        lock( lock __cfaabi_dbg_ctx2 );
    8587        if( owner == 0p ) {
    86                 owner = kernelTLS.this_thread;
     88                owner = active_thread();
    8789                recursion_count = 1;
    8890                unlock( lock );
    8991        }
    90         else if( owner == kernelTLS.this_thread ) {
     92        else if( owner == active_thread() ) {
    9193                recursion_count++;
    9294                unlock( lock );
    9395        }
    9496        else {
    95                 append( blocked_threads, kernelTLS.this_thread );
    96                 BlockInternal( &lock );
     97                append( blocked_threads, active_thread() );
     98                unlock( lock );
     99                park();
    97100        }
    98101}
     
    102105        lock( lock __cfaabi_dbg_ctx2 );
    103106        if( owner == 0p ) {
    104                 owner = kernelTLS.this_thread;
     107                owner = active_thread();
    105108                recursion_count = 1;
    106109                ret = true;
    107110        }
    108         else if( owner == kernelTLS.this_thread ) {
     111        else if( owner == active_thread() ) {
    109112                recursion_count++;
    110113                ret = true;
     
    118121        recursion_count--;
    119122        if( recursion_count == 0 ) {
    120                 thread_desc * thrd = pop_head( blocked_threads );
     123                $thread * thrd = pop_head( blocked_threads );
    121124                owner = thrd;
    122125                recursion_count = (thrd ? 1 : 0);
    123                 WakeThread( thrd );
     126                unpark( thrd );
    124127        }
    125128        unlock( lock );
     
    138141void notify_one(condition_variable & this) with(this) {
    139142        lock( lock __cfaabi_dbg_ctx2 );
    140         WakeThread(
     143        unpark(
    141144                pop_head( this.blocked_threads )
    142145        );
     
    147150        lock( lock __cfaabi_dbg_ctx2 );
    148151        while(this.blocked_threads) {
    149                 WakeThread(
     152                unpark(
    150153                        pop_head( this.blocked_threads )
    151154                );
     
    156159void wait(condition_variable & this) {
    157160        lock( this.lock __cfaabi_dbg_ctx2 );
    158         append( this.blocked_threads, kernelTLS.this_thread );
    159         BlockInternal( &this.lock );
     161        append( this.blocked_threads, active_thread() );
     162        unlock( this.lock );
     163        park();
    160164}
    161165
     
    163167void wait(condition_variable & this, L & l) {
    164168        lock( this.lock __cfaabi_dbg_ctx2 );
    165         append( this.blocked_threads, kernelTLS.this_thread );
    166         void __unlock(void) {
    167                 unlock(l);
    168                 unlock(this.lock);
    169         }
    170         BlockInternal( __unlock );
     169        append( this.blocked_threads, active_thread() );
     170        unlock(l);
     171        unlock(this.lock);
     172        park();
    171173        lock(l);
    172174}
Note: See TracChangeset for help on using the changeset viewer.