Changes in / [7a8f62c3:1def117b]


Ignore:
Files:
6 added
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/Makefile.am

    r7a8f62c3 r1def117b  
    6262        iterator.hfa \
    6363        limits.hfa \
     64        memory.hfa \
    6465        parseargs.hfa \
    6566        rational.hfa \
  • libcfa/src/concurrency/monitor.cfa

    r7a8f62c3 r1def117b  
    8989        __cfaabi_dbg_print_safe( "Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
    9090
    91         if( !this->owner ) {
     91        if( unlikely(0 != (0x1 & (uintptr_t)this->owner)) ) {
     92                abort( "Attempt by thread \"%.256s\" (%p) to access joined monitor %p.", thrd->self_cor.name, thrd, this );
     93        }
     94        else if( !this->owner ) {
    9295                // No one has the monitor, just take it
    9396                __set_owner( this, thrd );
     
    137140}
    138141
    139 static void __dtor_enter( $monitor * this, fptr_t func ) {
     142static void __dtor_enter( $monitor * this, fptr_t func, bool join ) {
    140143        // Lock the monitor spinlock
    141144        lock( this->lock __cfaabi_dbg_ctx2 );
     
    157160                return;
    158161        }
    159         else if( this->owner == thrd) {
     162        else if( this->owner == thrd && !join) {
    160163                // We already have the monitor... but where about to destroy it so the nesting will fail
    161164                // Abort!
    162165                abort( "Attempt to destroy monitor %p by thread \"%.256s\" (%p) in nested mutex.", this, thrd->self_cor.name, thrd );
     166        }
     167        // SKULLDUGGERY: join will act as a dtor so it would normally trigger to above check
     168        // to avoid that it sets the owner to the special value thrd | 1p before exiting
     169        else if( this->owner == ($thread*)(1 | (uintptr_t)thrd) ) {
     170                // restore the owner and just return
     171                __cfaabi_dbg_print_safe( "Kernel : Destroying free mon %p\n", this);
     172
     173                // No one has the monitor, just take it
     174                this->owner = thrd;
     175
     176                verifyf( kernelTLS.this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", kernelTLS.this_thread, this->owner, this->recursion, this );
     177
     178                unlock( this->lock );
     179                return;
    163180        }
    164181
     
    251268
    252269// Leave single monitor for the last time
    253 void __dtor_leave( $monitor * this ) {
     270void __dtor_leave( $monitor * this, bool join ) {
    254271        __cfaabi_dbg_debug_do(
    255272                if( TL_GET( this_thread ) != this->owner ) {
    256273                        abort( "Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, TL_GET( this_thread ), this->owner);
    257274                }
    258                 if( this->recursion != 1 ) {
     275                if( this->recursion != 1  && !join ) {
    259276                        abort( "Destroyed monitor %p has %d outstanding nested calls.\n", this, this->recursion - 1);
    260277                }
    261278        )
     279
     280        this->owner = ($thread*)(1 | (uintptr_t)this->owner);
    262281}
    263282
     
    307326}
    308327
     328// Join a thread
     329forall( dtype T | is_thread(T) )
     330T & join( T & this ) {
     331        $monitor *    m = get_monitor(this);
     332        void (*dtor)(T& mutex this) = ^?{};
     333        monitor_dtor_guard_t __guard = { &m, (fptr_t)dtor, true };
     334        {
     335                return this;
     336        }
     337}
     338
    309339// Enter multiple monitor
    310340// relies on the monitor array being sorted
     
    366396// Ctor for monitor guard
    367397// Sorts monitors before entering
    368 void ?{}( monitor_dtor_guard_t & this, $monitor * m [], fptr_t func ) {
     398void ?{}( monitor_dtor_guard_t & this, $monitor * m [], fptr_t func, bool join ) {
    369399        // optimization
    370400        $thread * thrd = TL_GET( this_thread );
     
    376406        this.prev = thrd->monitors;
    377407
     408        // Save whether we are in a join or not
     409        this.join = join;
     410
    378411        // Update thread context (needed for conditions)
    379412        (thrd->monitors){m, 1, func};
    380413
    381         __dtor_enter( this.m, func );
     414        __dtor_enter( this.m, func, join );
    382415}
    383416
     
    385418void ^?{}( monitor_dtor_guard_t & this ) {
    386419        // Leave the monitors in order
    387         __dtor_leave( this.m );
     420        __dtor_leave( this.m, this.join );
    388421
    389422        // Restore thread context
  • libcfa/src/concurrency/monitor.hfa

    r7a8f62c3 r1def117b  
    5353        $monitor *    m;
    5454        __monitor_group_t prev;
     55        bool join;
    5556};
    5657
    57 void ?{}( monitor_dtor_guard_t & this, $monitor ** m, void (*func)() );
     58void ?{}( monitor_dtor_guard_t & this, $monitor ** m, void (*func)(), bool join );
    5859void ^?{}( monitor_dtor_guard_t & this );
    5960
  • libcfa/src/concurrency/thread.hfa

    r7a8f62c3 r1def117b  
    106106void sleep( Duration duration );
    107107
     108//----------
     109// join
     110forall( dtype T | is_thread(T) )
     111T & join( T & this );
     112
    108113// Local Variables: //
    109114// mode: c //
  • src/Concurrency/Keywords.cc

    r7a8f62c3 r1def117b  
    931931                                        {
    932932                                                new SingleInit( new AddressExpr( new VariableExpr( monitors ) ) ),
    933                                                 new SingleInit( new CastExpr( new VariableExpr( func ), generic_func->clone(), false ) )
     933                                                new SingleInit( new CastExpr( new VariableExpr( func ), generic_func->clone(), false ) ),
     934                                                new SingleInit( new ConstantExpr( Constant::from_bool( false ) ) )
    934935                                        },
    935936                                        noDesignators,
  • tests/Makefile.am

    r7a8f62c3 r1def117b  
    3838# since automake doesn't have support for CFA we have to
    3939AM_CFLAGS = $(if $(test), 2> $(test), ) \
     40        -fdebug-prefix-map=$(abspath ${abs_srcdir})= \
     41        -fdebug-prefix-map=/tmp= \
    4042        -g \
    4143        -Wall \
     
    110112% : %.cfa $(CFACCBIN)
    111113        $(CFACOMPILETEST) -c -o $(abspath ${@}).o
    112         $(CFACCLOCAL) $($(shell echo "${@}_FLAGSLD" | sed 's/-\|\//_/g')) $(abspath ${@}).o -o $(abspath ${@})
     114        $(CFACCLOCAL) $(if $(test), 2> $(test), ) $($(shell echo "${@}_FLAGSLD" | sed 's/-\|\//_/g')) ${@}.o -o $(abspath ${@})
    113115
    114116# implicit rule for c++ test
     
    137139# CUSTOM TARGET
    138140#------------------------------------------------------------------------------
     141# tests that just validate syntax
     142expression : expression.cfa $(CFACCBIN)
     143        $(CFACOMPILETEST) -c -fsyntax-only -o $(abspath ${@})
     144
    139145# expected failures
    140146# use custom target since they require a custom define and custom dependencies
  • tests/pybin/tools.py

    r7a8f62c3 r1def117b  
    120120                return None
    121121
    122         file = open(file, mode)
     122        file = open(file, mode, encoding="latin-1") # use latin-1 so all chars mean something.
    123123        exitstack.push(file)
    124124        return file
  • tests/test.py

    r7a8f62c3 r1def117b  
    207207                else:
    208208                        if os.stat(out_file).st_size < 1048576:
    209                                 with open (out_file, "r") as myfile:
     209                                with open (out_file, "r", encoding='latin-1') as myfile:  # use latin-1 so all chars mean something.
    210210                                        error = myfile.read()
    211211                        else:
Note: See TracChangeset for help on using the changeset viewer.