Ignore:
File:
1 edited

Legend:

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

    r4aeaee5 rac5816d  
    33#include <stdbool.h>
    44
    5 #include "bits/algorithm.hfa"
    65#include "bits/locks.hfa"
    76#include "bits/sequence.hfa"
    8 #include "bits/containers.hfa"
    97
    108#include "invoke.h"
     
    1210#include "time_t.hfa"
    1311#include "time.hfa"
    14 #include <sys/time.h>
    15 #include "alarm.hfa"
    1612
    17 ///////////////////////////////////////////////////////////////////
    18 //// is_blocking_lock
    19 ///////////////////////////////////////////////////////////////////
     13//-----------------------------------------------------------------------------
     14// is_blocking_lock
     15trait is_blocking_lock(dtype L | sized(L)) {
     16        // For synchronization locks to use when acquiring
     17        void on_notify( L &, struct $thread * );
    2018
    21 trait 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;
     19        // For synchronization locks to use when releasing
     20        void on_wait( L & );
     21
     22        // to get recursion count for cond lock to reset after waking
     23        size_t get_recursion_count( L & );
     24
     25        // to set recursion count after getting signalled;
     26        void set_recursion_count( L &, size_t recursion );
    2627};
    2728
    28 ///////////////////////////////////////////////////////////////////
    29 //// info_thread
    30 ///////////////////////////////////////////////////////////////////
     29//-----------------------------------------------------------------------------
     30// info_thread
     31// the info thread is a wrapper around a thread used
     32// to store extra data for use in the condition variable
     33forall(dtype L | is_blocking_lock(L)) {
     34        struct info_thread;
    3135
    32 forall(dtype L | is_blocking_lock(L)) {
    33         struct info_thread {
    34                 inline Seqable;
    35                 struct $thread * t;
    36                 uintptr_t info;
    37                 L * lock;
    38                 bool listed;                                    // true if info_thread is on queue, false otherwise;
    39         };
    40 
    41 
    42         void ?{}( info_thread(L) & this, $thread * t );
    43         void ?{}( info_thread(L) & this, $thread * t, uintptr_t info );
    44         void ^?{}( info_thread(L) & this );
     36        // for use by sequence
     37        info_thread(L) *& Back( info_thread(L) * this );
     38        info_thread(L) *& Next( info_thread(L) * this );
    4539}
    4640
    47 ///////////////////////////////////////////////////////////////////
    48 //// Blocking Locks
    49 ///////////////////////////////////////////////////////////////////
    50 
    51 // struct lock_thread {
    52 //      struct $thread * t;
    53 //      lock_thread * next;
    54 // };
    55 
    56 // void ?{}( lock_thread & this, struct $thread * thd );
    57 // void ^?{}( lock_thread & this );
    58 
    59 // lock_thread *& get_next( lock_thread & );
    60 
     41//-----------------------------------------------------------------------------
     42// Blocking Locks
    6143struct blocking_lock {
    6244        // Spin lock used for mutual exclusion
     
    6446
    6547        // List of blocked threads
    66         __queue_t( $thread ) blocked_threads;
     48        Sequence( $thread ) blocked_threads;
    6749
    6850        // Count of current blocked threads
     
    9476};
    9577
    96 void ?{}( blocking_lock & this, bool multi_acquisition, bool strict_owner );
     78void  ?{}( blocking_lock & this, bool multi_acquisition, bool strict_owner );
    9779void ^?{}( blocking_lock & this );
    9880
    99 void ?{}( single_acquisition_lock & this );
     81void  ?{}( single_acquisition_lock & this );
    10082void ^?{}( single_acquisition_lock & this );
    10183
    102 void ?{}( owner_lock & this );
     84void  ?{}( owner_lock & this );
    10385void ^?{}( owner_lock & this );
    10486
    105 void ?{}( multiple_acquisition_lock & this );
     87void  ?{}( multiple_acquisition_lock & this );
    10688void ^?{}( multiple_acquisition_lock & this );
    10789
     
    10991bool try_lock( blocking_lock & this );
    11092void unlock( blocking_lock & this );
    111 void add_( blocking_lock & this, struct $thread * t );
    112 void remove_( blocking_lock & this );
     93void on_notify( blocking_lock & this, struct $thread * t );
     94void on_wait( blocking_lock & this );
    11395size_t wait_count( blocking_lock & this );
    11496void set_recursion_count( blocking_lock & this, size_t recursion );
     
    11799void lock( single_acquisition_lock & this );
    118100void unlock( single_acquisition_lock & this );
    119 void add_( single_acquisition_lock & this, struct $thread * t );
    120 void remove_( single_acquisition_lock & this );
     101void on_notify( single_acquisition_lock & this, struct $thread * t );
     102void on_wait( single_acquisition_lock & this );
    121103void set_recursion_count( single_acquisition_lock & this, size_t recursion );
    122104size_t get_recursion_count( single_acquisition_lock & this );
     
    124106void lock( owner_lock & this );
    125107void unlock( owner_lock & this );
    126 void add_( owner_lock & this, struct $thread * t );
    127 void remove_( owner_lock & this );
     108void on_notify( owner_lock & this, struct $thread * t );
     109void on_wait( owner_lock & this );
    128110void set_recursion_count( owner_lock & this, size_t recursion );
    129111size_t get_recursion_count( owner_lock & this );
     
    131113void lock( multiple_acquisition_lock & this );
    132114void unlock( multiple_acquisition_lock & this );
    133 void add_( multiple_acquisition_lock & this, struct $thread * t );
    134 void remove_( multiple_acquisition_lock & this );
     115void on_notify( multiple_acquisition_lock & this, struct $thread * t );
     116void on_wait( multiple_acquisition_lock & this );
    135117void set_recursion_count( multiple_acquisition_lock & this, size_t recursion );
    136118size_t get_recursion_count( multiple_acquisition_lock & this );
    137119
    138 ///////////////////////////////////////////////////////////////////
    139 //// Synchronization Locks
    140 ///////////////////////////////////////////////////////////////////
     120//-----------------------------------------------------------------------------
     121// Synchronization Locks
    141122forall(dtype L | is_blocking_lock(L)) {
    142123        struct condition_variable {
    143124                // Spin lock used for mutual exclusion
    144125                __spinlock_t lock;
    145 
    146                 info_thread(L) * last_thread;
    147126
    148127                // List of blocked threads
     
    153132        };
    154133
    155         void ?{}( condition_variable(L) & this );
     134        void  ?{}( condition_variable(L) & this );
    156135        void ^?{}( condition_variable(L) & this );
    157 
    158         struct alarm_node_wrap {
    159                 alarm_node_t alarm_node;
    160 
    161                 condition_variable(L) * cond;
    162 
    163                 info_thread(L) * i;
    164         };
    165 
    166         void ?{}( alarm_node_wrap(L) & this, Time alarm, Duration period, Alarm_Callback callback );
    167         void ^?{}( alarm_node_wrap(L) & this );
    168 
    169         void alarm_node_callback( alarm_node_wrap(L) & this );
    170 
    171         void alarm_node_wrap_cast( alarm_node_t & a );
    172136
    173137        bool notify_one( condition_variable(L) & this );
     
    176140        uintptr_t front( condition_variable(L) & this );
    177141
    178         bool empty( condition_variable(L) & this );
    179         int counter( condition_variable(L) & this );
     142        bool empty  ( condition_variable(L) & this );
     143        int  counter( condition_variable(L) & this );
    180144
    181         // TODO: look into changing timout routines to return bool showing if signalled or woken by kernel
    182145        void wait( condition_variable(L) & this );
    183146        void wait( condition_variable(L) & this, uintptr_t info );
    184         void wait( condition_variable(L) & this, Duration duration );
    185         void wait( condition_variable(L) & this, uintptr_t info, Duration duration );
    186         void wait( condition_variable(L) & this, Time time );
    187         void wait( condition_variable(L) & this, uintptr_t info, Time time );
     147        bool wait( condition_variable(L) & this, Duration duration );
     148        bool wait( condition_variable(L) & this, uintptr_t info, Duration duration );
     149        bool wait( condition_variable(L) & this, Time time );
     150        bool wait( condition_variable(L) & this, uintptr_t info, Time time );
    188151
    189152        void wait( condition_variable(L) & this, L & l );
    190153        void wait( condition_variable(L) & this, L & l, uintptr_t info );
    191         void wait( condition_variable(L) & this, L & l, Duration duration );
    192         void wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration );
    193         void wait( condition_variable(L) & this, L & l, Time time );
    194         void wait( condition_variable(L) & this, L & l, uintptr_t info, Time time );
     154        bool wait( condition_variable(L) & this, L & l, Duration duration );
     155        bool wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration );
     156        bool wait( condition_variable(L) & this, L & l, Time time );
     157        bool wait( condition_variable(L) & this, L & l, uintptr_t info, Time time );
    195158}
Note: See TracChangeset for help on using the changeset viewer.