Changeset 2e9aed4


Ignore:
Timestamp:
Jan 30, 2018, 2:04:27 PM (6 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:
ffd0ac2
Parents:
813ddcaa
Message:

Fixed non-preemptive locks

Location:
src/libcfa
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/bits/locks.h

    r813ddcaa r2e9aed4  
    6565        extern void yield( unsigned int );
    6666        extern thread_local struct thread_desc *    volatile this_thread;
     67        extern thread_local struct processor *      volatile this_processor;
    6768
    6869        static inline void ?{}( __spinlock_t & this ) {
     
    112113        }
    113114
    114         // Lock the spinlock, spin if already acquired
    115         static inline void lock_yield( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) {
    116                 for ( unsigned int i = 1;; i += 1 ) {
    117                         if ( __lock_test_and_test_and_set( this.lock ) ) break;
    118                         yield( i );
    119                 }
    120                 disable_interrupts();
    121                 __cfaabi_dbg_debug_do(
    122                         this.prev_name = caller;
    123                         this.prev_thrd = this_thread;
    124                 )
    125         }
     115        // // Lock the spinlock, yield if already acquired
     116        // static inline void lock_yield( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) {
     117        //      for ( unsigned int i = 1;; i += 1 ) {
     118        //              if ( __lock_test_and_test_and_set( this.lock ) ) break;
     119        //              yield( i );
     120        //      }
     121        //      disable_interrupts();
     122        //      __cfaabi_dbg_debug_do(
     123        //              this.prev_name = caller;
     124        //              this.prev_thrd = this_thread;
     125        //      )
     126        // }
    126127
    127128        static inline void unlock( __spinlock_t & this ) {
     129                enable_interrupts_noPoll();
    128130                __lock_release( this.lock );
    129                 enable_interrupts_noPoll();
    130131        }
    131132#endif
  • src/libcfa/concurrency/kernel.c

    r813ddcaa r2e9aed4  
    242242void finishRunning(processor * this) {
    243243        if( this->finish.action_code == Release ) {
     244                verify( disable_preempt_count > 1 );
    244245                unlock( *this->finish.lock );
    245246        }
     
    248249        }
    249250        else if( this->finish.action_code == Release_Schedule ) {
     251                verify( disable_preempt_count > 1 );
    250252                unlock( *this->finish.lock );
    251253                ScheduleThread( this->finish.thrd );
    252254        }
    253255        else if( this->finish.action_code == Release_Multi ) {
     256                verify( disable_preempt_count > this->finish.lock_count );
    254257                for(int i = 0; i < this->finish.lock_count; i++) {
    255258                        unlock( *this->finish.locks[i] );
     
    257260        }
    258261        else if( this->finish.action_code == Release_Multi_Schedule ) {
     262                verify( disable_preempt_count > this->finish.lock_count );
    259263                for(int i = 0; i < this->finish.lock_count; i++) {
    260264                        unlock( *this->finish.locks[i] );
     
    363367        this_processor->finish.lock = lock;
    364368
    365         verify( disable_preempt_count > 0 );
     369        verify( disable_preempt_count > 1 );
    366370        suspend();
    367371        verify( disable_preempt_count > 0 );
     
    391395        this_processor->finish.thrd = thrd;
    392396
    393         verify( disable_preempt_count > 0 );
     397        verify( disable_preempt_count > 1 );
    394398        suspend();
    395399        verify( disable_preempt_count > 0 );
  • src/libcfa/concurrency/monitor.c

    r813ddcaa r2e9aed4  
    5353static inline __lock_size_t aggregate    ( monitor_desc * storage [], const __waitfor_mask_t & mask );
    5454
    55 #ifndef __CFA_LOCK_NO_YIELD
    56 #define DO_LOCK lock_yield
    57 #else
    58 #define DO_LOCK lock
    59 #endif
    60 
    6155//-----------------------------------------------------------------------------
    6256// Useful defines
     
    9084        static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) {
    9185                // Lock the monitor spinlock
    92                 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
     86                lock( this->lock __cfaabi_dbg_ctx2 );
    9387                thread_desc * thrd = this_thread;
     88
     89                verify( disable_preempt_count > 0 );
    9490
    9591                __cfaabi_dbg_print_safe("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
     
    121117                        // Some one else has the monitor, wait in line for it
    122118                        append( this->entry_queue, thrd );
     119
     120                        verify( disable_preempt_count > 0 );
     121
    123122                        BlockInternal( &this->lock );
    124123
     
    138137        static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) {
    139138                // Lock the monitor spinlock
    140                 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
     139                lock( this->lock __cfaabi_dbg_ctx2 );
    141140                thread_desc * thrd = this_thread;
    142141
     
    201200        // Leave single monitor
    202201        void __leave_monitor_desc( monitor_desc * this ) {
    203                 // Lock the monitor spinlock, DO_LOCK to reduce contention
    204                 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
     202                // Lock the monitor spinlock
     203                lock( this->lock __cfaabi_dbg_ctx2 );
    205204
    206205                __cfaabi_dbg_print_safe("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);
     
    248247
    249248                // Lock the monitor now
    250                 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
     249                lock( this->lock __cfaabi_dbg_ctx2 );
    251250
    252251                disable_interrupts();
     
    397396        append( this.blocked, &waiter );
    398397
     398        verify( disable_preempt_count == 0 );
     399
    399400        // Lock all monitors (aggregates the locks as well)
    400401        lock_all( monitors, locks, count );
     402
     403        // verifyf( disable_preempt_count == count, "Got %d, expected %d\n", disable_preempt_count, count );
     404        if(disable_preempt_count != count) { __cfaabi_dbg_print_buffer_decl("----------Gonna crash\n"); }
    401405
    402406        // Find the next thread(s) to run
     
    473477        monitor_ctx( this.monitors, this.monitor_count );
    474478
     479        verify( disable_preempt_count == 0 );
     480
    475481        // Lock all monitors (aggregates the locks them as well)
    476482        lock_all( monitors, locks, count );
     483
     484        // verify( disable_preempt_count == count );
     485        if(disable_preempt_count != count) { __cfaabi_dbg_print_buffer_decl("----------Gonna crash\n"); }
     486
    477487
    478488        // Create the node specific to this wait operation
     
    737747static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) {
    738748        for( __lock_size_t i = 0; i < count; i++ ) {
    739                 DO_LOCK( *locks[i] __cfaabi_dbg_ctx2 );
     749                lock( *locks[i] __cfaabi_dbg_ctx2 );
    740750        }
    741751}
     
    744754        for( __lock_size_t i = 0; i < count; i++ ) {
    745755                __spinlock_t * l = &source[i]->lock;
    746                 DO_LOCK( *l __cfaabi_dbg_ctx2 );
     756                lock( *l __cfaabi_dbg_ctx2 );
    747757                if(locks) locks[i] = l;
    748758        }
  • src/libcfa/concurrency/preemption.c

    r813ddcaa r2e9aed4  
    169169        void enable_interrupts_noPoll() {
    170170                __attribute__((unused)) unsigned short prev = __atomic_fetch_add_2( &disable_preempt_count, -1, __ATOMIC_SEQ_CST );
    171                 verify( prev != 0u );                     // If this triggers someone is enabled already enabled interrupts
     171                verifyf( prev != 0u, "Incremented from %u\n", prev );                     // If this triggers someone is enabled already enabled interrupts
    172172        }
    173173}
     
    293293        if( !preemption_ready() ) { return; }
    294294
    295         // __cfaabi_dbg_print_buffer_decl(" KERNEL: preempting core %p (%p).\n", this_processor, this_thread);
     295        __cfaabi_dbg_print_buffer_decl(" KERNEL: preempting core %p (%p).\n", this_processor, this_thread);
    296296
    297297        preemption_in_progress = true;                      // Sync flag : prevent recursive calls to the signal handler
Note: See TracChangeset for help on using the changeset viewer.