SafeHaskell: Added SafeHaskell to base
[packages/base.git] / Foreign / Concurrent.hs
1 {-# LANGUAGE Trustworthy #-}
2 {-# LANGUAGE CPP, NoImplicitPrelude #-}
3
4 -----------------------------------------------------------------------------
5 -- |
6 -- Module : Foreign.Concurrent
7 -- Copyright : (c) The University of Glasgow 2003
8 -- License : BSD-style (see the file libraries/base/LICENSE)
9 --
10 -- Maintainer : ffi@haskell.org
11 -- Stability : provisional
12 -- Portability : non-portable (requires concurrency)
13 --
14 -- FFI datatypes and operations that use or require concurrency (GHC only).
15 --
16 -----------------------------------------------------------------------------
17
18 module Foreign.Concurrent
19 (
20 -- * Concurrency-based 'ForeignPtr' operations
21
22 -- | These functions generalize their namesakes in the portable
23 -- "Foreign.ForeignPtr" module by allowing arbitrary 'IO' actions
24 -- as finalizers. These finalizers necessarily run in a separate
25 -- thread, cf. /Destructors, Finalizers and Synchronization/,
26 -- by Hans Boehm, /POPL/, 2003.
27
28 newForeignPtr,
29 addForeignPtrFinalizer,
30 ) where
31
32 #ifdef __GLASGOW_HASKELL__
33 import GHC.IO ( IO )
34 import GHC.Ptr ( Ptr )
35 import GHC.ForeignPtr ( ForeignPtr )
36 import qualified GHC.ForeignPtr
37
38 newForeignPtr :: Ptr a -> IO () -> IO (ForeignPtr a)
39 -- ^Turns a plain memory reference into a foreign object by associating
40 -- a finalizer - given by the monadic operation - with the reference.
41 -- The finalizer will be executed after the last reference to the
42 -- foreign object is dropped. There is no guarantee of promptness, and
43 -- in fact there is no guarantee that the finalizer will eventually
44 -- run at all.
45 newForeignPtr = GHC.ForeignPtr.newConcForeignPtr
46
47 addForeignPtrFinalizer :: ForeignPtr a -> IO () -> IO ()
48 -- ^This function adds a finalizer to the given 'ForeignPtr'.
49 -- The finalizer will run after the last reference to the foreign object
50 -- is dropped, but /before/ all previously registered finalizers for the
51 -- same object.
52 addForeignPtrFinalizer = GHC.ForeignPtr.addForeignPtrConcFinalizer
53 #endif
54