Changeset af67ee1 for libcfa/src


Ignore:
Timestamp:
Aug 27, 2021, 12:51:55 PM (3 years ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, pthread-emulation, qualifiedEnum
Children:
1b97976c
Parents:
9f5a19fa
Message:

Added support for locks as parameters to mutex stmt

Location:
libcfa/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/Makefile.am

    r9f5a19fa raf67ee1  
    116116        concurrency/monitor.hfa \
    117117        concurrency/mutex.hfa \
    118         concurrency/thread.hfa
     118        concurrency/thread.hfa \
     119        concurrency/mutex_stmt.hfa
    119120
    120121thread_libsrc = ${inst_thread_headers_src} ${inst_thread_headers_src:.hfa=.cfa} \
  • libcfa/src/concurrency/monitor.cfa

    r9f5a19fa raf67ee1  
    990990}
    991991
     992//-----------------------------------------------------------------------------
     993// Enter routine for mutex stmt
     994// Can't be accepted since a mutex stmt is effectively an anonymous routine
     995// Thus we do not need a monitor group
     996void lock( monitor$ * this ) {
     997        thread$ * thrd = active_thread();
     998
     999        // Lock the monitor spinlock
     1000        lock( this->lock __cfaabi_dbg_ctx2 );
     1001
     1002        __cfaabi_dbg_print_safe( "Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
     1003
     1004        if( unlikely(0 != (0x1 & (uintptr_t)this->owner)) ) {
     1005                abort( "Attempt by thread \"%.256s\" (%p) to access joined monitor %p.", thrd->self_cor.name, thrd, this );
     1006        }
     1007        else if( !this->owner ) {
     1008                // No one has the monitor, just take it
     1009                __set_owner( this, thrd );
     1010
     1011                __cfaabi_dbg_print_safe( "Kernel :  mon is free \n" );
     1012        }
     1013        else if( this->owner == thrd) {
     1014                // We already have the monitor, just note how many times we took it
     1015                this->recursion += 1;
     1016
     1017                __cfaabi_dbg_print_safe( "Kernel :  mon already owned \n" );
     1018        }
     1019        else {
     1020                __cfaabi_dbg_print_safe( "Kernel :  blocking \n" );
     1021
     1022                // Some one else has the monitor, wait in line for it
     1023                /* paranoid */ verify( thrd->link.next == 0p );
     1024                append( this->entry_queue, thrd );
     1025                /* paranoid */ verify( thrd->link.next == 1p );
     1026
     1027                unlock( this->lock );
     1028                park();
     1029
     1030                __cfaabi_dbg_print_safe( "Kernel : %10p Entered  mon %p\n", thrd, this);
     1031
     1032                /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
     1033                return;
     1034        }
     1035
     1036        __cfaabi_dbg_print_safe( "Kernel : %10p Entered  mon %p\n", thrd, this);
     1037
     1038        /* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
     1039        /* paranoid */ verify( this->lock.lock );
     1040
     1041        // Release the lock and leave
     1042        unlock( this->lock );
     1043        return;
     1044}
     1045
     1046// Leave routine for mutex stmt
     1047// Is just a wrapper around __leave for the is_lock trait to see
     1048void unlock( monitor$ * this ) { __leave( this ); }
     1049
    9921050// Local Variables: //
    9931051// mode: c //
  • libcfa/src/concurrency/monitor.hfa

    r9f5a19fa raf67ee1  
    149149void __waitfor_internal( const __waitfor_mask_t & mask, int duration );
    150150
     151// lock and unlock routines for mutex statements to use
     152void lock( monitor$ * this );
     153void unlock( monitor$ * this );
     154
    151155// Local Variables: //
    152156// mode: c //
Note: See TracChangeset for help on using the changeset viewer.