Ignore:
File:
1 edited

Legend:

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

    rea8b2f7 r85b1deb  
    126126
    127127        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;
    131131        };
    132132
    133133        static inline void ?{}(__bin_sem_t & this) with( this ) {
    134                 counter = 0;
     134                signaled = false;
    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(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;
    151151                pthread_mutex_unlock(&lock);
    152152        }
     
    154154        static inline void post(__bin_sem_t & this) with( this ) {
    155155                verify(__cfaabi_dbg_in_kernel());
     156
    156157                pthread_mutex_lock(&lock);
    157                 bool needs_signal = counter == 0;
    158                 counter = 1;
     158                        bool needs_signal = !signaled;
     159                        signaled = true;
    159160                pthread_mutex_unlock(&lock);
    160                 if (!needs_signal)
     161
     162                if (needs_signal)
    161163                        pthread_cond_signal(&cond);
    162                 }
     164        }
    163165#endif
Note: See TracChangeset for help on using the changeset viewer.