]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/semaphore.cpp
Rename to libmspcore
[libs/core.git] / source / core / semaphore.cpp
diff --git a/source/core/semaphore.cpp b/source/core/semaphore.cpp
new file mode 100644 (file)
index 0000000..9139ce1
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+This file is part of libmspframework
+Copyright © 2006  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+#include <sys/time.h>
+#include <errno.h>
+#include "semaphore.h"
+#include "../time/timestamp.h"
+#include "../time/utils.h"
+
+namespace Msp {
+
+#ifndef WIN32
+int Semaphore::wait(const Time::TimeDelta &d)
+{
+       Time::TimeStamp ts=Time::now()+d;
+
+       timespec timeout;
+       timeout.tv_sec=ts.raw()/1000000;
+       timeout.tv_nsec=(ts.raw()%1000000)*1000;
+
+       MutexLock l(mutex);
+       int r=pthread_cond_timedwait(&cond, &mutex.mutex, &timeout);
+       if(r==ETIMEDOUT)
+               return 1;
+       else if(r)
+               return -1;
+       return 0;
+}
+#endif
+
+} // namespace Msp