summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Hambüchen <mail@nh2.me>2019-02-14 16:52:17 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-02-19 06:20:13 -0500
commit76ac103f5021cba5cd000293c7cb8c2bd3148e7a (patch)
treef5b48d9ad3877beb62f223a6d96fea6a714b78d9
parent7833cf407d1f608bebb1d38bb99d3035d8d735e6 (diff)
downloadhaskell-76ac103f5021cba5cd000293c7cb8c2bd3148e7a.tar.gz
base: Document errno behaviour in haddocks.
Also add an implementation comment for details.
-rw-r--r--libraries/base/Foreign/C/Error.hs6
1 files changed, 5 insertions, 1 deletions
diff --git a/libraries/base/Foreign/C/Error.hs b/libraries/base/Foreign/C/Error.hs
index 90b949b782..6d6c0cc0dd 100644
--- a/libraries/base/Foreign/C/Error.hs
+++ b/libraries/base/Foreign/C/Error.hs
@@ -255,11 +255,15 @@ isValidErrno (Errno errno) = errno /= -1
-- | Get the current value of @errno@ in the current thread.
--
+-- On GHC, the runtime will ensure that any Haskell thread will only see "its own"
+-- @errno@, by saving and restoring the value when Haskell threads are scheduled
+-- across OS threads.
getErrno :: IO Errno
-- We must call a C function to get the value of errno in general. On
-- threaded systems, errno is hidden behind a C macro so that each OS
--- thread gets its own copy.
+-- thread gets its own copy (`saved_errno`, which `rts/Schedule.c` restores
+-- back into the thread-local `errno` when a Haskell thread is rescheduled).
getErrno = do e <- get_errno; return (Errno e)
foreign import ccall unsafe "HsBase.h __hscore_get_errno" get_errno :: IO CInt