Cleaned up the code. Added client exception for error handling.

This commit is contained in:
lotodore
2007-02-18 11:26:57 +00:00
parent e6c6fa0eee
commit 9ec3e020dd
9 changed files with 173 additions and 71 deletions
+24 -7
View File
@@ -19,6 +19,19 @@
#include "thread.h"
// This is ugly, but I can't help it.
#define ADD_MSEC_TO_XTIME(__xt, __msec) \
{ \
__xt.sec += __msec / 1000; \
__xt.nsec += (__msec % 1000) * 1000; \
if (__xt.nsec > NANOSECONDS_PER_SECOND) \
{ \
__xt.sec++; \
__xt.nsec -= NANOSECONDS_PER_SECOND; \
} \
}
// Helper class for thread creation.
class ThreadStarter
{
@@ -68,13 +81,7 @@ Thread::Join(unsigned msecTimeout)
// Calculate time after timeout
boost::xtime t;
boost::xtime_get(&t, boost::TIME_UTC);
t.sec += msecTimeout / 1000;
t.nsec += (msecTimeout % 1000) * 1000;
if (t.nsec > NANOSECONDS_PER_SECOND)
{
t.sec++;
t.nsec -= NANOSECONDS_PER_SECOND;
}
ADD_MSEC_TO_XTIME(t, msecTimeout);
// Wait for the termination of the application code.
boost::timed_mutex::scoped_timed_lock lock(m_isTerminatedMutex, t);
@@ -94,6 +101,16 @@ Thread::Join(unsigned msecTimeout)
return tmpIsTerminated;
}
void
Thread::Msleep(unsigned msecs)
{
boost::xtime t;
boost::xtime_get(&t, boost::TIME_UTC);
ADD_MSEC_TO_XTIME(t, msecs);
boost::thread::sleep(t);
}
void
Thread::MainWrapper()
{
+3
View File
@@ -46,6 +46,9 @@ public:
// You SHOULD always call join for a thread.
bool Join(unsigned msecTimeout);
// Sleep the currently active thread.
static void Msleep(unsigned msecs);
protected:
// Startup function.