summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Src/Thread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/Common/Src/Thread.cpp')
-rw-r--r--Source/Core/Common/Src/Thread.cpp35
1 files changed, 30 insertions, 5 deletions
diff --git a/Source/Core/Common/Src/Thread.cpp b/Source/Core/Common/Src/Thread.cpp
index 05a930b9f3..bb0d591771 100644
--- a/Source/Core/Common/Src/Thread.cpp
+++ b/Source/Core/Common/Src/Thread.cpp
@@ -139,9 +139,9 @@ void Event::Set()
SetEvent(m_hEvent);
}
-void Event::Wait()
+bool Event::Wait(const u32 timeout)
{
- WaitForSingleObject(m_hEvent, INFINITE);
+ return WaitForSingleObject(m_hEvent, timeout) != WAIT_OBJECT_0;
}
inline HRESULT MsgWaitForSingleObject(HANDLE handle, DWORD timeout)
@@ -400,17 +400,42 @@ void Event::Set()
}
-void Event::Wait()
+bool Event::Wait(const u32 timeout)
{
+ bool timedout = false;
+ struct timespec wait;
pthread_mutex_lock(&mutex_);
- while (!is_set_)
+ if (timeout != INFINITE)
{
- pthread_cond_wait(&event_, &mutex_);
+ struct timeval now;
+ gettimeofday(&now, NULL);
+
+ memset(&wait, 0, sizeof(wait));
+ //TODO: timespec also has nanoseconds, but do we need them?
+ //as consequence, waiting is limited to seconds for now.
+ //the following just looks ridiculous, and probably fails for
+ //values 429 < ms <= 999 since it overflows the long.
+ //wait.tv_nsec = (now.tv_usec + (timeout % 1000) * 1000) * 1000);
+ wait.tv_sec = now.tv_sec + (timeout / 1000);
+ }
+
+ while (!is_set_ && !timedout)
+ {
+ if (timeout == INFINITE)
+ {
+ pthread_cond_wait(&event_, &mutex_);
+ }
+ else
+ {
+ timedout = pthread_cond_timedwait(&event_, &mutex_, &wait) == ETIMEDOUT;
+ }
}
is_set_ = false;
pthread_mutex_unlock(&mutex_);
+
+ return timedout;
}
#endif