1 {-# LANGUAGE CPP, NoImplicitPrelude #-}
3 -----------------------------------------------------------------------------
5 -- Module : Foreign.Concurrent
6 -- Copyright : (c) The University of Glasgow 2003
7 -- License : BSD-style (see the file libraries/base/LICENSE)
9 -- Maintainer : ffi@haskell.org
10 -- Stability : provisional
11 -- Portability : non-portable (requires concurrency)
13 -- FFI datatypes and operations that use or require concurrency (GHC only).
15 -----------------------------------------------------------------------------
17 module Foreign.Concurrent
19 -- * Concurrency-based 'ForeignPtr' operations
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.
28 addForeignPtrFinalizer,
31 #ifdef __GLASGOW_HASKELL__
33 import GHC.Ptr ( Ptr )
34 import GHC.ForeignPtr ( ForeignPtr )
35 import qualified GHC.ForeignPtr
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
46 newForeignPtr = GHC.ForeignPtr.newConcForeignPtr
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
53 addForeignPtrFinalizer = GHC.ForeignPtr.addForeignPtrConcFinalizer