Changeset eeb5023 for libcfa/src/concurrency/locks.hfa
- Timestamp:
- Nov 5, 2020, 3:32:05 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- c5bbb9b
- Parents:
- c28ea4e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.hfa
rc28ea4e reeb5023 10 10 #include "time.hfa" 11 11 #include <sys/time.h> 12 #include "alarm.hfa" 12 13 13 14 /////////////////////////////////////////////////////////////////// … … 32 33 info_thread(L) * next; 33 34 L * lock; 35 bool listed; // true if info_thread is on queue, false otherwise; 34 36 }; 35 37 … … 119 121 /////////////////////////////////////////////////////////////////// 120 122 forall(dtype L | is_blocking_lock(L)) { 121 struct synchronization_lock{123 struct condition_variable { 122 124 // Spin lock used for mutual exclusion 123 125 __spinlock_t lock; … … 128 130 // Count of current blocked threads 129 131 int count; 130 131 // If true threads will reacquire the lock they block on upon waking132 bool reacquire_after_signal;133 132 }; 134 135 struct condition_variable {136 inline synchronization_lock(L);137 };138 139 struct thread_queue {140 inline synchronization_lock(L);141 };142 143 144 void ?{}( synchronization_lock(L) & this, bool multi_acquisition, bool strict_owner );145 void ^?{}( synchronization_lock(L) & this );146 133 147 134 void ?{}( condition_variable(L) & this ); 148 135 void ^?{}( condition_variable(L) & this ); 149 136 150 void ?{}( thread_queue(L) & this );151 void ^?{}( thread_queue(L) & this );137 struct alarm_node_wrap { 138 alarm_node_t alarm_node; 152 139 153 bool notify_one( synchronization_lock(L) & this ); 154 bool notify_all( synchronization_lock(L) & this ); 140 condition_variable(L) * cond; 155 141 156 uintptr_t front( synchronization_lock(L) & this ); 157 158 bool empty( synchronization_lock(L) & this ); 159 int counter( synchronization_lock(L) & this ); 160 161 // wait functions that are not passed a mutex lock 162 void wait( synchronization_lock(L) & this ); 163 void wait( synchronization_lock(L) & this, uintptr_t info ); 164 bool wait( synchronization_lock(L) & this, Duration duration ); 165 bool wait( synchronization_lock(L) & this, uintptr_t info, Duration duration ); 166 bool wait( synchronization_lock(L) & this, Time time ); 167 bool wait( synchronization_lock(L) & this, uintptr_t info, Time time ); 168 169 // wait functions that are passed a lock 170 bool notify_one( synchronization_lock(L) & this, L & l ); 171 bool notify_all( synchronization_lock(L) & this, L & l ); 172 173 void wait( synchronization_lock(L) & this, L & l ); 174 void wait( synchronization_lock(L) & this, L & l, uintptr_t info ); 175 bool wait( synchronization_lock(L) & this, L & l, Duration duration ); 176 bool wait( synchronization_lock(L) & this, L & l, uintptr_t info, Duration duration ); 177 bool wait( synchronization_lock(L) & this, L & l, Time time ); 178 bool wait( synchronization_lock(L) & this, L & l, uintptr_t info, Time time ); 179 } 180 181 /////////////////////////////////////////////////////////////////// 182 //// condition lock alternative approach 183 /////////////////////////////////////////////////////////////////// 184 185 186 /////////////////////////////////////////////////////////////////// 187 //// is_simple_lock 188 /////////////////////////////////////////////////////////////////// 189 190 trait is_simple_lock(dtype L | sized(L)) { 191 void lock( L & ); // For synchronization locks to use when acquiring 192 void unlock( L & ); // For synchronization locks to use when releasing 193 size_t get_recursion_count( L & ); // to get recursion count for cond lock to reset after waking 194 void set_recursion_count( L &, size_t recursion ); // to set recursion count after getting signalled; 195 }; 196 197 forall(dtype L | is_simple_lock(L)) { 198 struct condition_lock { 199 // Spin lock used for mutual exclusion 200 mutex_lock m_lock; 201 202 condition_variable( mutex_lock ) c_var; 142 info_thread(L) ** i; 203 143 }; 204 144 205 void ?{}( condition_lock(L) & this);206 void ^?{}( condition_lock(L) & this );145 void ?{}( alarm_node_wrap(L) & this, $thread * thrd, Time alarm, Duration period, Alarm_Callback callback ); 146 void ^?{}( alarm_node_wrap(L) & this ); 207 147 208 bool notify_one( condition_lock(L) & this ); 209 bool notify_all( condition_lock(L) & this ); 210 void wait( condition_lock(L) & this, L & l ); 148 void alarm_node_callback( alarm_node_wrap(L) & this ); 149 150 void alarm_node_wrap_cast( alarm_node_t & a ); 151 152 bool notify_one( condition_variable(L) & this ); 153 bool notify_all( condition_variable(L) & this ); 154 155 uintptr_t front( condition_variable(L) & this ); 156 157 bool empty( condition_variable(L) & this ); 158 int counter( condition_variable(L) & this ); 159 160 // TODO: look into changing timout routines to return bool showing if signalled or woken by kernel 161 void wait( condition_variable(L) & this ); 162 void wait( condition_variable(L) & this, uintptr_t info ); 163 void wait( condition_variable(L) & this, Duration duration ); 164 void wait( condition_variable(L) & this, uintptr_t info, Duration duration ); 165 void wait( condition_variable(L) & this, Time time ); 166 void wait( condition_variable(L) & this, uintptr_t info, Time time ); 167 168 void wait( condition_variable(L) & this, L & l ); 169 void wait( condition_variable(L) & this, L & l, uintptr_t info ); 170 void wait( condition_variable(L) & this, L & l, Duration duration ); 171 void wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration ); 172 void wait( condition_variable(L) & this, L & l, Time time ); 173 void wait( condition_variable(L) & this, L & l, uintptr_t info, Time time ); 211 174 }
Note: See TracChangeset
for help on using the changeset viewer.