Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/bits/locks.h

    r85b1deb rea8b2f7  
    126126
    127127        struct __bin_sem_t {
    128                 bool                    signaled;
    129                 pthread_mutex_t         lock;
    130                 pthread_cond_t          cond;
     128                int_fast8_t     counter;
     129                pthread_mutex_t lock;
     130                pthread_cond_t  cond;
    131131        };
    132132
    133133        static inline void ?{}(__bin_sem_t & this) with( this ) {
    134                 signaled = false;
     134                counter = 0;
    135135                pthread_mutex_init(&lock, NULL);
    136136                pthread_cond_init (&cond, NULL);
     
    145145                verify(__cfaabi_dbg_in_kernel());
    146146                pthread_mutex_lock(&lock);
    147                         if(!signaled) {   // this must be a loop, not if!
    148                                 pthread_cond_wait(&cond, &lock);
    149                         }
    150                         signaled = false;
     147                if(counter != 0) {   // this must be a loop, not if!
     148                        pthread_cond_wait(&cond, &lock);
     149                }
     150                counter = 1;
    151151                pthread_mutex_unlock(&lock);
    152152        }
     
    154154        static inline void post(__bin_sem_t & this) with( this ) {
    155155                verify(__cfaabi_dbg_in_kernel());
    156 
    157156                pthread_mutex_lock(&lock);
    158                         bool needs_signal = !signaled;
    159                         signaled = true;
     157                bool needs_signal = counter == 0;
     158                counter = 1;
    160159                pthread_mutex_unlock(&lock);
    161 
    162                 if (needs_signal)
     160                if (!needs_signal)
    163161                        pthread_cond_signal(&cond);
    164         }
     162                }
    165163#endif
Note: See TracChangeset for help on using the changeset viewer.