From b9702fd55d7ed6d94f93a207014059bcf3578a6a Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Wed, 9 Jul 2003 02:37:10 +0000 Subject: "" svn path=/trunk/; revision=767 --- externals/grill/flext/source/flthr.cpp | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'externals/grill/flext/source/flthr.cpp') diff --git a/externals/grill/flext/source/flthr.cpp b/externals/grill/flext/source/flthr.cpp index 84623a3d..0846805c 100644 --- a/externals/grill/flext/source/flthr.cpp +++ b/externals/grill/flext/source/flthr.cpp @@ -17,6 +17,16 @@ WARRANTIES, see the file, "license.txt," in this distribution. #ifdef FLEXT_THREADS + +#include + +#if FLEXT_OS == FLEXT_OS_WIN +#include +#elif FLEXT_OS == FLEXT_OS_LINUX +#include +#include +#endif + #include //! Thread id of system thread @@ -492,4 +502,52 @@ flext_base::thr_entry::thr_entry(void (*m)(thr_params *),thr_params *p,thrid_t i {} + +#if FLEXT_THREADS == FLEXT_THR_POSIX +bool flext::ThrCond::Wait() { + Lock(); + bool ret = pthread_cond_wait(&cond,&mutex) == 0; + Unlock(); + return ret; +} + +bool flext::ThrCond::TimedWait(double ftime) +{ + timespec tm; +#if FLEXT_OS == FLEXT_OS_WIN + _timeb tmb; + _ftime(&tmb); + tm.tv_nsec = tmb.millitm*1000000; + tm.tv_sec = tmb.time; +#else +#if 0 // find out when the following is defined + clock_gettime(CLOCK_REALTIME,tm); +#else + struct timeval tp; + gettimeofday(&tp, NULL); + tm.tv_nsec = tp.tv_usec*1000; + tm.tv_sec = tp.tv_sec; +#endif +#endif + tm.tv_nsec += (long)((ftime-(long)ftime)*1.e9); + long nns = tm.tv_nsec%1000000000; + tm.tv_sec += (long)ftime+(tm.tv_nsec-nns)/1000000000; + tm.tv_nsec = nns; + + Lock(); + bool ret = pthread_cond_timedwait(&cond,&mutex,&tm) == 0; + Unlock(); + return ret; +} + +bool flext::ThrCond::Signal() +{ + Lock(); + bool ret = pthread_cond_signal(&cond) == 0; + Unlock(); + return ret; +} +#endif + + #endif // FLEXT_THREADS -- cgit v1.2.1