-/* $Id$
-
-This file is part of libmspcore
-Copyright © 2006 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
#ifdef WIN32
#include <windows.h>
#else
#include <sys/time.h>
#include <cerrno>
#endif
+#include <msp/time/rawtime_private.h>
#include <msp/time/timestamp.h>
-#include <msp/time/units.h>
#include <msp/time/utils.h>
#include "mutex_private.h"
#include "semaphore.h"
{
#ifdef WIN32
if(!ReleaseSemaphore(priv->handle, 1, 0))
- throw system_error("Semaphore::signal");
+ throw system_error("ReleaseSemaphore");
#else
MutexLock mlock(priv->mutex);
if(priv->count<priv->limit)
++priv->count;
if(int err = pthread_cond_signal(&priv->cond))
- throw system_error("Semaphore::signal", err);
+ throw system_error("pthread_cond_signal", err);
#endif
}
#ifdef WIN32
DWORD ret = WaitForSingleObject(priv->handle, INFINITE);
if(ret==WAIT_FAILED)
- throw system_error("Semaphore::wait");
+ throw system_error("WaitForSingleObject");
#else
MutexLock mlock(priv->mutex);
while(!priv->count)
if(int err = pthread_cond_wait(&priv->cond, &priv->mutex.priv->mutex))
- throw system_error("Semaphore::wait", err);
+ throw system_error("pthread_cond_wait", err);
--priv->count;
#endif
}
#ifdef WIN32
DWORD ret = WaitForSingleObject(priv->handle, (DWORD)(d/Time::usec));
if(ret==WAIT_FAILED)
- throw system_error("Semaphore::wait");
+ throw system_error("WaitForSingleObject");
return ret==WAIT_OBJECT_0;
#else
- Time::TimeStamp ts = Time::now()+d;
-
- timespec timeout;
- timeout.tv_sec = ts.raw()/1000000;
- timeout.tv_nsec = (ts.raw()%1000000)*1000;
+ timespec timeout = Time::rawtime_to_timespec((Time::now()+d).raw());
int err = pthread_cond_timedwait(&priv->cond, &priv->mutex.priv->mutex, &timeout);
if(err && err!=ETIMEDOUT)
- throw system_error("Semaphore::wait", err);
+ throw system_error("pthread_cond_timedwait", err);
return err==0;
#endif
}