summaryrefslogtreecommitdiff
path: root/rts/posix/OSThreads.c
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2021-07-21 14:42:32 -0700
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-07-27 04:49:00 -0400
commit0090517a8fccc0d6605e4b6d3d95568d91201d72 (patch)
tree61eeed903f8f06baeb6bcee941b0aa364c2311b7 /rts/posix/OSThreads.c
parentb19f1a6a541645b735e01aa2658f5493fb1cc97d (diff)
downloadhaskell-0090517a8fccc0d6605e4b6d3d95568d91201d72.tar.gz
rts/OSThreads: Improve error handling consistency
Previously we relied on the caller to check the return value from broadcastCondition and friends, most of whom neglected to do so. Given that these functions should not fail anyways, I've opted to drop the return value entirely and rather move the result check into the OSThreads functions. This slightly changes the semantics of timedWaitCondition which now returns false only in the case of timeout, rather than any error as previously done.
Diffstat (limited to 'rts/posix/OSThreads.c')
-rw-r--r--rts/posix/OSThreads.c28
1 files changed, 17 insertions, 11 deletions
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