5.1. Portable Condition Variable

Start cpp section to pthread/pthread_condv.hpp[1 /1 ]
     1: #line 967 "./lpsrc/flx_pthread.pak"
     2: #ifndef __FLX_PTHREAD_CONDV_H__
     3: #define __FLX_PTHREAD_CONDV_H__
     4: #include <flx_pthread_config.hpp>
     5: #include "pthread_mutex.hpp"
     6: 
     7: #include "pthread_win_posix_condv_emul.hpp"
     8: 
     9: namespace flx { namespace pthread {
    10: 
    11: // ********************************************************
    12: /// Condition Variable.
    13: // ********************************************************
    14: class PTHREAD_EXTERN flx_condv_t {
    15: public:
    16:   pthread_cond_t cv;        // be nice, don't touch
    17:   flx_condv_t();
    18:   ~flx_condv_t();
    19:   void signal();
    20:   void broadcast();
    21:   void wait(flx_mutex_t*);
    22:   int timedwait(flx_mutex_t*, timespec*);
    23: };
    24: 
    25: }} // namespace pthread, flx
    26: #endif
    27: 
End cpp section to pthread/pthread_condv.hpp[1]
Start cpp section to pthread/pthread_condv.cpp[1 /1 ]
     1: #line 995 "./lpsrc/flx_pthread.pak"
     2: #include "pthread_condv.hpp"
     3: #include <stdio.h>        // printf debugging
     4: #include <assert.h>
     5: 
     6: namespace flx { namespace pthread {
     7: 
     8: flx_condv_t::flx_condv_t() { pthread_cond_init(&cv, NULL); }
     9: flx_condv_t::~flx_condv_t() { pthread_cond_destroy(&cv); }
    10: void flx_condv_t::wait(flx_mutex_t *m) { pthread_cond_wait(&cv,&(m->m)); }
    11: void flx_condv_t::signal() { pthread_cond_signal(&cv);}
    12: void flx_condv_t::broadcast() { pthread_cond_broadcast(&cv); }
    13: int flx_condv_t::timedwait(flx_mutex_t *m, timespec *t) {
    14:   int res = pthread_cond_timedwait(&cv,&(m->m),t);
    15:   #if !FLX_WIN32
    16:   if(res==EINVAL) return 0; // this is NOT an error!
    17:   #endif
    18:   return res;
    19: }
    20: }}
    21: 
End cpp section to pthread/pthread_condv.cpp[1]