Changes in src/libcfa/bits/locks.h [13073be:ea8b2f7]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/bits/locks.h
r13073be rea8b2f7 18 18 #include "bits/debug.h" 19 19 #include "bits/defs.h" 20 #include <assert.h> 21 22 #ifdef __cforall 23 extern "C" { 24 #include <pthread.h> 25 } 26 #endif 20 27 21 28 // pause to prevent excess processor bus usage … … 112 119 __atomic_clear( &this.lock, __ATOMIC_RELEASE ); 113 120 } 121 122 123 #ifdef __CFA_WITH_VERIFY__ 124 extern bool __cfaabi_dbg_in_kernel(); 125 #endif 126 127 struct __bin_sem_t { 128 int_fast8_t counter; 129 pthread_mutex_t lock; 130 pthread_cond_t cond; 131 }; 132 133 static inline void ?{}(__bin_sem_t & this) with( this ) { 134 counter = 0; 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(counter != 0) { // this must be a loop, not if! 148 pthread_cond_wait(&cond, &lock); 149 } 150 counter = 1; 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 pthread_mutex_lock(&lock); 157 bool needs_signal = counter == 0; 158 counter = 1; 159 pthread_mutex_unlock(&lock); 160 if (!needs_signal) 161 pthread_cond_signal(&cond); 162 } 114 163 #endif
Note: See TracChangeset
for help on using the changeset viewer.