]> git.tdb.fi Git - libs/core.git/blobdiff - source/core/semaphore.cpp
Semaphore is now win32-compatible, I hope
[libs/core.git] / source / core / semaphore.cpp
index 9139ce1429b8e3ab484c38256925c7d1619ca83d..06777fb984872f9444dc4c3146208c3e50643ae3 100644 (file)
@@ -11,9 +11,9 @@ Distributed under the LGPL
 
 namespace Msp {
 
 
 namespace Msp {
 
-#ifndef WIN32
 int Semaphore::wait(const Time::TimeDelta &d)
 {
 int Semaphore::wait(const Time::TimeDelta &d)
 {
+#ifndef WIN32
        Time::TimeStamp ts=Time::now()+d;
 
        timespec timeout;
        Time::TimeStamp ts=Time::now()+d;
 
        timespec timeout;
@@ -21,13 +21,15 @@ int Semaphore::wait(const Time::TimeDelta &d)
        timeout.tv_nsec=(ts.raw()%1000000)*1000;
 
        MutexLock l(mutex);
        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;
        if(r==ETIMEDOUT)
                return 1;
        else if(r)
                return -1;
        return 0;
-}
+#else
+       return WaitForSingleObject(sem, (DWORD)(d/Time::usec))==WAIT_OBJECT_0;
 #endif
 #endif
+}
 
 } // namespace Msp
 
 } // namespace Msp