From b4799c6b611ed3ef7291c37cc59bcb2e20bd3fad Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Thu, 16 Nov 2017 22:05:19 +0800 Subject: [PATCH] Update WinUtil --- WinUtil.cpp | 23 +++++++++++++++++++---- WinUtil.h | 4 ++-- 2 files changed, 21 insertions(+), 6 deletions(-) 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;