Ignore:
Timestamp:
May 20, 2022, 10:36:45 AM (3 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
25fa20a
Parents:
29d8c02 (diff), 7831e8fb (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

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

    r29d8c02 r74ec742  
    2424#include <stdlib.hfa>
    2525
     26#pragma GCC visibility push(default)
     27
    2628//-----------------------------------------------------------------------------
    2729// info_thread
     
    116118}
    117119
    118 void pop_and_set_new_owner( blocking_lock & this ) with( this ) {
     120static void pop_and_set_new_owner( blocking_lock & this ) with( this ) {
    119121        thread$ * t = &try_pop_front( blocked_threads );
    120122        owner = t;
     
    192194        void ^?{}( alarm_node_wrap(L) & this ) { }
    193195
    194         void timeout_handler ( alarm_node_wrap(L) & this ) with( this ) {
     196        static void timeout_handler ( alarm_node_wrap(L) & this ) with( this ) {
    195197                // This condition_variable member is called from the kernel, and therefore, cannot block, but it can spin.
    196198                lock( cond->lock __cfaabi_dbg_ctx2 );
     
    216218
    217219        // this casts the alarm node to our wrapped type since we used type erasure
    218         void alarm_node_wrap_cast( alarm_node_t & a ) { timeout_handler( (alarm_node_wrap(L) &)a ); }
     220        static void alarm_node_wrap_cast( alarm_node_t & a ) { timeout_handler( (alarm_node_wrap(L) &)a ); }
    219221}
    220222
    221223//-----------------------------------------------------------------------------
    222 // condition variable
     224// Synchronization Locks
    223225forall(L & | is_blocking_lock(L)) {
    224226
     227        //-----------------------------------------------------------------------------
     228        // condition variable
    225229        void ?{}( condition_variable(L) & this ){
    226230                this.lock{};
     
    231235        void ^?{}( condition_variable(L) & this ){ }
    232236
    233         void process_popped( condition_variable(L) & this, info_thread(L) & popped ) with( this ) {
     237        static void process_popped( condition_variable(L) & this, info_thread(L) & popped ) with( this ) {
    234238                if(&popped != 0p) {
    235239                        popped.signalled = true;
     
    276280        int counter( condition_variable(L) & this ) with(this) { return count; }
    277281
    278         size_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) {
     282        static size_t queue_and_get_recursion( condition_variable(L) & this, info_thread(L) * i ) with(this) {
    279283                // add info_thread to waiting queue
    280284                insert_last( blocked_threads, *i );
     
    289293
    290294        // helper for wait()'s' with no timeout
    291         void queue_info_thread( condition_variable(L) & this, info_thread(L) & i ) with(this) {
     295        static void queue_info_thread( condition_variable(L) & this, info_thread(L) & i ) with(this) {
    292296                lock( lock __cfaabi_dbg_ctx2 );
    293297                size_t recursion_count = queue_and_get_recursion(this, &i);
     
    306310
    307311        // helper for wait()'s' with a timeout
    308         void queue_info_thread_timeout( condition_variable(L) & this, info_thread(L) & info, Duration t, Alarm_Callback callback ) with(this) {
     312        static void queue_info_thread_timeout( condition_variable(L) & this, info_thread(L) & info, Duration t, Alarm_Callback callback ) with(this) {
    309313                lock( lock __cfaabi_dbg_ctx2 );
    310314                size_t recursion_count = queue_and_get_recursion(this, &info);
     
    337341        bool wait( condition_variable(L) & this, L & l, Duration duration                 ) with(this) { WAIT_TIME( 0   , &l , duration ) }
    338342        bool wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration ) with(this) { WAIT_TIME( info, &l , duration ) }
     343
     344        //-----------------------------------------------------------------------------
     345        // fast_cond_var
     346        void  ?{}( fast_cond_var(L) & this ){
     347                this.blocked_threads{};
     348                #ifdef __CFA_DEBUG__
     349                this.lock_used = 0p;
     350                #endif
     351        }
     352        void ^?{}( fast_cond_var(L) & this ){ }
     353
     354        bool notify_one( fast_cond_var(L) & this ) with(this) {
     355                bool ret = ! blocked_threads`isEmpty;
     356                if ( ret ) {
     357                        info_thread(L) & popped = try_pop_front( blocked_threads );
     358                        on_notify(*popped.lock, popped.t);
     359                }
     360                return ret;
     361        }
     362        bool notify_all( fast_cond_var(L) & this ) with(this) {
     363                bool ret = ! blocked_threads`isEmpty;
     364                while( ! blocked_threads`isEmpty ) {
     365                        info_thread(L) & popped = try_pop_front( blocked_threads );
     366                        on_notify(*popped.lock, popped.t);
     367                }
     368                return ret;
     369        }
     370
     371        uintptr_t front( fast_cond_var(L) & this ) with(this) { return blocked_threads`isEmpty ? NULL : blocked_threads`first.info; }
     372        bool empty ( fast_cond_var(L) & this ) with(this) { return blocked_threads`isEmpty; }
     373
     374        void wait( fast_cond_var(L) & this, L & l ) {
     375                wait( this, l, 0 );
     376        }
     377
     378        void wait( fast_cond_var(L) & this, L & l, uintptr_t info ) with(this) {
     379                // brand cond lock with lock
     380                #ifdef __CFA_DEBUG__
     381                        if ( lock_used == 0p ) lock_used = &l;
     382                        else { assert(lock_used == &l); }
     383                #endif
     384                info_thread( L ) i = { active_thread(), info, &l };
     385                insert_last( blocked_threads, i );
     386                size_t recursion_count = on_wait( *i.lock );
     387                park( );
     388                on_wakeup(*i.lock, recursion_count);
     389        }
    339390}
    340391
Note: See TracChangeset for help on using the changeset viewer.