Changes in libcfa/src/bits/locks.hfa [4069faad:92e7631]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/locks.hfa
r4069faad r92e7631 113 113 114 114 struct __bin_sem_t { 115 bool signaled; 115 116 pthread_mutex_t lock; 116 117 pthread_cond_t cond; 117 int val;118 118 }; 119 119 120 120 static inline void ?{}(__bin_sem_t & this) with( this ) { 121 signaled = false; 121 122 pthread_mutex_init(&lock, NULL); 122 123 pthread_cond_init (&cond, NULL); 123 val = 0;124 124 } 125 125 … … 132 132 verify(__cfaabi_dbg_in_kernel()); 133 133 pthread_mutex_lock(&lock); 134 while(val < 1) {134 if(!signaled) { // this must be a loop, not if! 135 135 pthread_cond_wait(&cond, &lock); 136 136 } 137 val -= 1;137 signaled = false; 138 138 pthread_mutex_unlock(&lock); 139 139 } 140 140 141 141 static inline bool post(__bin_sem_t & this) with( this ) { 142 bool needs_signal = false; 142 pthread_mutex_lock(&lock); 143 bool needs_signal = !signaled; 144 signaled = true; 145 pthread_mutex_unlock(&lock); 143 146 144 pthread_mutex_lock(&lock); 145 if(val < 1) { 146 val += 1; 147 pthread_cond_signal(&cond); 148 needs_signal = true; 149 } 150 pthread_mutex_unlock(&lock); 147 if (needs_signal) pthread_cond_signal(&cond); 151 148 152 149 return needs_signal;
Note:
See TracChangeset
for help on using the changeset viewer.