Changeset cd348e7 for src/libcfa


Ignore:
Timestamp:
Apr 19, 2017, 2:39:01 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
8731d8c
Parents:
154fdc8
Message:

Fixed mutual exclusion on monitors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/monitor.c

    r154fdc8 rcd348e7  
    3333                thread_desc * thrd = this_thread();
    3434
    35                 //Update the stack owner
    36                 this->stack_owner = leader;
     35                // //Update the stack owner
     36                // this->stack_owner = leader;
     37
     38                LIB_DEBUG_PRINT_SAFE("Entering %p (o: %p, r: %i)\n", this, this->owner, this->recursion);
    3739
    3840                if( !this->owner ) {
    3941                        //No one has the monitor, just take it
    40                         this->owner = thrd;
    41                         this->recursion = 1;
     42                        set_owner( this, thrd );
    4243                }
    4344                else if( this->owner == thrd) {
     
    7778                lock( &this->lock );
    7879
     80                LIB_DEBUG_PRINT_SAFE("Leaving %p (o: %p, r: %i)\n", this, this->owner, this->recursion);
     81
    7982                thread_desc * thrd = this_thread();
    80                 assert( thrd == this->owner || this->stack_owner );
     83                assertf( thrd == this->owner, "Expected owner to be %p, got %p (r: %i)", this->owner, thrd, this->recursion );
    8184
    8285                //Leaving a recursion level, decrement the counter
     
    8689                //it means we don't need to do anything
    8790                if( this->recursion != 0) {
    88                         this->stack_owner = leader;
     91                        // this->stack_owner = leader;
    8992                        unlock( &this->lock );
    9093                        return;
    9194                }
    9295                       
    93                 //If we don't own the signal stack then just leave it to the owner
    94                 if( this->stack_owner ) {
    95                         this->stack_owner = leader;
    96                         unlock( &this->lock );
    97                         return;
    98                 }
     96                // //If we don't own the signal stack then just leave it to the owner
     97                // if( this->stack_owner ) {
     98                //      this->stack_owner = leader;
     99                //      unlock( &this->lock );
     100                //      return;
     101                // }
    99102
    100103                //We are the stack owner and have left the last recursion level.
     
    108111                        //transfer control immediately
    109112                        set_owner( this, new_owner );
    110                         this->stack_owner = leader;
     113                        // this->stack_owner = leader;
    111114                        ScheduleInternal( &this->lock, new_owner );
    112115                        return;
     
    118121                set_owner( this, new_owner );
    119122
    120                 //Update the stack owner
    121                 this->stack_owner = leader;
     123                // //Update the stack owner
     124                // this->stack_owner = leader;
    122125
    123126                //We can now let other threads in safely
     
    138141static inline void leave(monitor_desc ** monitors, int count) {
    139142        __leave_monitor_desc( monitors[0], NULL );
    140         for(int i = count - 1; i >= 0; i--) {
     143        for(int i = count - 1; i >= 1; i--) {
    141144                __leave_monitor_desc( monitors[i], monitors[0] );
    142145        }
     
    166169// Internal scheduling
    167170void wait( condition * this ) {
     171        assertf(false, "NO SUPPORTED");
    168172        // LIB_DEBUG_FPRINTF("Waiting\n");
    169173        thread_desc * this_thrd = this_thread();
     
    236240
    237241static void __signal_internal( condition * this ) {
     242        assertf(false, "NO SUPPORTED");
    238243        if( !this->blocked.head ) return;
    239244
Note: See TracChangeset for help on using the changeset viewer.