summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/Event.cpp
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-10-06 17:38:42 +0200
committerHowaner <franzi.moos@googlemail.com>2014-10-06 17:38:42 +0200
commita59f2d15fbaa934f517d9bb5fbe4737078188f9d (patch)
tree3e54201e4cffb6b9675eb6a1584925b911f924f8 /src/OSSupport/Event.cpp
parentBetter StreamNextChunk() method (diff)
parentFixed crash in ForEachEntityInBox API. (diff)
downloadcuberite-a59f2d15fbaa934f517d9bb5fbe4737078188f9d.tar
cuberite-a59f2d15fbaa934f517d9bb5fbe4737078188f9d.tar.gz
cuberite-a59f2d15fbaa934f517d9bb5fbe4737078188f9d.tar.bz2
cuberite-a59f2d15fbaa934f517d9bb5fbe4737078188f9d.tar.lz
cuberite-a59f2d15fbaa934f517d9bb5fbe4737078188f9d.tar.xz
cuberite-a59f2d15fbaa934f517d9bb5fbe4737078188f9d.tar.zst
cuberite-a59f2d15fbaa934f517d9bb5fbe4737078188f9d.zip
Diffstat (limited to 'src/OSSupport/Event.cpp')
-rw-r--r--src/OSSupport/Event.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/OSSupport/Event.cpp b/src/OSSupport/Event.cpp
index 74f823216..7cf8a826c 100644
--- a/src/OSSupport/Event.cpp
+++ b/src/OSSupport/Event.cpp
@@ -102,6 +102,53 @@ void cEvent::Wait(void)
+bool cEvent::Wait(int a_TimeoutMSec)
+{
+ #ifdef _WIN32
+ DWORD res = WaitForSingleObject(m_Event, (DWORD)a_TimeoutMSec);
+ switch (res)
+ {
+ case WAIT_OBJECT_0: return true; // Regular event signalled
+ case WAIT_TIMEOUT: return false; // Regular event timeout
+ default:
+ {
+ LOGWARN("cEvent: waiting for the event failed: %u, GLE = %u. Continuing, but server may be unstable.", (unsigned)res, (unsigned)GetLastError());
+ return false;
+ }
+ }
+ #else
+ // Get the current time:
+ timespec timeout;
+ if (clock_gettime(CLOCK_REALTIME, &timeout) == -1)
+ {
+ LOGWARN("cEvent: Getting current time failed: %i, err = %s. Continuing, but the server may be unstable.", errno, GetOSErrorString(errno).c_str());
+ return false;
+ }
+
+ // Add the specified timeout:
+ timeout.tv_sec += a_TimeoutMSec / 1000;
+ timeout.tv_nsec += (a_TimeoutMSec % 1000) * 1000000; // 1 msec = 1000000 usec
+
+ // Wait with timeout:
+ int res = sem_timedwait(m_Event, &timeout);
+ switch (res)
+ {
+ case 0: return true; // Regular event signalled
+ case ETIMEDOUT: return false; // Regular even timeout
+ default:
+ {
+ AString error = GetOSErrorString(errno);
+ LOGWARN("cEvent: waiting for the event failed: %i, err = %s. Continuing, but server may be unstable.", res, error.c_str());
+ return false;
+ }
+ }
+ #endif
+}
+
+
+
+
+
void cEvent::Set(void)
{
#ifdef _WIN32