From: hs Date: Wed, 22 Aug 2012 17:58:17 +0000 (+0200) Subject: implemented dummy mallocBytes etc which; added cabal build system; X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=hs-boehmgc.git;a=commitdiff_plain;h=c0b90dd3b13b6c926d9f31654957715c2c63f530 implemented dummy mallocBytes etc which; added cabal build system; --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..63a0d85 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +dist/* +*.swp + diff --git a/Setup.lhs b/Setup.lhs new file mode 100644 index 0000000..3eb981e --- /dev/null +++ b/Setup.lhs @@ -0,0 +1,4 @@ +#!/usr/bin/env runhaskell + +> import Distribution.Simple +> main = defaultMain diff --git a/hs-boehmgc.cabal b/hs-boehmgc.cabal new file mode 100644 index 0000000..1c4d820 --- /dev/null +++ b/hs-boehmgc.cabal @@ -0,0 +1,15 @@ +Name: hs-boehmgc +Version: 0.1 +Synopsis: none +Description: Haskell bindings for Boehm-Demers-Weiser conservative GC used in MateVM +License: GPL-3 +Author: Harald Steinlechner, Bernhard Urban +Maintainer: Harald Steinlechner +Build-Depends: base +cabal-version: >= 1.2 +build-type: Simple + +library + build-depends: base + exposed-modules: Mate.GC.Boehm + hs-source-dirs: src diff --git a/src/Mate/GC/Boehm.hs b/src/Mate/GC/Boehm.hs new file mode 100644 index 0000000..eb5711b --- /dev/null +++ b/src/Mate/GC/Boehm.hs @@ -0,0 +1,36 @@ +{-# LANGUAGE CPP #-} +module Mate.GC.Boehm ( + mallocBytesGC, + unsafeFreeGC, + getHeapSize, + ) where + +#define DEBUG + +import Foreign.Marshal.Alloc +import Foreign.Ptr +import Data.IORef +import System.IO.Unsafe + +-- counts allocated memory in heap +{-# NOINLINE globalBytesAllocated #-} +globalBytesAllocated :: IORef Int +globalBytesAllocated = unsafePerformIO (newIORef 0) + +#ifdef DEBUG +-- |Allocates size bytes in managed memory +mallocBytesGC :: Int -> IO (Ptr a) +mallocBytesGC size = modifyIORef globalBytesAllocated (+ size) >> mallocBytes size +#else +-- |Allocates size bytes in managed memory +mallocBytesGC :: Int -> IO (Ptr a) +mallocBytesGC = mallocBytes +#endif + +-- |Explicitely deallocate an object. Not required and dangerous. +unsafeFreeGC :: Ptr a -> IO () +unsafeFreeGC _ = print "not implemented" + +-- |Returns currently allocated memory in bytes +getHeapSize :: IO Int +getHeapSize = readIORef globalBytesAllocated