- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.hfa
rac5816d r797a193 3 3 #include <stdbool.h> 4 4 5 #include "bits/algorithm.hfa" 5 6 #include "bits/locks.hfa" 6 7 #include "bits/sequence.hfa" … … 10 11 #include "time_t.hfa" 11 12 #include "time.hfa" 13 #include <sys/time.h> 14 #include "alarm.hfa" 12 15 13 //----------------------------------------------------------------------------- 14 // is_blocking_lock 16 /////////////////////////////////////////////////////////////////// 17 //// is_blocking_lock 18 /////////////////////////////////////////////////////////////////// 19 15 20 trait 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; 27 25 }; 28 26 29 //----------------------------------------------------------------------------- 30 // info_thread 27 /////////////////////////////////////////////////////////////////// 28 //// info_thread 29 /////////////////////////////////////////////////////////////////// 30 31 31 // the info thread is a wrapper around a thread used 32 32 // to store extra data for use in the condition variable 33 33 forall(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 ); 35 46 36 47 // for use by sequence … … 39 50 } 40 51 41 //----------------------------------------------------------------------------- 42 // Blocking Locks 52 /////////////////////////////////////////////////////////////////// 53 //// Blocking Locks 54 /////////////////////////////////////////////////////////////////// 55 43 56 struct blocking_lock { 44 57 // Spin lock used for mutual exclusion … … 76 89 }; 77 90 78 void 91 void ?{}( blocking_lock & this, bool multi_acquisition, bool strict_owner ); 79 92 void ^?{}( blocking_lock & this ); 80 93 81 void 94 void ?{}( single_acquisition_lock & this ); 82 95 void ^?{}( single_acquisition_lock & this ); 83 96 84 void 97 void ?{}( owner_lock & this ); 85 98 void ^?{}( owner_lock & this ); 86 99 87 void 100 void ?{}( multiple_acquisition_lock & this ); 88 101 void ^?{}( multiple_acquisition_lock & this ); 89 102 … … 118 131 size_t get_recursion_count( multiple_acquisition_lock & this ); 119 132 120 //----------------------------------------------------------------------------- 121 // Synchronization Locks 133 /////////////////////////////////////////////////////////////////// 134 //// Synchronization Locks 135 /////////////////////////////////////////////////////////////////// 122 136 forall(dtype L | is_blocking_lock(L)) { 123 137 struct condition_variable { … … 132 146 }; 133 147 134 void 148 void ?{}( condition_variable(L) & this ); 135 149 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 ); 136 165 137 166 bool notify_one( condition_variable(L) & this ); … … 140 169 uintptr_t front( condition_variable(L) & this ); 141 170 142 bool empty 143 int 171 bool empty( condition_variable(L) & this ); 172 int counter( condition_variable(L) & this ); 144 173 145 174 void wait( condition_variable(L) & this );
Note: See TracChangeset
for help on using the changeset viewer.