Changeset 7b28e4a for src/libcfa/bits/locks.h
- Timestamp:
- Jun 8, 2018, 1:40:52 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 332d3c2, 9c32e21
- Parents:
- 90cedbdd (diff), beefc34c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/bits/locks.h
r90cedbdd r7b28e4a 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.