{-# language UndecidableSuperClasses #-}
{-# language ScopedTypeVariables #-}
{-# language FlexibleContexts #-}
{-# language TypeApplications #-}
{-# language ConstraintKinds #-}
{-# language TypeFamilies #-}
{-# language Trustworthy #-}
module Foreign.Const.Concurrent
( newConstForeignPtr
, addAForeignPtrFinalizer
) where
import Data.Coerce
import Data.Type.Coercion
import Foreign.Concurrent
import Data.Const.Unsafe
newConstForeignPtr :: forall p a. APtr p => p a -> IO () -> IO (ConstForeignPtr a)
newConstForeignPtr = gcoerceWith (unsafePtrCoercion @p @a) $ coerce $ newForeignPtr @a
{-# inline newConstForeignPtr #-}
addAForeignPtrFinalizer :: forall fp a. AForeignPtr fp => fp a -> IO () -> IO ()
addAForeignPtrFinalizer = gcoerceWith (unsafeForeignPtrCoercion @fp @a) $ coerce $ addForeignPtrFinalizer @a
{-# inline addAForeignPtrFinalizer #-}