Ignore:
File:
1 edited

Legend:

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

    r454f478 r4f449d2  
    224224        }
    225225
    226         post( this->terminated );
     226        V( this->terminated );
    227227
    228228        if(this == mainProcessor) {
     
    624624// Unexpected Terminating logic
    625625//=============================================================================================
    626 void __kernel_abort_msg( char * abort_text, int abort_text_size ) {
    627         $thread * thrd = __cfaabi_tls.this_thread;
     626
     627extern "C" {
     628        extern void __cfaabi_real_abort(void);
     629}
     630static volatile bool kernel_abort_called = false;
     631
     632void * kernel_abort(void) __attribute__ ((__nothrow__)) {
     633        // abort cannot be recursively entered by the same or different processors because all signal handlers return when
     634        // the globalAbort flag is true.
     635        bool first = !__atomic_test_and_set( &kernel_abort_called, __ATOMIC_SEQ_CST);
     636
     637        // first task to abort ?
     638        if ( !first ) {
     639                // We aren't the first to abort.
     640                // I give up, just let C handle it
     641                __cfaabi_real_abort();
     642        }
     643
     644        // disable interrupts, it no longer makes sense to try to interrupt this processor
     645        disable_interrupts();
     646
     647        return __cfaabi_tls.this_thread;
     648}
     649
     650void kernel_abort_msg( void * kernel_data, char * abort_text, int abort_text_size ) {
     651        $thread * thrd = ( $thread * ) kernel_data;
    628652
    629653        if(thrd) {
     
    645669}
    646670
    647 int __kernel_abort_lastframe( void ) __attribute__ ((__nothrow__)) {
    648         return get_coroutine(__cfaabi_tls.this_thread) == get_coroutine(mainThread) ? 4 : 2;
     671int kernel_abort_lastframe( void ) __attribute__ ((__nothrow__)) {
     672        return get_coroutine(kernelTLS().this_thread) == get_coroutine(mainThread) ? 4 : 2;
    649673}
    650674
     
    664688// Kernel Utilities
    665689//=============================================================================================
     690//-----------------------------------------------------------------------------
     691// Locks
     692void  ?{}( semaphore & this, int count = 1 ) {
     693        (this.lock){};
     694        this.count = count;
     695        (this.waiting){};
     696}
     697void ^?{}(semaphore & this) {}
     698
     699bool P(semaphore & this) with( this ){
     700        lock( lock __cfaabi_dbg_ctx2 );
     701        count -= 1;
     702        if ( count < 0 ) {
     703                // queue current task
     704                append( waiting, active_thread() );
     705
     706                // atomically release spin lock and block
     707                unlock( lock );
     708                park();
     709                return true;
     710        }
     711        else {
     712            unlock( lock );
     713            return false;
     714        }
     715}
     716
     717bool V(semaphore & this) with( this ) {
     718        $thread * thrd = 0p;
     719        lock( lock __cfaabi_dbg_ctx2 );
     720        count += 1;
     721        if ( count <= 0 ) {
     722                // remove task at head of waiting list
     723                thrd = pop_head( waiting );
     724        }
     725
     726        unlock( lock );
     727
     728        // make new owner
     729        unpark( thrd );
     730
     731        return thrd != 0p;
     732}
     733
     734bool V(semaphore & this, unsigned diff) with( this ) {
     735        $thread * thrd = 0p;
     736        lock( lock __cfaabi_dbg_ctx2 );
     737        int release = max(-count, (int)diff);
     738        count += diff;
     739        for(release) {
     740                unpark( pop_head( waiting ) );
     741        }
     742
     743        unlock( lock );
     744
     745        return thrd != 0p;
     746}
     747
    666748//-----------------------------------------------------------------------------
    667749// Debug
Note: See TracChangeset for help on using the changeset viewer.