Skip to content

Fix 'semTrywait: invalid argument (Bad file descriptor)' wrt #218 #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions System/Posix/Semaphore.hsc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE Safe #-}
{-# LANGUAGE CApiFFI #-}
-----------------------------------------------------------------------------
-- |
-- Module : System.Posix.Semaphore
Expand Down Expand Up @@ -110,18 +111,18 @@ semGetValue_ sem ptr = do throwErrnoIfMinus1Retry_ "semGetValue" $
cint <- peek ptr
return $ fromEnum cint

foreign import ccall safe "sem_open"
foreign import capi safe "semaphore.h sem_open"
sem_open :: CString -> CInt -> CMode -> CUInt -> IO (Ptr ())
foreign import ccall safe "sem_close"
foreign import capi safe "semaphore.h sem_close"
sem_close :: Ptr () -> IO CInt
foreign import ccall safe "sem_unlink"
foreign import capi safe "semaphore.h sem_unlink"
sem_unlink :: CString -> IO CInt

foreign import ccall safe "sem_wait"
foreign import capi safe "semaphore.h sem_wait"
sem_wait :: Ptr () -> IO CInt
foreign import ccall safe "sem_trywait"
foreign import capi safe "semaphore.h sem_trywait"
sem_trywait :: Ptr () -> IO CInt
foreign import ccall safe "sem_post"
foreign import capi safe "semaphore.h sem_post"
sem_post :: Ptr () -> IO CInt
foreign import ccall safe "sem_getvalue"
foreign import capi safe "semaphore.h sem_getvalue"
sem_getvalue :: Ptr () -> Ptr CInt -> IO Int
2 changes: 2 additions & 0 deletions test-wasm32-wasi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import util from "util";
const my_execFile = util.promisify(child_process.execFile);
let warns_count = 0;
for (const f of await fs.promises.readdir("tests")) {
// odd linker errors
if (f === "Semaphore001.hs") continue;
// Find self-contained test cases (aka doesn't rely on tasty)
if (!f.endsWith(".hs")) continue;
const s = await fs.promises.readFile(`tests/${f}`, "utf-8");
Expand Down
9 changes: 9 additions & 0 deletions tests/Semaphore001.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Main (main) where

import System.Posix

main :: IO ()
main = do
sem <- semOpen "/test" OpenSemFlags {semCreate = True, semExclusive = False} stdFileMode 1
semThreadWait sem
semPost sem
8 changes: 8 additions & 0 deletions unix.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,11 @@ test-suite PutEnv001
default-language: Haskell2010
build-depends: base, unix, tasty, tasty-hunit
ghc-options: -Wall -with-rtsopts=-V0 -O0

test-suite Semaphore001
hs-source-dirs: tests
main-is: Semaphore001.hs
type: exitcode-stdio-1.0
default-language: Haskell2010
build-depends: base, unix
ghc-options: -Wall