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