File: Concurrent.hs

package info (click to toggle)
ghc-cvs 20040725-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 68,484 kB
  • ctags: 19,658
  • sloc: haskell: 251,945; ansic: 109,709; asm: 24,961; sh: 12,825; perl: 5,786; makefile: 5,334; xml: 3,884; python: 682; yacc: 650; lisp: 477; cpp: 337; ml: 76; fortran: 24; csh: 18
file content (54 lines) | stat: -rw-r--r-- 2,119 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{-# OPTIONS -fno-implicit-prelude #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Foreign.Concurrent
-- Copyright   :  (c) The University of Glasgow 2003
-- License     :  BSD-style (see the file libraries/base/LICENSE)
-- 
-- Maintainer  :  ffi@haskell.org
-- Stability   :  provisional
-- Portability :  non-portable (requires concurrency)
--
-- FFI datatypes and operations that use or require concurrency (GHC only).
--
-----------------------------------------------------------------------------

module Foreign.Concurrent
  (
	-- * Concurrency-based 'ForeignPtr' operations

	-- | These functions generalize their namesakes in the portable
	-- "Foreign.ForeignPtr" module by allowing arbitrary 'IO' actions
	-- as finalizers.  These finalizers necessarily run in a separate
	-- thread, cf. /Destructors, Finalizers and Synchronization/,
	-- by Hans Boehm, /POPL/, 2003.

	newForeignPtr,
	addForeignPtrFinalizer,
  ) where

#ifdef __GLASGOW_HASKELL__
import GHC.IOBase	( IO )
import GHC.Ptr		( Ptr )
import GHC.ForeignPtr	( ForeignPtr )
import qualified GHC.ForeignPtr
#endif

#ifdef __GLASGOW_HASKELL__
newForeignPtr :: Ptr a -> IO () -> IO (ForeignPtr a)
-- ^Turns a plain memory reference into a foreign object by associating
-- a finalizer - given by the monadic operation - with the reference.
-- The finalizer will be executed after the last reference to the
-- foreign object is dropped.  Note that there is no guarantee on how
-- soon the finalizer is executed after the last reference was dropped;
-- this depends on the details of the Haskell storage manager.  The only
-- guarantee is that the finalizer runs before the program terminates.
newForeignPtr = GHC.ForeignPtr.newConcForeignPtr

addForeignPtrFinalizer :: ForeignPtr a -> IO () -> IO ()
-- ^This function adds a finalizer to the given 'ForeignPtr'.
-- The finalizer will run after the last reference to the foreign object
-- is dropped, but /before/ all previously registered finalizers for the
-- same object.
addForeignPtrFinalizer = GHC.ForeignPtr.addForeignPtrConcFinalizer
#endif