Ignore:
File:
1 edited

Legend:

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

    rac5816d r797a193  
    33#include <stdbool.h>
    44
     5#include "bits/algorithm.hfa"
    56#include "bits/locks.hfa"
    67#include "bits/sequence.hfa"
     
    1011#include "time_t.hfa"
    1112#include "time.hfa"
     13#include <sys/time.h>
     14#include "alarm.hfa"
    1215
    13 //-----------------------------------------------------------------------------
    14 // is_blocking_lock
     16///////////////////////////////////////////////////////////////////
     17//// is_blocking_lock
     18///////////////////////////////////////////////////////////////////
     19
    1520trait is_blocking_lock(dtype L | sized(L)) {
    16         // For synchronization locks to use when acquiring
    17         void on_notify( L &, struct $thread * );
    18 
    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 );
     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;
    2725};
    2826
    29 //-----------------------------------------------------------------------------
    30 // info_thread
     27///////////////////////////////////////////////////////////////////
     28//// info_thread
     29///////////////////////////////////////////////////////////////////
     30
    3131// the info thread is a wrapper around a thread used
    3232// to store extra data for use in the condition variable
    3333forall(dtype L | is_blocking_lock(L)) {
    34         struct info_thread;
     34        struct info_thread {
     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)
     39                bool signalled;                                 // true when signalled and false when timeout wakes thread
     40        };
     41
     42
     43        void ?{}( info_thread(L) & this, $thread * t );
     44        void ?{}( info_thread(L) & this, $thread * t, uintptr_t info );
     45        void ^?{}( info_thread(L) & this );
    3546
    3647        // for use by sequence
     
    3950}
    4051
    41 //-----------------------------------------------------------------------------
    42 // Blocking Locks
     52///////////////////////////////////////////////////////////////////
     53//// Blocking Locks
     54///////////////////////////////////////////////////////////////////
     55
    4356struct blocking_lock {
    4457        // Spin lock used for mutual exclusion
     
    7689};
    7790
    78 void  ?{}( blocking_lock & this, bool multi_acquisition, bool strict_owner );
     91void ?{}( blocking_lock & this, bool multi_acquisition, bool strict_owner );
    7992void ^?{}( blocking_lock & this );
    8093
    81 void  ?{}( single_acquisition_lock & this );
     94void ?{}( single_acquisition_lock & this );
    8295void ^?{}( single_acquisition_lock & this );
    8396
    84 void  ?{}( owner_lock & this );
     97void ?{}( owner_lock & this );
    8598void ^?{}( owner_lock & this );
    8699
    87 void  ?{}( multiple_acquisition_lock & this );
     100void ?{}( multiple_acquisition_lock & this );
    88101void ^?{}( multiple_acquisition_lock & this );
    89102
     
    118131size_t get_recursion_count( multiple_acquisition_lock & this );
    119132
    120 //-----------------------------------------------------------------------------
    121 // Synchronization Locks
     133///////////////////////////////////////////////////////////////////
     134//// Synchronization Locks
     135///////////////////////////////////////////////////////////////////
    122136forall(dtype L | is_blocking_lock(L)) {
    123137        struct condition_variable {
     
    132146        };
    133147
    134         void  ?{}( condition_variable(L) & this );
     148        void ?{}( condition_variable(L) & this );
    135149        void ^?{}( condition_variable(L) & this );
     150
     151        struct alarm_node_wrap {
     152                alarm_node_t alarm_node;
     153
     154                condition_variable(L) * cond;
     155
     156                info_thread(L) * i;
     157        };
     158
     159        void ?{}( alarm_node_wrap(L) & this, Time alarm, Duration period, Alarm_Callback callback );
     160        void ^?{}( alarm_node_wrap(L) & this );
     161
     162        void alarm_node_callback( alarm_node_wrap(L) & this );
     163
     164        void alarm_node_wrap_cast( alarm_node_t & a );
    136165
    137166        bool notify_one( condition_variable(L) & this );
     
    140169        uintptr_t front( condition_variable(L) & this );
    141170
    142         bool empty  ( condition_variable(L) & this );
    143         int  counter( condition_variable(L) & this );
     171        bool empty( condition_variable(L) & this );
     172        int counter( condition_variable(L) & this );
    144173
    145174        void wait( condition_variable(L) & this );
Note: See TracChangeset for help on using the changeset viewer.