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