Ignore:
Timestamp:
Dec 22, 2020, 12:50:46 PM (2 years ago)
Author:
caparsons <caparson@…>
Branches:
arm-eh, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
26a249c, 302ef2a
Parents:
fe97de26
Message:

cleaned up locks code and added comments

File:
1 edited

Legend:

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

    rfe97de26 r797a193  
    66#include "bits/locks.hfa"
    77#include "bits/sequence.hfa"
    8 #include "bits/containers.hfa"
    98
    109#include "invoke.h"
     
    2019
    2120trait is_blocking_lock(dtype L | sized(L)) {
    22         void add_( L &, struct $thread * );             // For synchronization locks to use when acquiring
    23         void remove_( L & );    // For synchronization locks to use when releasing
    24         size_t get_recursion_count( L & ); // to get recursion count for cond lock to reset after waking
    25         void set_recursion_count( L &, size_t recursion ); // to set recursion count after getting signalled;
     21        void on_notify( L &, struct $thread * );                        // For synchronization locks to use when acquiring
     22        void on_wait( L & );                                                            // For synchronization locks to use when releasing
     23        size_t get_recursion_count( L & );                                      // to get recursion count for cond lock to reset after waking
     24        void set_recursion_count( L &, size_t recursion );      // to set recursion count after getting signalled;
    2625};
    2726
     
    3029///////////////////////////////////////////////////////////////////
    3130
     31// the info thread is a wrapper around a thread used
     32// to store extra data for use in the condition variable
    3233forall(dtype L | is_blocking_lock(L)) {
    3334        struct info_thread {
    34                 inline Seqable;
    35                 struct $thread * t;
    36                 uintptr_t info;
    37                 L * lock;
     35                inline Seqable;                                 // used to put info_thread on a dl queue (aka sequence)
     36                struct $thread * t;                             // waiting thread
     37                uintptr_t info;                                 // shadow field
     38                L * lock;                                               // lock that is passed to wait() (if one is passed)
    3839                bool signalled;                                 // true when signalled and false when timeout wakes thread
    3940        };
     
    4445        void ^?{}( info_thread(L) & this );
    4546
     47        // for use by sequence
    4648        info_thread(L) *& Back( info_thread(L) * this );
    4749        info_thread(L) *& Next( info_thread(L) * this );
     
    102104bool try_lock( blocking_lock & this );
    103105void unlock( blocking_lock & this );
    104 void add_( blocking_lock & this, struct $thread * t );
    105 void remove_( blocking_lock & this );
     106void on_notify( blocking_lock & this, struct $thread * t );
     107void on_wait( blocking_lock & this );
    106108size_t wait_count( blocking_lock & this );
    107109void set_recursion_count( blocking_lock & this, size_t recursion );
     
    110112void lock( single_acquisition_lock & this );
    111113void unlock( single_acquisition_lock & this );
    112 void add_( single_acquisition_lock & this, struct $thread * t );
    113 void remove_( single_acquisition_lock & this );
     114void on_notify( single_acquisition_lock & this, struct $thread * t );
     115void on_wait( single_acquisition_lock & this );
    114116void set_recursion_count( single_acquisition_lock & this, size_t recursion );
    115117size_t get_recursion_count( single_acquisition_lock & this );
     
    117119void lock( owner_lock & this );
    118120void unlock( owner_lock & this );
    119 void add_( owner_lock & this, struct $thread * t );
    120 void remove_( owner_lock & this );
     121void on_notify( owner_lock & this, struct $thread * t );
     122void on_wait( owner_lock & this );
    121123void set_recursion_count( owner_lock & this, size_t recursion );
    122124size_t get_recursion_count( owner_lock & this );
     
    124126void lock( multiple_acquisition_lock & this );
    125127void unlock( multiple_acquisition_lock & this );
    126 void add_( multiple_acquisition_lock & this, struct $thread * t );
    127 void remove_( multiple_acquisition_lock & this );
     128void on_notify( multiple_acquisition_lock & this, struct $thread * t );
     129void on_wait( multiple_acquisition_lock & this );
    128130void set_recursion_count( multiple_acquisition_lock & this, size_t recursion );
    129131size_t get_recursion_count( multiple_acquisition_lock & this );
     
    136138                // Spin lock used for mutual exclusion
    137139                __spinlock_t lock;
    138 
    139                 info_thread(L) * last_thread;
    140140
    141141                // List of blocked threads
Note: See TracChangeset for help on using the changeset viewer.