Changes in libcfa/src/bits/locks.hfa [92e7631:4069faad]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/locks.hfa
r92e7631 r4069faad 113 113 114 114 struct __bin_sem_t { 115 bool signaled;116 115 pthread_mutex_t lock; 117 116 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;122 121 pthread_mutex_init(&lock, NULL); 123 122 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 if(!signaled) { // this must be a loop, not if!134 while(val < 1) { 135 135 pthread_cond_wait(&cond, &lock); 136 136 } 137 signaled = false;137 val -= 1; 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; 143 142 144 pthread_mutex_lock(&lock); 143 bool needs_signal = !signaled; 144 signaled = true; 145 if(val < 1) { 146 val += 1; 147 pthread_cond_signal(&cond); 148 needs_signal = true; 149 } 145 150 pthread_mutex_unlock(&lock); 146 147 if (needs_signal) pthread_cond_signal(&cond);148 151 149 152 return needs_signal;
Note:
See TracChangeset
for help on using the changeset viewer.