X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Flib%2Fstd%2FPrelWeak.lhs;h=1a7e643ffb4160353f0dd7f56c2c0ac32c0da2f8;hb=d9af408e5c512501cfa991f5e4a76c9154bca917;hp=c1d49fbd7a2f814d0b6455e6e046373f2f3f223a;hpb=a103a9dc0de992716e62c30d7ac81c0bc0dbcdc5;p=ghc-hetmet.git diff --git a/ghc/lib/std/PrelWeak.lhs b/ghc/lib/std/PrelWeak.lhs index c1d49fb..1a7e643 100644 --- a/ghc/lib/std/PrelWeak.lhs +++ b/ghc/lib/std/PrelWeak.lhs @@ -1,21 +1,20 @@ +% ------------------------------------------------------------------------------ +% $Id: PrelWeak.lhs,v 1.16 2001/03/22 03:51:09 hwloidl Exp $ % -% (c) The AQUA Project, Glasgow University, 1998 +% (c) The University of Glasgow, 1998-2000 % \section[PrelWeak]{Module @PrelWeak@} \begin{code} -{-# OPTIONS -fcompiling-prelude -fno-implicit-prelude #-} +{-# OPTIONS -fno-implicit-prelude #-} module PrelWeak where import PrelGHC import PrelBase import PrelMaybe -import PrelIOBase -import PrelForeign - -#ifndef __PARALLEL_HASKELL__ +import PrelIOBase ( IO(..), unIO ) data Weak v = Weak (Weak# v) @@ -37,14 +36,30 @@ addFinalizer key finalizer = do mkWeakPtr key (Just finalizer) -- throw it away return () -addForeignFinalizer :: ForeignObj -> IO () -> IO () -addForeignFinalizer (ForeignObj fo) finalizer = addFinalizer fo finalizer - {- -instance Eq (Weak v) where +Instance Eq (Weak v) where (Weak w1) == (Weak w2) = w1 `sameWeak#` w2 -} -#endif + +-- run a batch of finalizers from the garbage collector. We're given +-- an array of finalizers and the length of the array, and we just +-- call each one in turn. +-- +-- the IO primitives are inlined by hand here to get the optimal +-- code (sigh) --SDM. + +runFinalizerBatch :: Int -> Array# (IO ()) -> IO () +runFinalizerBatch (I# n) arr = + let go m = IO $ \s -> + case m of + 0# -> (# s, () #) + _ -> let m' = m -# 1# in + case indexArray# arr m' of { (# io #) -> + case unIO io s of { (# s, _ #) -> + unIO (go m') s + }} + in + go n \end{code}