Changes in libcfa/src/bits/locks.hfa [b353a49:e0f93e0]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/locks.hfa
rb353a49 re0f93e0 130 130 pthread_mutex_init(&lock, &mattr); 131 131 132 pthread_cond_init (&cond, (const pthread_condattr_t *)0p); // workaround trac#208: cast should not be required132 pthread_cond_init (&cond, 0p); 133 133 val = 0; 134 134 } … … 219 219 } 220 220 } 221 222 // Semaphore which only supports a single thread and one post223 // Semaphore which only supports a single thread224 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 }255 221 #endif
Note:
See TracChangeset
for help on using the changeset viewer.