/*
-This file is part of libmspframework
+This file is part of libmspcore
Copyright © 2006 Mikko Rasa, Mikkosoft Productions
Distributed under the LGPL
*/
#include <errno.h>
#include "semaphore.h"
#include "../time/timestamp.h"
+#include "../time/units.h"
#include "../time/utils.h"
namespace Msp {
-#ifndef WIN32
int Semaphore::wait(const Time::TimeDelta &d)
{
+#ifndef WIN32
Time::TimeStamp ts=Time::now()+d;
timespec timeout;
timeout.tv_nsec=(ts.raw()%1000000)*1000;
MutexLock l(mutex);
- int r=pthread_cond_timedwait(&cond, &mutex.mutex, &timeout);
+ int r=pthread_cond_timedwait(&sem, &mutex.mutex, &timeout);
if(r==ETIMEDOUT)
return 1;
else if(r)
return -1;
return 0;
-}
+#else
+ return WaitForSingleObject(sem, (DWORD)(d/Time::usec))==WAIT_OBJECT_0;
#endif
+}
} // namespace Msp