summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/rts/OSThreads.h7
-rw-r--r--rts/posix/OSThreads.c28
-rw-r--r--rts/win32/OSThreads.c21
3 files changed, 33 insertions, 23 deletions
diff --git a/includes/rts/OSThreads.h b/includes/rts/OSThreads.h
index b711036b17..08d90de06e 100644
--- a/includes/rts/OSThreads.h
+++ b/includes/rts/OSThreads.h
@@ -173,9 +173,10 @@ extern void joinOSThread ( OSThreadId id );
//
extern void initCondition ( Condition* pCond );
extern void closeCondition ( Condition* pCond );
-extern bool broadcastCondition ( Condition* pCond );
-extern bool signalCondition ( Condition* pCond );
-extern bool waitCondition ( Condition* pCond, Mutex* pMut );
+extern void broadcastCondition ( Condition* pCond );
+extern void signalCondition ( Condition* pCond );
+extern void waitCondition ( Condition* pCond, Mutex* pMut );
+// Returns false on timeout, true otherwise.
extern bool timedWaitCondition ( Condition* pCond, Mutex* pMut, Time timeout);
//
diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c
index 8ac23d4168..04375006d2 100644
--- a/rts/posix/OSThreads.c
+++ b/rts/posix/OSThreads.c
@@ -104,33 +104,31 @@
void
initCondition( Condition* pCond )
{
- pthread_cond_init(pCond, NULL);
- return;
+ CHECK(pthread_cond_init(pCond, NULL) == 0);
}
void
closeCondition( Condition* pCond )
{
- pthread_cond_destroy(pCond);
- return;
+ CHECK(pthread_cond_destroy(pCond) == 0);
}
-bool
+void
broadcastCondition ( Condition* pCond )
{
- return (pthread_cond_broadcast(pCond) == 0);
+ CHECK(pthread_cond_broadcast(pCond) == 0);
}
-bool
+void
signalCondition ( Condition* pCond )
{
- return (pthread_cond_signal(pCond) == 0);
+ CHECK(pthread_cond_signal(pCond) == 0);
}
-bool
+void
waitCondition ( Condition* pCond, Mutex* pMut )
{
- return (pthread_cond_wait(pCond,pMut) == 0);
+ CHECK(pthread_cond_wait(pCond,pMut) == 0);
}
bool
@@ -143,7 +141,15 @@ timedWaitCondition ( Condition* pCond, Mutex* pMut, Time timeout) {
.tv_nsec = TimeToNS(timeout - SecondsToTime(secs))
};
- return pthread_cond_timedwait(pCond,pMut, &t) == 0;
+ int ret = pthread_cond_timedwait(pCond,pMut, &t);
+ switch (ret) {
+ case ETIMEDOUT:
+ return false;
+ case 0:
+ return true;
+ default:
+ barf("pthread_cond_timedwait failed");
+ }
}
void
diff --git a/rts/win32/OSThreads.c b/rts/win32/OSThreads.c
index 46e363b3ab..2c1e462cb4 100644
--- a/rts/win32/OSThreads.c
+++ b/rts/win32/OSThreads.c
@@ -543,25 +543,22 @@ closeCondition( Condition* pCond STG_UNUSED)
return;
}
-bool
+void
broadcastCondition ( Condition* pCond )
{
WakeAllConditionVariable(pCond);
- return true;
}
-bool
+void
signalCondition ( Condition* pCond )
{
WakeConditionVariable(pCond);
- return true;
}
-bool
+void
waitCondition ( Condition* pCond, Mutex* pMut )
{
- SleepConditionVariableSRW(pCond, pMut, INFINITE, 0);
- return true;
+ CHECK(SleepConditionVariableSRW(pCond, pMut, INFINITE, 0));
}
bool
@@ -570,8 +567,14 @@ timedWaitCondition ( Condition* pCond, Mutex* pMut, Time timeout )
// If we pass a timeout of 0 SleepConditionVariableSRW will return immediately
// https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-sleepconditionvariablesrw
DWORD ms = (DWORD)stg_min(1, TimeToMS(timeout));
- SleepConditionVariableSRW(pCond, pMut, ms, 0);
- return true;
+ BOOL res = SleepConditionVariableSRW(pCond, pMut, ms, 0);
+ if (res) {
+ return true; // success
+ } else if (GetLastError() == ERROR_TIMEOUT) {
+ return false; // timeout
+ } else {
+ barf("timedWaitCondition: error %" FMT_Word, (StgWord) GetLastError());
+ }
}
void