summaryrefslogtreecommitdiff
path: root/rts/win32/OSThreads.c
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2021-07-21 14:42:32 -0700
committerBen Gamari <ben@smart-cactus.org>2021-07-25 18:39:38 -0400
commit8ed5bcf70ad42677d6b01e35268d7a9609aa427a (patch)
tree90fd14b3494f4f6c21a9be36ce06b307badd2e7a /rts/win32/OSThreads.c
parent79794b3f1a604d46d1ea9835444fdc3997aedd10 (diff)
downloadhaskell-wip/osthread-fixes.tar.gz
rts/OSThreads: Improve error handling consistencywip/osthread-fixes
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/win32/OSThreads.c')
-rw-r--r--rts/win32/OSThreads.c21
1 files changed, 12 insertions, 9 deletions
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