Changes in / [0d4456b:6403ae5]


Ignore:
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/Makefile.am

    r0d4456b r6403ae5  
    9696        concurrency/exception.hfa \
    9797        concurrency/kernel.hfa \
    98         concurrency/locks.hfa \
    9998        concurrency/monitor.hfa \
    10099        concurrency/mutex.hfa \
  • libcfa/src/concurrency/locks.cfa

    r0d4456b r6403ae5  
    5151}
    5252
    53 void ?{}( single_acquisition_lock & this ) {
     53void ?{}( mutex_lock & this ) {
    5454        ((blocking_lock &)this){ false, false };
    5555}
    5656
    57 void ^?{}( single_acquisition_lock & this ) {
     57void ^?{}( mutex_lock & this ) {
    5858        // default
    5959}
     
    6767}
    6868
    69 void ?{}( multiple_acquisition_lock & this ) {
     69void ?{}( recursive_mutex_lock & this ) {
    7070        ((blocking_lock &)this){ true, false };
    7171}
    7272
    73 void ^?{}( multiple_acquisition_lock & this ) {
     73void ^?{}( recursive_mutex_lock & this ) {
    7474        // default
    7575}
    7676
    7777void lock( blocking_lock & this ) with( this ) {
     78        $thread * thrd = active_thread();
    7879        lock( lock __cfaabi_dbg_ctx2 );
    79         if ( owner == active_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 != active_thread() ) {
    83                 append( blocked_threads, active_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 == active_thread() && multi_acquisition ) {
     88        } else if ( owner == thrd && multi_acquisition ) {
    8889                recursion_count++;
    8990                unlock( lock );
    9091        } else {
    91                 owner = active_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 = active_thread();
    102                 recursion_count = 1;
     103                owner = thrd;
     104                if ( multi_acquisition ) recursion_count = 1;
    103105                ret = true;
    104         } else if ( owner == active_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 != active_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        }
     
    123125                $thread * thrd = pop_head( blocked_threads );
    124126                owner = thrd;
    125                 recursion_count = ( thrd ? 1 : 0 );
     127                recursion_count = ( thrd && multi_acquisition ? 1 : 0 );
    126128                wait_count--;
    127129                unpark( thrd );
     
    151153        } else {
    152154                owner = t;
    153                 recursion_count = 1;
     155                if ( multi_acquisition ) recursion_count = 1;
    154156                #if !defined( __CFA_NO_STATISTICS__ )
    155                         //kernelTLS.this_stats = t->curr_cluster->stats;
     157                        kernelTLS.this_stats = t->curr_cluster->stats;
    156158                #endif
    157159                unpark( t );
     
    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 != active_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 );
    170172                owner = thrd;
    171                 recursion_count = ( thrd ? 1 : 0 );
     173                recursion_count = ( thrd && multi_acquisition ? 1 : 0 );
    172174                wait_count--;
    173175                unpark( thrd );
     
    182184// This is temporary until an inheritance bug is fixed
    183185
    184 void lock( single_acquisition_lock & this ){
     186void lock( mutex_lock & this ){
    185187        lock( (blocking_lock &)this );
    186188}
    187189
    188 void unlock( single_acquisition_lock & this ){
     190void unlock( mutex_lock & this ){
    189191        unlock( (blocking_lock &)this );
    190192}
    191193
    192 void add_( single_acquisition_lock & this, struct $thread * t ){
     194void add_( mutex_lock & this, struct $thread * t ){
    193195        add_( (blocking_lock &)this, t );
    194196}
    195197
    196 void remove_( single_acquisition_lock & this ){
     198void remove_( mutex_lock & this ){
    197199        remove_( (blocking_lock &)this );
    198200}
    199201
    200 void set_recursion_count( single_acquisition_lock & this, size_t recursion ){
     202void set_recursion_count( mutex_lock & this, size_t recursion ){
    201203        set_recursion_count( (blocking_lock &)this, recursion );
    202204}
    203205
    204 size_t get_recursion_count( single_acquisition_lock & this ){
    205         return get_recursion_count( (blocking_lock &)this );
    206 }
    207 
    208 void lock( owner_lock & this ){
     206size_t get_recursion_count( mutex_lock & this ){
     207        get_recursion_count( (blocking_lock &)this );
     208}
     209
     210void lock( recursive_mutex_lock & this ){
    209211        lock( (blocking_lock &)this );
    210212}
    211213
    212 void unlock( owner_lock & this ){
     214void unlock( recursive_mutex_lock & this ){
    213215        unlock( (blocking_lock &)this );
    214216}
    215217
    216 void add_( owner_lock & this, struct $thread * t ){
     218void add_( recursive_mutex_lock & this, struct $thread * t ){
    217219        add_( (blocking_lock &)this, t );
    218220}
    219221
    220 void remove_( owner_lock & this ){
     222void remove_( recursive_mutex_lock & this ){
    221223        remove_( (blocking_lock &)this );
    222224}
    223225
    224 void set_recursion_count( owner_lock & this, size_t recursion ){
     226void set_recursion_count( recursive_mutex_lock & this, size_t recursion ){
    225227        set_recursion_count( (blocking_lock &)this, recursion );
    226228}
    227229
    228 size_t get_recursion_count( owner_lock & this ){
    229         return get_recursion_count( (blocking_lock &)this );
    230 }
    231 
    232 void lock( multiple_acquisition_lock & this ){
    233         lock( (blocking_lock &)this );
    234 }
    235 
    236 void unlock( multiple_acquisition_lock & this ){
    237         unlock( (blocking_lock &)this );
    238 }
    239 
    240 void add_( multiple_acquisition_lock & this, struct $thread * t ){
    241         add_( (blocking_lock &)this, t );
    242 }
    243 
    244 void remove_( multiple_acquisition_lock & this ){
    245         remove_( (blocking_lock &)this );
    246 }
    247 
    248 void set_recursion_count( multiple_acquisition_lock & this, size_t recursion ){
    249         set_recursion_count( (blocking_lock &)this, recursion );
    250 }
    251 
    252 size_t get_recursion_count( multiple_acquisition_lock & this ){
    253         return get_recursion_count( (blocking_lock &)this );
     230size_t get_recursion_count( recursive_mutex_lock & this ){
     231        get_recursion_count( (blocking_lock &)this );
    254232}
    255233
     
    266244                info_thread(L) * copy = *i;
    267245                        remove( cond->blocked_threads, i );              //remove this thread O(1)
    268                         cond->count--;
     246                        cond->wait_count--;
    269247                        if( !copy->lock ) {
     248                                unlock( cond->lock );
    270249                                #if !defined( __CFA_NO_STATISTICS__ )
    271                                         //kernelTLS.this_stats = copy->t->curr_cluster->stats;
     250                                        #warning unprotected access to tls TODO discuss this
     251                                        kernelTLS.this_stats = copy->t->curr_cluster->stats;
    272252                                #endif
    273253                                unpark( copy->t );
     
    305285                bool ret = !!blocked_threads;
    306286                info_thread(L) * popped = pop_head( blocked_threads );
     287                popped->listed = false;
    307288                if(popped != 0p) {
    308                         popped->listed = false;
    309289                        count--;
    310290                        if (popped->lock) {
     
    323303                while( blocked_threads ) {
    324304                        info_thread(L) * popped = pop_head( blocked_threads );
     305                        popped->listed = false;
    325306                        if(popped != 0p){
    326                                 popped->listed = false;
    327307                                count--;
    328308                                if (popped->lock) {
     
    361341                        remove_( *i.lock );
    362342                }
    363                
     343
    364344                unlock( lock );
    365345                park( ); // blocks here
     
    405385                queue_info_thread( this, i );
    406386        }
    407        
     387
    408388        void wait( condition_variable(L) & this, Duration duration ) with(this) {
    409389                info_thread( L ) i = { active_thread() };
     
    411391        }
    412392
    413         void wait( condition_variable(L) & this, uintptr_t info, Duration duration ) with(this) { 
     393        void wait( condition_variable(L) & this, uintptr_t info, Duration duration ) with(this) {
    414394                info_thread( L ) i = { active_thread(), info };
    415395                queue_info_thread_timeout(this, i, __kernel_get_time() + duration );
     
    437417                queue_info_thread( this, i );
    438418        }
    439        
     419
    440420        void wait( condition_variable(L) & this, L & l, Duration duration ) with(this) {
    441421                info_thread(L) i = { active_thread() };
     
    443423                queue_info_thread_timeout(this, i, __kernel_get_time() + duration );
    444424        }
    445        
     425
    446426        void wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration ) with(this) {
    447427                info_thread(L) i = { active_thread(), info };
     
    449429                queue_info_thread_timeout(this, i, __kernel_get_time() + duration );
    450430        }
    451        
     431
    452432        void wait( condition_variable(L) & this, L & l, Time time ) with(this) {
    453433                info_thread(L) i = { active_thread() };
     
    455435                queue_info_thread_timeout(this, i, time );
    456436        }
    457        
     437
    458438        void wait( condition_variable(L) & this, L & l, uintptr_t info, Time time ) with(this) {
    459439                info_thread(L) i = { active_thread(), info };
     
    462442        }
    463443}
    464 
    465 // thread T1 {};
    466 // thread T2 {};
    467 
    468 // multiple_acquisition_lock m;
    469 // condition_variable( multiple_acquisition_lock ) c;
    470 
    471 // void main( T1 & this ) {
    472 //      printf("T1 start\n");
    473 //      lock(m);
    474 //      printf("%d\n", counter(c));
    475 //      if(empty(c)) {
    476 //              printf("T1 wait\n");
    477 //              wait(c,m,12);
    478 //      }else{
    479 //              printf("%d\n", front(c));
    480 //              notify_one(c);
    481 //      }
    482 //      unlock(m);
    483 //      printf("curr thd in main %p \n", active_thread());
    484 //      printf("T1 waits for 2s\n");
    485 //      lock(m);
    486 //      wait( c, m, 2`s );
    487 //      unlock(m);
    488 //      printf("T1 wakes\n");
    489 //      printf("T1 done\n");
    490 // }
    491 
    492 // void main( T2 & this ) {
    493 //      printf("T2 start\n");
    494 //      lock(m);
    495 //      printf("%d\n", counter(c));
    496 //      if(empty(c)) {
    497 //              printf("T2 wait\n");
    498 //              wait(c,m,12);
    499 //      }else{
    500 //              printf("%d\n", front(c));
    501 //              notify_one(c);
    502 //      }
    503 //      unlock(m);
    504 //      printf("T2 done\n");
    505 // }
    506 
    507 // int main() {
    508 //      printf("start\n");
    509 //      processor p[2];
    510 //      {
    511 //              T1 t1;
    512 //              T2 t2;
    513 //      }
    514 //      printf("done\n");
    515 // }
  • libcfa/src/concurrency/locks.hfa

    r0d4456b r6403ae5  
    4949//// Blocking Locks
    5050///////////////////////////////////////////////////////////////////
    51 
    5251struct blocking_lock {
    5352        // Spin lock used for mutual exclusion
     
    7372};
    7473
    75 struct single_acquisition_lock {
     74struct mutex_lock {
    7675        inline blocking_lock;
    7776};
     
    8180};
    8281
    83 struct multiple_acquisition_lock {
     82struct recursive_mutex_lock {
    8483        inline blocking_lock;
    8584};
     
    8887void ^?{}( blocking_lock & this );
    8988
    90 void ?{}( single_acquisition_lock & this );
    91 void ^?{}( single_acquisition_lock & this );
     89void ?{}( mutex_lock & this );
     90void ^?{}( mutex_lock & this );
    9291
    9392void ?{}( owner_lock & this );
    9493void ^?{}( owner_lock & this );
    9594
    96 void ?{}( multiple_acquisition_lock & this );
    97 void ^?{}( multiple_acquisition_lock & this );
     95void ?{}( recursive_mutex_lock & this );
     96void ^?{}( recursive_mutex_lock & this );
    9897
    9998void lock( blocking_lock & this );
     
    106105size_t get_recursion_count( blocking_lock & this );
    107106
    108 void lock( single_acquisition_lock & this );
    109 void unlock( single_acquisition_lock & this );
    110 void add_( single_acquisition_lock & this, struct $thread * t );
    111 void remove_( single_acquisition_lock & this );
    112 void set_recursion_count( single_acquisition_lock & this, size_t recursion );
    113 size_t get_recursion_count( single_acquisition_lock & this );
     107void lock( mutex_lock & this );
     108void unlock( mutex_lock & this );
     109void add_( mutex_lock & this, struct $thread * t );
     110void remove_( mutex_lock & this );
     111void set_recursion_count( mutex_lock & this, size_t recursion );
     112size_t get_recursion_count( mutex_lock & this );
    114113
    115 void lock( owner_lock & this );
    116 void unlock( owner_lock & this );
    117 void add_( owner_lock & this, struct $thread * t );
    118 void remove_( owner_lock & this );
    119 void set_recursion_count( owner_lock & this, size_t recursion );
    120 size_t get_recursion_count( owner_lock & this );
    121 
    122 void lock( multiple_acquisition_lock & this );
    123 void unlock( multiple_acquisition_lock & this );
    124 void add_( multiple_acquisition_lock & this, struct $thread * t );
    125 void remove_( multiple_acquisition_lock & this );
    126 void set_recursion_count( multiple_acquisition_lock & this, size_t recursion );
    127 size_t get_recursion_count( multiple_acquisition_lock & this );
     114void lock( recursive_mutex_lock & this );
     115void unlock( recursive_mutex_lock & this );
     116void add_( recursive_mutex_lock & this, struct $thread * t );
     117void remove_( recursive_mutex_lock & this );
     118void set_recursion_count( recursive_mutex_lock & this, size_t recursion );
     119size_t get_recursion_count( recursive_mutex_lock & this );
    128120
    129121///////////////////////////////////////////////////////////////////
  • src/AST/Convert.cpp

    r0d4456b r6403ae5  
    99// Author           : Thierry Delisle
    1010// Created On       : Thu May 09 15::37::05 2019
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Nov 12 10:07:00 2020
    13 // Update Count     : 34
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 21:39:32 2019
     13// Update Count     : 33
    1414//
    1515
     
    187187                auto init = get<Initializer>().accept1( node->init );
    188188                decl->init = init;
    189 
     189               
    190190                this->node = decl;
    191191                return nullptr;
     
    28122812        }
    28132813        deleteAll(translationUnit);
    2814 
    2815         // Load the local static varables into the global store.
    2816         unit.global.sizeType = ast::sizeType;
    2817         unit.global.dereference = ast::dereferenceOperator;
    2818         unit.global.dtorStruct = ast::dtorStruct;
    2819         unit.global.dtorDestroy = ast::dtorStructDestroy;
    2820 
    28212814        return unit;
    28222815}
Note: See TracChangeset for help on using the changeset viewer.