summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Hambüchen <mail@nh2.me>2019-02-14 16:52:17 -0500
committerBen Gamari <ben@smart-cactus.org>2019-02-20 14:28:55 -0500
commitbeb7f9ba73b8cac469f15fa8ab31f1e21b4c1cb9 (patch)
tree0fdb6cab644aae1af01c4e3e7dc0357ad4fca484
parent612e7dd633f375774e89af3f072721fe4632a806 (diff)
downloadhaskell-beb7f9ba73b8cac469f15fa8ab31f1e21b4c1cb9.tar.gz
base: Document errno behaviour in haddocks.
Also add an implementation comment for details. (cherry picked from commit 76ac103f5021cba5cd000293c7cb8c2bd3148e7a)
-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