Changes in src/libcfa/bits/locks.h [ea8b2f7:85b1deb]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/bits/locks.h
rea8b2f7 r85b1deb 126 126 127 127 struct __bin_sem_t { 128 int_fast8_t counter;129 pthread_mutex_t lock;130 pthread_cond_t cond;128 bool signaled; 129 pthread_mutex_t lock; 130 pthread_cond_t cond; 131 131 }; 132 132 133 133 static inline void ?{}(__bin_sem_t & this) with( this ) { 134 counter = 0;134 signaled = false; 135 135 pthread_mutex_init(&lock, NULL); 136 136 pthread_cond_init (&cond, NULL); … … 145 145 verify(__cfaabi_dbg_in_kernel()); 146 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;147 if(!signaled) { // this must be a loop, not if! 148 pthread_cond_wait(&cond, &lock); 149 } 150 signaled = false; 151 151 pthread_mutex_unlock(&lock); 152 152 } … … 154 154 static inline void post(__bin_sem_t & this) with( this ) { 155 155 verify(__cfaabi_dbg_in_kernel()); 156 156 157 pthread_mutex_lock(&lock); 157 bool needs_signal = counter == 0;158 counter = 1;158 bool needs_signal = !signaled; 159 signaled = true; 159 160 pthread_mutex_unlock(&lock); 160 if (!needs_signal) 161 162 if (needs_signal) 161 163 pthread_cond_signal(&cond); 162 164 } 163 165 #endif
Note: See TracChangeset
for help on using the changeset viewer.