X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Fsemaphore.cpp;h=139cae2f4ca523ffac47af9487663799a65c17ea;hp=bd1180b805b2701231e7833414717ea8bd7a9802;hb=d5dd704b2576f878809e87dbb8ff8591b9bdbce4;hpb=47a232c3c19e718a30281d3ada8acc1b6212ea8c diff --git a/source/core/semaphore.cpp b/source/core/semaphore.cpp index bd1180b..139cae2 100644 --- a/source/core/semaphore.cpp +++ b/source/core/semaphore.cpp @@ -33,8 +33,8 @@ Semaphore::Semaphore(Mutex &m): void Semaphore::init() { #ifdef WIN32 - count=0; - sem=CreateSemaphore(0, 0, 32, 0); + count = 0; + sem = CreateSemaphore(0, 0, 32, 0); #else pthread_cond_init(&sem, 0); #endif @@ -57,9 +57,9 @@ int Semaphore::signal() if(count==0) return 0; - int ret=!ReleaseSemaphore(sem, 1, 0); + int ret = !ReleaseSemaphore(sem, 1, 0); - unsigned old_count=count; + unsigned old_count = count; mutex->unlock(); while(count==old_count) Sleep(0); @@ -72,7 +72,7 @@ int Semaphore::broadcast() { if(count==0) return 0; - int ret=!ReleaseSemaphore(sem, count, 0); + int ret = !ReleaseSemaphore(sem, count, 0); mutex->unlock(); while(count) @@ -86,7 +86,7 @@ int Semaphore::wait() { ++count; mutex->unlock(); - DWORD ret=WaitForSingleObject(sem, INFINITE); + DWORD ret = WaitForSingleObject(sem, INFINITE); mutex->lock(); --count; @@ -97,13 +97,13 @@ int Semaphore::wait() int Semaphore::wait(const Time::TimeDelta &d) { #ifndef WIN32 - Time::TimeStamp ts=Time::now()+d; + Time::TimeStamp ts = Time::now()+d; timespec timeout; - timeout.tv_sec=ts.raw()/1000000; - timeout.tv_nsec=(ts.raw()%1000000)*1000; + timeout.tv_sec = ts.raw()/1000000; + timeout.tv_nsec = (ts.raw()%1000000)*1000; - int r=pthread_cond_timedwait(&sem, &mutex->mutex, &timeout); + int r = pthread_cond_timedwait(&sem, &mutex->mutex, &timeout); if(r==ETIMEDOUT) return 1; else if(r) @@ -112,7 +112,7 @@ int Semaphore::wait(const Time::TimeDelta &d) #else ++count; mutex->lock(); - DWORD ret=WaitForSingleObject(sem, (DWORD)(d/Time::usec)); + DWORD ret = WaitForSingleObject(sem, (DWORD)(d/Time::usec)); mutex->unlock(); --count; return ret==WAIT_OBJECT_0;