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/flatom_pr.cpp | 6 --- externals/grill/flext/source/flprefix.h | 8 +++ externals/grill/flext/source/flsupport.cpp | 6 +-- externals/grill/flext/source/flsupport.h | 81 ++++++++---------------------- externals/grill/flext/source/flthr.cpp | 58 +++++++++++++++++++++ 5 files changed, 91 insertions(+), 68 deletions(-) (limited to 'externals/grill/flext/source') diff --git a/externals/grill/flext/source/flatom_pr.cpp b/externals/grill/flext/source/flatom_pr.cpp index 898c4dd6..e4989320 100644 --- a/externals/grill/flext/source/flatom_pr.cpp +++ b/externals/grill/flext/source/flatom_pr.cpp @@ -18,12 +18,6 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include #include -#ifdef __MWERKS__ -#define STD std -#else -#define STD -#endif - void flext::PrintAtom(const t_atom &a,char *buf,int bufsz) { GetAString(a,buf,bufsz?bufsz:100000); diff --git a/externals/grill/flext/source/flprefix.h b/externals/grill/flext/source/flprefix.h index 14a9edf6..2399eef5 100755 --- a/externals/grill/flext/source/flprefix.h +++ b/externals/grill/flext/source/flprefix.h @@ -334,4 +334,12 @@ WARRANTIES, see the file, "license.txt," in this distribution. #endif #endif +// std namespace +#ifdef __MWERKS__ +#define STD std +#else +#define STD +#endif + + #endif // __FLEXT_PREFIX_H diff --git a/externals/grill/flext/source/flsupport.cpp b/externals/grill/flext/source/flsupport.cpp index 9e6a2491..78aeb6d0 100644 --- a/externals/grill/flext/source/flsupport.cpp +++ b/externals/grill/flext/source/flsupport.cpp @@ -141,9 +141,9 @@ void flext::GetAString(const t_atom &a,char *buf,int szbuf) atom_string(const_cast(&a),buf,szbuf); #else // no checking for size here - if(IsSymbol(a)) sprintf(buf,GetString(a)); - else if(IsFloat(a)) sprintf(buf,"%f",GetFloat(a)); - else if(IsInt(a)) sprintf(buf,"%i",GetInt(a)); + if(IsSymbol(a)) STD::sprintf(buf,GetString(a)); + else if(IsFloat(a)) STD::sprintf(buf,"%f",GetFloat(a)); + else if(IsInt(a)) STD::sprintf(buf,"%i",GetInt(a)); else *buf = 0; #endif } diff --git a/externals/grill/flext/source/flsupport.h b/externals/grill/flext/source/flsupport.h index f2129d7c..b2132289 100644 --- a/externals/grill/flext/source/flsupport.h +++ b/externals/grill/flext/source/flsupport.h @@ -16,11 +16,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. #define __FLSUPPORT_H #include "flstdc.h" -#include -#if FLEXT_OS == FLEXT_OS_WIN -#include -#endif class FLEXT_SHARE flext_base; @@ -296,12 +292,7 @@ public: //! Compare two atoms static int CmpAtom(const t_atom &a,const t_atom &b); - static bool operator ==(const t_atom &a,const t_atom &b) { return CmpAtom(a,b) == 0; } - static bool operator !=(const t_atom &a,const t_atom &b) { return CmpAtom(a,b) != 0; } - static bool operator <(const t_atom &a,const t_atom &b) { return CmpAtom(a,b) < 0; } - static bool operator <=(const t_atom &a,const t_atom &b) { return CmpAtom(a,b) <= 0; } - static bool operator >(const t_atom &a,const t_atom &b) { return CmpAtom(a,b) > 0; } - static bool operator >=(const t_atom &a,const t_atom &b) { return CmpAtom(a,b) >= 0; } + // there are some more comparison functions for t_atom types outside the class #if FLEXT_SYS == FLEXT_SYS_JMAX //! Set atom from another atom @@ -755,10 +746,10 @@ public: //! Lock thread mutex bool Lock() { return pthread_mutex_lock(&mutex) == 0; } - /*! \brief Wait to lock thread mutex. + /*! Wait to lock thread mutex. \todo Implement! */ - bool WaitForLock(double tm) { return pthread_mutex_lock(&mutex) == 0; } +// bool WaitForLock(double tm) { return pthread_mutex_lock(&mutex) == 0; } //! Try to lock, but don't wait bool TryLock() { return pthread_mutex_trylock(&mutex) == 0; } //! Unlock thread mutex @@ -779,7 +770,7 @@ public: //! Lock thread mutex bool Lock() { return MPEnterCriticalRegion(crit,kDurationForever) == noErr; } //! Wait to lock thread mutex - bool WaitForLock(double tm) { return MPEnterCriticalRegion(crit,tm*kDurationMicrosecond*1.e6) == noErr; } +// bool WaitForLock(double tm) { return MPEnterCriticalRegion(crit,tm*kDurationMicrosecond*1.e6) == noErr; } //! Try to lock, but don't wait bool TryLock() { return MPEnterCriticalRegion(crit,kDurationImmediate) == noErr; } //! Unlock thread mutex @@ -806,57 +797,19 @@ public: ~ThrCond() { pthread_cond_destroy(&cond); } //! Wait for condition - bool Wait() { - Lock(); - bool ret = pthread_cond_wait(&cond,&mutex) == 0; - Unlock(); - return ret; - } + bool Wait(); - /*! \brief Wait for condition (for a certain time). + /*! Wait for condition (for a certain time). \param ftime Wait time in seconds \ret 0 = signalled, 1 = timed out \remark If ftime = 0 this may suck away your cpu if used in a signalled loop. + \remark The time resolution of the implementation is required to be at least ms. */ - bool 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; - rs = 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 TimedWait(double ftime); //! Signal condition - bool Signal() - { - Lock(); - bool ret = pthread_cond_signal(&cond) == 0; - Unlock(); - return ret; - } - //! Broadcast condition -// int Broadcast() { return pthread_cond_broadcast(&cond); } + bool Signal(); + protected: pthread_cond_t cond; }; @@ -878,8 +831,7 @@ public: //! Signal condition bool Signal() { return MPSetEvent(ev,1) == noErr; } // one bit needs to be set at least - //! Broadcast condition -// int Broadcast() { return pthread_cond_broadcast(&cond); } + protected: MPEventID ev; }; @@ -1050,4 +1002,15 @@ protected: static unsigned long simdcaps; }; + +// gcc doesn't like these to be included into the flext class (even if static) +inline bool operator ==(const t_atom &a,const t_atom &b) { return flext::CmpAtom(a,b) == 0; } +inline bool operator !=(const t_atom &a,const t_atom &b) { return flext::CmpAtom(a,b) != 0; } +inline bool operator <(const t_atom &a,const t_atom &b) { return flext::CmpAtom(a,b) < 0; } +inline bool operator <=(const t_atom &a,const t_atom &b) { return flext::CmpAtom(a,b) <= 0; } +inline bool operator >(const t_atom &a,const t_atom &b) { return flext::CmpAtom(a,b) > 0; } +inline bool operator >=(const t_atom &a,const t_atom &b) { return flext::CmpAtom(a,b) >= 0; } + + + #endif 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