//--------------------- begin measurement code
// poll to align to a tick of gettimeofday
::gettimeofday(&tvtmp,0);
- do {
+ do {
::gettimeofday(&tvstart,0);
__asm__ __volatile__ (".byte 0x0f, 0x31" : "=A" (Tstart)); // RDTSC
} while (tvtmp.tv_usec!=tvstart.tv_usec);
::usleep(sktd_TSC_MeasurementPeriod);
//
::gettimeofday(&tvtmp,0);
- do {
+ do {
::gettimeofday(&tvend,0);
__asm__ __volatile__ (".byte 0x0f, 0x31" : "=A" (Tend)); // RDTSC
} while (tvtmp.tv_usec!=tvend.tv_usec);
#endif
return nTicksPerMicrosecond;
}
-
+
#if defined(__APPLE__) //&& !defined(__MACH__)
-
+
bool FindNetInterfaceByIPAddress(const char *sIP, char *sInterface) // sIP and sInterface are both char[16]
{
FILE *fProcess , *pSubcall;
while (pToken)
{
sprintf(sCommand, "ifconfig %s | grep \"inet %s \"", pToken, sIP);
-
+
pSubcall = popen(sCommand, "r");
if (pSubcall)
{
}
}
pclose(pSubcall);
- pToken = strtok(NULL, " ");
+ pToken = strtok(NULL, " ");
}
-
+
}
pclose(fProcess);
-
+
return res;
}
#endif // MACOS
#elif XPLATFORMTHREADS_POSIX
void yield() { ::sched_yield(); }
#endif
-
+
inline void obtain() { EnsureThreadingInitialized(); ::EnterCriticalSection (&m_critsec); }
inline void release() { EnsureThreadingInitialized(); ::LeaveCriticalSection (&m_critsec); }
inline bool tryobtain() { EnsureThreadingInitialized(); return TryEnterCriticalSection(&m_critsec)!=FALSE; }
-
+
#elif defined (XPLATFORMTHREADS_POSIX)
protected:
pthread_mutex_t m_ptmutex;
public:
- inline OSDependentMutex()
- {
- EnsureThreadingInitialized();
+ inline OSDependentMutex()
+ {
+ EnsureThreadingInitialized();
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
ThreadMutexInited::ThreadMutexInited() :
m_osdmutex(0) {}
-
+
void ThreadMutexInited::init()
{
if (! is_init())
m_osdmutex = new OSDependentMutex;
}
}
-
+
void ThreadMutexInited::uninit()
{
if (is_init())
m_osdmutex = 0;
}
}
-
+
ThreadMutexInited::~ThreadMutexInited()
{
uninit();
- }
-
+ }
+
void ThreadMutexInited::obtain()
{
if (is_init())
{
- m_osdmutex->obtain();
+ m_osdmutex->obtain();
}
- }
+ }
void ThreadMutexInited::release()
{
if (is_init())
{
- m_osdmutex->release();
+ m_osdmutex->release();
}
- }
-
+ }
+
bool ThreadMutexInited::tryobtain()
{
bool retVal = true;
if (is_init())
{
- retVal = m_osdmutex->tryobtain();
+ retVal = m_osdmutex->tryobtain();
}
return retVal;
- }
-
+ }
+
class ThreadConditionSignal::OSDependentObject : public noncopyableobject
{
#if defined (XPLATFORMTHREADS_POSIX)
pthread_cond_t m_ptcond;
pthread_mutex_t m_ptmutex;
public:
- inline OSDependentObject()
+ inline OSDependentObject()
{
- EnsureThreadingInitialized();
+ EnsureThreadingInitialized();
::pthread_mutex_init(&m_ptmutex,0);
- ::pthread_cond_init(&m_ptcond, 0);
+ ::pthread_cond_init(&m_ptcond, 0);
}
inline ~OSDependentObject() { ::pthread_cond_destroy(&m_ptcond), ::pthread_mutex_destroy(&m_ptmutex); }
inline void signal_unicast() { ::pthread_cond_signal(&m_ptcond); }
inline void signal_broadcast() { ::pthread_cond_broadcast(&m_ptcond); }
inline void await_signal() { ::pthread_cond_wait(&m_ptcond, &m_ptmutex); }
- inline bool await_signal(timediff td)
+ inline bool await_signal(timediff td)
{
timespec tspecDeadline;
timeval tvNow;
#endif // OS switch
};
- void ThreadConditionSignal::obtain_mutex()
- {
- m_osdepobj.obtain_mutex();
+ void ThreadConditionSignal::obtain_mutex()
+ {
+ m_osdepobj.obtain_mutex();
}
bool ThreadConditionSignal::tryobtain_mutex() { return m_osdepobj.tryobtain_mutex(); }
- void ThreadConditionSignal::release_mutex()
- {
- m_osdepobj.release_mutex();
+ void ThreadConditionSignal::release_mutex()
+ {
+ m_osdepobj.release_mutex();
}
void ThreadConditionSignal::await_condition() { m_osdepobj.await_signal(); }
0 // where to store thread ID
);
- if (h)
+ if (h)
{
th.m_oshandle = h;
if (pri!=ThreadPriority::Normal)
ThunkedThreadWrapper,
ptwdata
);
-
- if (anyerr)
+
+ if (anyerr)
th=Invalid;
else
th.m_oshandle = OSDependent::from_oshandle(pt);
class WCThreadRef::OSDependent
{
public:
- static void GetCurrentThreadRef(WCThreadRef& tid);
+ static void GetCurrentThreadRef(WCThreadRef& tid);
#if XPLATFORMTHREADS_WINDOWS
static inline uintptr_t from_os(DWORD thread_id) { return (uintptr_t)(thread_id); }
static inline DWORD to_os(uintptr_t thread_id) { return (DWORD)(thread_id); }
WCThreadRef GetCurrentThreadRef()
{
- EnsureThreadingInitialized(); // Is it necessary?
+ EnsureThreadingInitialized(); // Is it necessary?
WCThreadRef tRefToReturn;
WCThreadRef::OSDependent::GetCurrentThreadRef(tRefToReturn);
return tRefToReturn;
bool WCAtomicLock::obtain(const uint32_t in_num_trys)
{
bool retVal = false;
-
+
uint32_t timeOut = in_num_trys;
while (true)
{
sleep_milliseconds(1000);
}
}
-
+
return retVal;
}