- Timestamp:
- Aug 14, 2020, 12:31:56 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 4998155
- Parents:
- fa5e0112
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/locks.hfa
rfa5e0112 rb353a49 219 219 } 220 220 } 221 222 // Semaphore which only supports a single thread and one post 223 // Semaphore which only supports a single thread 224 struct oneshot { 225 struct $thread * volatile ptr; 226 }; 227 228 static inline { 229 void ?{}(oneshot & this) { 230 this.ptr = 0p; 231 } 232 233 void ^?{}(oneshot & this) {} 234 235 bool wait(oneshot & this) { 236 for() { 237 struct $thread * expected = this.ptr; 238 if(expected == 1p) return false; 239 /* paranoid */ verify( expected == 0p ); 240 if(__atomic_compare_exchange_n(&this.ptr, &expected, active_thread(), false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) { 241 park( __cfaabi_dbg_ctx ); 242 /* paranoid */ verify( this.ptr == 1p ); 243 return true; 244 } 245 } 246 } 247 248 bool post(oneshot & this) { 249 struct $thread * got = __atomic_exchange_n( &this.ptr, 1p, __ATOMIC_SEQ_CST); 250 if( got == 0p ) return false; 251 unpark( got __cfaabi_dbg_ctx2 ); 252 return true; 253 } 254 } 221 255 #endif
Note: See TracChangeset
for help on using the changeset viewer.