Changes in src/libcfa/bits/locks.h [85b1deb:13073be]
- File:
-
- 1 edited
-
src/libcfa/bits/locks.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/bits/locks.h
r85b1deb r13073be 18 18 #include "bits/debug.h" 19 19 #include "bits/defs.h" 20 #include <assert.h>21 22 #ifdef __cforall23 extern "C" {24 #include <pthread.h>25 }26 #endif27 20 28 21 // pause to prevent excess processor bus usage … … 119 112 __atomic_clear( &this.lock, __ATOMIC_RELEASE ); 120 113 } 121 122 123 #ifdef __CFA_WITH_VERIFY__124 extern bool __cfaabi_dbg_in_kernel();125 #endif126 127 struct __bin_sem_t {128 bool signaled;129 pthread_mutex_t lock;130 pthread_cond_t cond;131 };132 133 static inline void ?{}(__bin_sem_t & this) with( this ) {134 signaled = false;135 pthread_mutex_init(&lock, NULL);136 pthread_cond_init (&cond, NULL);137 }138 139 static inline void ^?{}(__bin_sem_t & this) with( this ) {140 pthread_mutex_destroy(&lock);141 pthread_cond_destroy (&cond);142 }143 144 static inline void wait(__bin_sem_t & this) with( this ) {145 verify(__cfaabi_dbg_in_kernel());146 pthread_mutex_lock(&lock);147 if(!signaled) { // this must be a loop, not if!148 pthread_cond_wait(&cond, &lock);149 }150 signaled = false;151 pthread_mutex_unlock(&lock);152 }153 154 static inline void post(__bin_sem_t & this) with( this ) {155 verify(__cfaabi_dbg_in_kernel());156 157 pthread_mutex_lock(&lock);158 bool needs_signal = !signaled;159 signaled = true;160 pthread_mutex_unlock(&lock);161 162 if (needs_signal)163 pthread_cond_signal(&cond);164 }165 114 #endif
Note:
See TracChangeset
for help on using the changeset viewer.