{-# LINE 1 "src/Data/Number/Flint/ThreadPool/FFI.hsc" #-}
module Data.Number.Flint.ThreadPool.FFI (
ThreadPool (..)
, CThreadPool (..)
, ThreadPoolHandle (..)
, CThreadPoolHandle (..)
, thread_pool_init
, thread_pool_get_size
, thread_pool_set_size
, thread_pool_request
, thread_pool_wake
, thread_pool_wait
, thread_pool_give_back
, thread_pool_clear
) where
import Foreign.C.String
import Foreign.C.Types
import Foreign.ForeignPtr
import Foreign.Ptr ( Ptr, FunPtr, plusPtr )
import Foreign.Storable
import Foreign.Marshal ( free )
import Data.Number.Flint.Flint
import Data.Number.Flint.Fmpz
import Data.Number.Flint.Fmpq
data ThreadPool = ThreadPool {-# UNPACK #-} !(ForeignPtr CThreadPool)
type CThreadPool = CFlint ThreadPool
instance Storable CThreadPool where
{-# INLINE sizeOf #-}
sizeOf :: CThreadPool -> Int
sizeOf CThreadPool
_ = (Int
80)
{-# LINE 48 "src/Data/Number/Flint/ThreadPool/FFI.hsc" #-}
{-# INLINE alignment #-}
alignment :: CThreadPool -> Int
alignment CThreadPool
_ = Int
8
{-# LINE 50 "src/Data/Number/Flint/ThreadPool/FFI.hsc" #-}
peek = undefined
poke :: Ptr CThreadPool -> CThreadPool -> IO ()
poke = forall a. HasCallStack => a
undefined
newThreadPool :: CLong -> IO ThreadPool
newThreadPool CLong
size = do
ForeignPtr CThreadPool
x <- forall a. Storable a => IO (ForeignPtr a)
mallocForeignPtr
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CThreadPool
x forall a b. (a -> b) -> a -> b
$ \Ptr CThreadPool
x -> Ptr CThreadPool -> CLong -> IO ()
thread_pool_init Ptr CThreadPool
x CLong
size
forall a. FinalizerPtr a -> ForeignPtr a -> IO ()
addForeignPtrFinalizer FunPtr (Ptr CThreadPool -> IO ())
p_thread_pool_clear ForeignPtr CThreadPool
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ForeignPtr CThreadPool -> ThreadPool
ThreadPool ForeignPtr CThreadPool
x
{-# INLINE withThreadPool #-}
withThreadPool :: ThreadPool -> (Ptr CThreadPool -> IO a) -> IO (ThreadPool, a)
withThreadPool (ThreadPool ForeignPtr CThreadPool
x) Ptr CThreadPool -> IO a
f = do
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr CThreadPool
x forall a b. (a -> b) -> a -> b
$ \Ptr CThreadPool
px -> Ptr CThreadPool -> IO a
f Ptr CThreadPool
px forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ForeignPtr CThreadPool -> ThreadPool
ThreadPool ForeignPtr CThreadPool
x,)
data ThreadPoolHandle = ThreadPoolHandle {-# UNPACK #-} !(ForeignPtr CThreadPoolHandle)
type CThreadPoolHandle = CFlint ThreadPoolHandle
foreign import ccall "flint/thread_pool.h thread_pool_init"
thread_pool_init :: Ptr CThreadPool -> CLong -> IO ()
foreign import ccall "flint/thread_pool.h thread_pool_get_size"
thread_pool_get_size :: Ptr CThreadPool -> IO CLong
foreign import ccall "flint/thread_pool.h thread_pool_set_size"
thread_pool_set_size :: Ptr CThreadPool -> CLong -> IO CInt
foreign import ccall "flint/thread_pool.h thread_pool_request"
thread_pool_request :: Ptr CThreadPool -> Ptr CThreadPoolHandle -> CLong -> IO CLong
foreign import ccall "flint/thread_pool.h thread_pool_wake"
thread_pool_wake :: Ptr CThreadPool -> Ptr CThreadPoolHandle -> CInt -> FunPtr (Ptr () -> IO ()) -> Ptr () -> IO ()
foreign import ccall "flint/thread_pool.h thread_pool_wait"
thread_pool_wait :: Ptr CThreadPool -> Ptr CThreadPoolHandle -> IO ()
foreign import ccall "flint/thread_pool.h thread_pool_give_back"
thread_pool_give_back :: Ptr CThreadPool -> Ptr CThreadPoolHandle -> IO ()
foreign import ccall "flint/thread_pool.h thread_pool_clear"
thread_pool_clear :: Ptr CThreadPool -> IO ()
foreign import ccall "flint/thread_pool.h &thread_pool_clear"
p_thread_pool_clear :: FunPtr (Ptr CThreadPool -> IO ())