-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Shared memory and control structures for IPC -- -- Provides portable shared memory allocator and semaphores. Can be used -- for interprocess communication. Refer to README.md for further -- information. @package interprocess @version 0.1.0.0 -- | Exposed internals of SharedObjectName. module Foreign.SharedObjectName.Internal -- | Reference to a shared object; can be sent to other processes. newtype SOName a SOName :: (ForeignPtr CChar) -> SOName a -- | Write a shared object name into somwhere referenced by a handle. -- Useful for sending references to other processes via pipes. hPutSOName :: Handle -> SOName a -> IO () -- | Read a shared object name from somwhere referenced by a handle. -- Returns Nothing if hGetBuf gets less than -- 32 bytes. Useful for sending references to other processes -- via pipes. hGetSOName :: Handle -> IO (Maybe (SOName a)) -- | Use a pointer to a C string to pass to some low-level (e.g. foreign) -- functions. SOName is asserted immutable, so do not modify it! unsafeWithSOName :: SOName a -> (CString -> IO b) -> IO b -- | Generate a new unique shared object name. genSOName :: IO (SOName a) -- | Allocate a new shared object name. newEmptySOName :: IO (SOName a) instance GHC.Show.Show (Foreign.SharedObjectName.Internal.SOName a) instance GHC.Classes.Eq (Foreign.SharedObjectName.Internal.SOName a) instance GHC.Classes.Ord (Foreign.SharedObjectName.Internal.SOName a) instance Foreign.Storable.Storable (Foreign.SharedObjectName.Internal.SOName a) -- | Globally unique names to be used as references in the interprocess -- communication. -- -- The implementation must guarantee that no two processes can generate -- the same unique SOName independently at the same time. To -- ensure this, the implementation uses three different seeds: -- --
    --
  1. C rand() with a time-dependent seed -- srand(time(NULL))
  2. --
  3. Process id taken from getpid or -- GetCurrentProcessId (unique across process).
  4. --
  5. A global auto-incremented variable (unique within a process).
  6. --
module Foreign.SharedObjectName -- | Reference to a shared object; can be sent to other processes. data SOName a -- | Write a shared object name into somwhere referenced by a handle. -- Useful for sending references to other processes via pipes. hPutSOName :: Handle -> SOName a -> IO () -- | Read a shared object name from somwhere referenced by a handle. -- Returns Nothing if hGetBuf gets less than -- 32 bytes. Useful for sending references to other processes -- via pipes. hGetSOName :: Handle -> IO (Maybe (SOName a)) -- | Use a pointer to a C string to pass to some low-level (e.g. foreign) -- functions. SOName is asserted immutable, so do not modify it! unsafeWithSOName :: SOName a -> (CString -> IO b) -> IO b -- | Simple interprocess quantity semaphores -- -- Based on POSIX or Win32 C semaphores module Control.Concurrent.Process.QSem -- | QSem is a quantity semaphore in which the resource is aqcuired -- and released in units of one. data QSem -- | Build a new QSem with a supplied initial quantity. The initial -- quantity must be at least 0. -- -- This function throws an exception if an underlying platform-dependent -- function fails. newQSem :: Int -> IO QSem -- | Lookup QSem by its name in the global namespace. Use this function to -- init several entangled semaphores in different processes. -- -- This function throws an exception if no QSem with this name -- exist, or if an underlying platform-dependent function fails. lookupQSem :: SOName QSem -> IO QSem -- | Wait for a unit to become available -- -- This function throws an exception if an underlying platform-dependent -- function fails. waitQSem :: QSem -> IO () -- | Try to take a unit of the QSem. -- -- This function does not wait, in fact. Sorry for naming. -- -- Returns: -- -- -- -- This function does not throw an exception. tryWaitQSem :: QSem -> IO Bool -- | Signal that a unit of the QSem is available -- -- This function throws an exception if an underlying platform-dependent -- function fails. signalQSem :: QSem -> IO () -- | Get a global reference to the semaphore. Send this reference to -- another process to lookup this semaphore and start interprocess -- communication. qSemName :: QSem -> SOName QSem module Foreign.SharedPtr.C -- | Special pointer format to pass between memory spaces of processes. data SharedPtr a -- | Opaque pointer to the allocator type defined in C code. type Allocator = Ptr AllocatorT c'shared_createAllocator :: IO Allocator c'shared_lookupAllocator :: CString -> IO Allocator c'shared_destroyAllocator :: Allocator -> IO () c'shared_getStoreName :: Allocator -> CString c'shared_ptrToShPtr :: Allocator -> Ptr a -> SharedPtr a c'shared_shPtrToPtr :: Allocator -> SharedPtr a -> Ptr a c'shared_malloc :: Allocator -> CSize -> IO (Ptr a) c'shared_realloc :: Allocator -> Ptr a -> CSize -> IO (Ptr a) c'shared_free :: Allocator -> Ptr a -> IO () p'shared_createAllocator :: FunPtr (IO Allocator) p'shared_lookupAllocator :: FunPtr (CString -> IO Allocator) p'shared_destroyAllocator :: FunPtr (Allocator -> IO ()) p'shared_getStoreName :: FunPtr (Allocator -> CString) p'shared_ptrToShPtr :: FunPtr (Allocator -> Ptr a -> SharedPtr a) p'shared_shPtrToPtr :: FunPtr (Allocator -> SharedPtr a -> Ptr a) p'shared_malloc :: FunPtr (Allocator -> CSize -> IO (Ptr a)) p'shared_realloc :: FunPtr (Allocator -> Ptr a -> CSize -> IO (Ptr a)) p'shared_free :: FunPtr (Allocator -> Ptr a -> IO ()) instance Foreign.Storable.Storable (Foreign.SharedPtr.C.SharedPtr a) instance GHC.Generics.Generic (Foreign.SharedPtr.C.SharedPtr a) instance Data.Data.Data a => Data.Data.Data (Foreign.SharedPtr.C.SharedPtr a) instance GHC.Show.Show (Foreign.SharedPtr.C.SharedPtr a) instance GHC.Classes.Ord (Foreign.SharedPtr.C.SharedPtr a) instance GHC.Classes.Eq (Foreign.SharedPtr.C.SharedPtr a) module Foreign.SharedPtr -- | Special pointer format to pass between memory spaces of processes. data SharedPtr a -- | Make a portable shared pointer out of a regular pointer. The result -- can be transfered to another process and re-created using the shared -- Allocator. toSharedPtr :: Allocator -> Ptr a -> SharedPtr a -- | Reconstruct a regular pointer from a portable shared pointer. Returns -- NULL if shared pointer or allocator are not valid. fromSharedPtr :: Allocator -> SharedPtr a -> Ptr a -- | Opaque pointer to the allocator type defined in C code. type Allocator = Ptr AllocatorT -- | Create a new Allocator. createAllocator :: IO Allocator -- | Lookup a Allocator by its name. Use this to share one allocator -- between multiple processes. lookupAllocator :: SOName Allocator -> IO Allocator -- | Destroy allocator instance. Note: memory is fully unlinked and -- released only after the last allocator sharing the memory is -- destroyed. destroyAllocator :: Allocator -> IO () withNewAllocator :: (Allocator -> IO a) -> IO a withAllocator :: SOName Allocator -> (Allocator -> IO a) -> IO a allocStoreName :: Allocator -> SOName Allocator malloc :: Storable a => Allocator -> IO (Ptr a) mallocBytes :: Allocator -> Int -> IO (Ptr a) realloc :: Allocator -> Ptr a -> Int -> IO (Ptr a) free :: Allocator -> Ptr a -> IO ()