diff --git a/WinUtil.cpp b/WinUtil.cpp index 5cdf9ed..141dcdd 100644 --- a/WinUtil.cpp +++ b/WinUtil.cpp @@ -72,14 +72,29 @@ DWORD NamedMutex::getError() const return errcode; } -void NamedMutex::wait() +int NamedMutex::wait() { - WaitForSingleObject(hmtx,INFINITE); + return wait_for(INFINITE); } -void NamedMutex::wait_for(int ms) +int NamedMutex::wait_for(int ms) { - WaitForSingleObject(hmtx,ms); + DWORD ret=WaitForSingleObject(hmtx,ms); + if(ret==WAIT_OBJECT_0) + { + return 1; + } + else if(ret==WAIT_TIMEOUT) + { + return 0; + } + else + { + // WAIT_ABANDONED + // WAIT_FAILED + errcode=GetLastError(); + return -1; + } } void NamedMutex::release() diff --git a/WinUtil.h b/WinUtil.h index 60c5949..cbd608b 100644 --- a/WinUtil.h +++ b/WinUtil.h @@ -29,8 +29,8 @@ public: DWORD getError() const; /// If the mutex has been occupied by this process, wait() will return immediately. - void wait(); - void wait_for(int ms); + int wait(); + int wait_for(int ms); void release(); private: HANDLE hmtx;