Changeset 4069faad for libcfa/src/bits
- Timestamp:
- May 1, 2020, 12:37:30 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- d45ed83
- Parents:
- 9987d79
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/bits/locks.hfa
r9987d79 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.