18 #ifndef UTIL_INLINEFUNCTIONS_H 19 #define UTIL_INLINEFUNCTIONS_H 21 #include "../Util/GlobalDefines.h" 31 #include <sys/timeb.h> 38 #include <sys/timeb.h> 40 #include <semaphore.h> 45 #define CRITICAL_SECTION int 53 #define CRITICAL_SECTION pthread_mutex_t 55 #include "../Util/Math.h" 58 template <
class T>
inline T
sqr(T fValue)
64 template <
class T>
inline int iRound(T v)
66 return (v>=0) ? (int)(v+.5) : (int)(v-.5);
84 inline long abs(
long iValue)
86 #if defined(NO_CAST_FUNCTION_TEMPLATES) 87 return long(
abs(iValue));
89 return static_cast<long>(
abs(iValue));
94 inline unsigned long abs(
unsigned long uiValue)
96 #if defined(NO_CAST_FUNCTION_TEMPLATES) 97 return unsigned long(
abs(uiValue));
99 return static_cast<unsigned long>(
abs(uiValue));
104 inline float abs(
float fValue)
106 #if defined(NO_CAST_FUNCTION_TEMPLATES) 107 return float(fabs(fValue));
109 return static_cast<float>(fabs(fValue));
114 inline double abs(
double fValue)
124 return ((b) >= 0.0) ? fabs(a) : -fabs(a);
130 return ((b) >= 0.0) ? fabs(a) : -fabs(a);
133 template <
class T>
inline void util_shift(T a, T b, T c, T d)
143 return fAngle * M_PI / 180.0;
149 return fAngle * 180.0 / M_PI;
155 return fPhase - (2*M_PI)*floor(fPhase*
M_1_2PI);
171 template <
class Type>
180 #ifndef __HAS_SLEEP__ 181 #define __HAS_SLEEP__ 184 inline void sleep(
unsigned int uiSec)
186 #if defined(NO_CAST_FUNCTION_TEMPLATES) 187 Sleep(DWORD(uiSec*1000));
189 Sleep(static_cast<DWORD> (uiSec*1000));
195 #if defined (__LINUX__) 196 inline int EnterCriticalSection(CRITICAL_SECTION *cs)
198 pthread_mutex_lock(cs);
202 inline int LeaveCriticalSection(CRITICAL_SECTION *cs)
204 pthread_mutex_unlock(cs);
208 inline int InitializeCriticalSection(CRITICAL_SECTION *cs)
210 pthread_mutex_init(cs,NULL);
211 pthread_mutex_unlock(cs);
215 inline int DeleteCriticalSection(CRITICAL_SECTION *cs)
221 inline int Sleep(
long iMilliSec)
225 tm.tv_sec=iMilliSec/1000;
226 tm.tv_nsec=(iMilliSec%1000)*1000000;
233 #if defined (__QNX__) 234 inline int EnterCriticalSection(CRITICAL_SECTION *cs)
236 sem_wait( (sem_t *)cs );
239 inline int LeaveCriticalSection(CRITICAL_SECTION *cs)
241 sem_post( (sem_t *)cs );
244 inline int InitializeCriticalSection(CRITICAL_SECTION *cs)
246 sem_init( (sem_t*)cs, 1, 1 );
250 inline int DeleteCriticalSection(CRITICAL_SECTION *cs)
253 sem_destroy( (sem_t*)cs );
257 inline int Sleep(
long iMilliSec)
304 #endif // UTIL_INLINEFUNCTIONS_H double util_phaseDifference(double fPhase1, double fPhase2)
unsigned int util_setAlarm(unsigned int uiSec)
void util_shift(T a, T b, T c, T d)
double util_averagedPhase(double fPhase1, double fPhase2)
double util_degToRad(double fAngle)
double util_radToDeg(double fAngle)
float util_sign(float a, float b)
unsigned int util_deactivateAlarm()
double util_adjustedPhase(double fPhase)
void util_swap(Type &a, Type &b)