{-# LANGUAGE FlexibleInstances, FlexibleContexts, TypeFamilies, MultiParamTypeClasses, OverlappingInstances, IncoherentInstances #-} module HROOT.Core.TMutex.Cast where import Foreign.Ptr import FFICXX.Runtime.Cast import System.IO.Unsafe import HROOT.Core.TMutex.RawType import HROOT.Core.TMutex.Interface instance (ITMutex a, FPtr a) => Castable (a) (Ptr RawTMutex) where cast :: forall r. a -> (Ptr RawTMutex -> IO r) -> IO r cast a x Ptr RawTMutex -> IO r f = Ptr RawTMutex -> IO r f (Ptr (Raw a) -> Ptr RawTMutex forall a b. Ptr a -> Ptr b castPtr (a -> Ptr (Raw a) forall a. FPtr a => a -> Ptr (Raw a) get_fptr a x)) uncast :: forall r. Ptr RawTMutex -> (a -> IO r) -> IO r uncast Ptr RawTMutex x a -> IO r f = a -> IO r f (Ptr (Raw a) -> a forall a. FPtr a => Ptr (Raw a) -> a cast_fptr_to_obj (Ptr RawTMutex -> Ptr (Raw a) forall a b. Ptr a -> Ptr b castPtr Ptr RawTMutex x)) instance () => Castable (TMutex) (Ptr RawTMutex) where cast :: forall r. TMutex -> (Ptr RawTMutex -> IO r) -> IO r cast TMutex x Ptr RawTMutex -> IO r f = Ptr RawTMutex -> IO r f (Ptr RawTMutex -> Ptr RawTMutex forall a b. Ptr a -> Ptr b castPtr (TMutex -> Ptr (Raw TMutex) forall a. FPtr a => a -> Ptr (Raw a) get_fptr TMutex x)) uncast :: forall r. Ptr RawTMutex -> (TMutex -> IO r) -> IO r uncast Ptr RawTMutex x TMutex -> IO r f = TMutex -> IO r f (Ptr (Raw TMutex) -> TMutex forall a. FPtr a => Ptr (Raw a) -> a cast_fptr_to_obj (Ptr RawTMutex -> Ptr RawTMutex forall a b. Ptr a -> Ptr b castPtr Ptr RawTMutex x))