summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Src/Thread.cpp
diff options
context:
space:
mode:
authorShawn Hoffman <godisgovernment@gmail.com>2010-01-09 19:06:23 +0000
committerShawn Hoffman <godisgovernment@gmail.com>2010-01-09 19:06:23 +0000
commit1a5817f6fdcf2fd5967809422c252e503d930b13 (patch)
tree5d8aa7f59e1f11031d492ac55faf85404166eca7 /Source/Core/Common/Src/Thread.cpp
parentf472e2904d8581e2b199fa73cb1c7a09d0c1212b (diff)
from BhaaL: linux compile fix for r4794, Event::Wait now supports a timeout (default to INFINITE), and it returns true when the timeout expired. fixes issue 1974
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4799 8ced0084-cf51-0410-be5f-012b33b47a6e
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