Changeset 305aaef
- Timestamp:
- Jun 2, 2022, 3:10:40 PM (16 months ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 015925a
- Parents:
- 490d17e0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/locks.cfa
r490d17e0 r305aaef 174 174 recursion_count = recursion; 175 175 } 176 177 //----------------------------------------------------------------------------- 178 // simple_owner_lock 179 180 static inline void lock(simple_owner_lock & this) with(this) { 181 if (owner == active_thread()) { 182 recursion_count++; 183 return; 184 } 185 lock( lock __cfaabi_dbg_ctx2 ); 186 187 if (owner != 0p) { 188 insert_last( blocked_threads, *active_thread() ); 189 unlock( lock ); 190 park( ); 191 return; 192 } 193 owner = active_thread(); 194 recursion_count = 1; 195 unlock( lock ); 196 } 197 198 void pop_and_set_new_owner( simple_owner_lock & this ) with( this ) { 199 thread$ * t = &try_pop_front( blocked_threads ); 200 owner = t; 201 recursion_count = ( t ? 1 : 0 ); 202 unpark( t ); 203 } 204 205 static inline void unlock(simple_owner_lock & this) with(this) { 206 lock( lock __cfaabi_dbg_ctx2 ); 207 /* paranoid */ verifyf( owner != 0p, "Attempt to release lock %p that isn't held", &this ); 208 /* paranoid */ verifyf( owner == active_thread(), "Thread %p other than the owner %p attempted to release owner lock %p", owner, active_thread(), &this ); 209 // if recursion count is zero release lock and set new owner if one is waiting 210 recursion_count--; 211 if ( recursion_count == 0 ) { 212 pop_and_set_new_owner( this ); 213 } 214 unlock( lock ); 215 } 216 217 static inline void on_notify(simple_owner_lock & this, struct thread$ * t ) with(this) { 218 lock( lock __cfaabi_dbg_ctx2 ); 219 // lock held 220 if ( owner != 0p ) { 221 insert_last( blocked_threads, *t ); 222 unlock( lock ); 223 } 224 // lock not held 225 else { 226 owner = t; 227 recursion_count = 1; 228 unpark( t ); 229 unlock( lock ); 230 } 231 } 232 233 static inline size_t on_wait(simple_owner_lock & this) with(this) { 234 lock( lock __cfaabi_dbg_ctx2 ); 235 /* paranoid */ verifyf( owner != 0p, "Attempt to release lock %p that isn't held", &this ); 236 /* paranoid */ verifyf( owner == active_thread(), "Thread %p other than the owner %p attempted to release owner lock %p", owner, active_thread(), &this ); 237 238 size_t ret = recursion_count; 239 240 pop_and_set_new_owner( this ); 241 242 unlock( lock ); 243 return ret; 244 } 245 246 static inline void on_wakeup(simple_owner_lock & this, size_t recursion ) with(this) { recursion_count = recursion; } 247 176 248 177 249 //-----------------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.