{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE NoFieldSelectors #-}
{-# LANGUAGE NoImplicitPrelude #-}

module SDL3.Sys.Bindgen.Mutex (
  SDL3.Sys.Bindgen.Mutex.SDL_Mutex,
  SDL3.Sys.Bindgen.Mutex.SDL_RWLock,
  SDL3.Sys.Bindgen.Mutex.SDL_Semaphore,
  SDL3.Sys.Bindgen.Mutex.SDL_Condition,
  SDL3.Sys.Bindgen.Mutex.SDL_InitStatus (..),
  pattern SDL3.Sys.Bindgen.Mutex.SDL_INIT_STATUS_UNINITIALIZED,
  pattern SDL3.Sys.Bindgen.Mutex.SDL_INIT_STATUS_INITIALIZING,
  pattern SDL3.Sys.Bindgen.Mutex.SDL_INIT_STATUS_INITIALIZED,
  pattern SDL3.Sys.Bindgen.Mutex.SDL_INIT_STATUS_UNINITIALIZING,
  SDL3.Sys.Bindgen.Mutex.SDL_InitState (..),
)
where

import Prelude (Eq, Int, Ord, Read, Show, pure, (<*>), (>>), type (~))

import HsBindgen.Runtime.CEnum qualified as CEnum
import HsBindgen.Runtime.HasCField qualified as HasCField
import HsBindgen.Runtime.Marshal qualified as Marshal
import HsBindgen.Runtime.Struct qualified as Struct
import HsBindgen.Runtime.Support qualified as BG
import HsBindgen.Runtime.Support.CompatHasField qualified as BG.CompatHasField
import SDL3.Sys.Bindgen.Atomic qualified
import SDL3.Sys.Bindgen.Thread qualified

-- | A means to serialize access to a resource between threads.
--
--     Mutexes (short for \"mutual exclusion\") are a synchronization primitive that allows exactly one thread to proceed at a time.
--
--     Wikipedia has a thorough explanation of the concept:
--
--     [https:\/\/en.wikipedia.org\/wiki\/Mutex](https://en.wikipedia.org/wiki/Mutex)
--
--     @since 3.2.0
--
--     [C declaration]: @struct SDL_Mutex@, defined at @SDL3\/SDL_mutex.h 296:16@
data SDL_Mutex

-- | A mutex that allows read-only threads to run in parallel.
--
--     A rwlock is roughly the same concept as 'SDL_Mutex', but allows threads that request read-only access to all hold the lock at the same time. If a thread requests write access, it will block until all read-only threads have released the lock, and no one else can hold the thread (for reading or writing) at the same time as the writing thread.
--
--     This can be more efficient in cases where several threads need to access data frequently, but changes to that data are rare.
--
--     There are other rules that apply to rwlocks that don\'t apply to mutexes, about how threads are scheduled and when they can be recursively locked. These are documented in the other rwlock functions.
--
--     @since 3.2.0
--
--     [C declaration]: @struct SDL_RWLock@, defined at @SDL3\/SDL_mutex.h 438:16@
data SDL_RWLock

-- | A means to manage access to a resource, by count, between threads.
--
--     Semaphores (specifically, \"counting semaphores\"), let X number of threads request access at the same time, each thread granted access decrementing a counter. When the counter reaches zero, future requests block until a prior thread releases their request, incrementing the counter again.
--
--     Wikipedia has a thorough explanation of the concept:
--
--     [https:\/\/en.wikipedia.org\/wiki\/Semaphore_(programming)](https://en.wikipedia.org/wiki/Semaphore_(programming))
--
--     @since 3.2.0
--
--     [C declaration]: @struct SDL_Semaphore@, defined at @SDL3\/SDL_mutex.h 684:16@
data SDL_Semaphore

-- | A means to block multiple threads until a condition is satisfied.
--
--     Condition variables, paired with an 'SDL_Mutex', let an app halt multiple threads until a condition has occurred, at which time the app can release one or all waiting threads.
--
--     Wikipedia has a thorough explanation of the concept:
--
--     [https:\/\/en.wikipedia.org\/wiki\/Condition_variable](https://en.wikipedia.org/wiki/Condition_variable)
--
--     @since 3.2.0
--
--     [C declaration]: @struct SDL_Condition@, defined at @SDL3\/SDL_mutex.h 841:16@
data SDL_Condition

-- | The current status of an 'SDL_InitState' structure.
--
--     @since 3.2.0
--
--     [C declaration]: @enum SDL_InitStatus@, defined at @SDL3\/SDL_mutex.h 975:14@
newtype SDL_InitStatus = SDL_InitStatus
  { SDL_InitStatus -> CUInt
unwrap :: BG.CUInt
  }
  deriving stock ((forall x. SDL_InitStatus -> Rep SDL_InitStatus x)
-> (forall x. Rep SDL_InitStatus x -> SDL_InitStatus)
-> Generic SDL_InitStatus
forall x. Rep SDL_InitStatus x -> SDL_InitStatus
forall x. SDL_InitStatus -> Rep SDL_InitStatus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SDL_InitStatus -> Rep SDL_InitStatus x
from :: forall x. SDL_InitStatus -> Rep SDL_InitStatus x
$cto :: forall x. Rep SDL_InitStatus x -> SDL_InitStatus
to :: forall x. Rep SDL_InitStatus x -> SDL_InitStatus
BG.Generic, SDL_InitStatus -> SDL_InitStatus -> Bool
(SDL_InitStatus -> SDL_InitStatus -> Bool)
-> (SDL_InitStatus -> SDL_InitStatus -> Bool) -> Eq SDL_InitStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SDL_InitStatus -> SDL_InitStatus -> Bool
== :: SDL_InitStatus -> SDL_InitStatus -> Bool
$c/= :: SDL_InitStatus -> SDL_InitStatus -> Bool
/= :: SDL_InitStatus -> SDL_InitStatus -> Bool
Eq, Eq SDL_InitStatus
Eq SDL_InitStatus =>
(SDL_InitStatus -> SDL_InitStatus -> Ordering)
-> (SDL_InitStatus -> SDL_InitStatus -> Bool)
-> (SDL_InitStatus -> SDL_InitStatus -> Bool)
-> (SDL_InitStatus -> SDL_InitStatus -> Bool)
-> (SDL_InitStatus -> SDL_InitStatus -> Bool)
-> (SDL_InitStatus -> SDL_InitStatus -> SDL_InitStatus)
-> (SDL_InitStatus -> SDL_InitStatus -> SDL_InitStatus)
-> Ord SDL_InitStatus
SDL_InitStatus -> SDL_InitStatus -> Bool
SDL_InitStatus -> SDL_InitStatus -> Ordering
SDL_InitStatus -> SDL_InitStatus -> SDL_InitStatus
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SDL_InitStatus -> SDL_InitStatus -> Ordering
compare :: SDL_InitStatus -> SDL_InitStatus -> Ordering
$c< :: SDL_InitStatus -> SDL_InitStatus -> Bool
< :: SDL_InitStatus -> SDL_InitStatus -> Bool
$c<= :: SDL_InitStatus -> SDL_InitStatus -> Bool
<= :: SDL_InitStatus -> SDL_InitStatus -> Bool
$c> :: SDL_InitStatus -> SDL_InitStatus -> Bool
> :: SDL_InitStatus -> SDL_InitStatus -> Bool
$c>= :: SDL_InitStatus -> SDL_InitStatus -> Bool
>= :: SDL_InitStatus -> SDL_InitStatus -> Bool
$cmax :: SDL_InitStatus -> SDL_InitStatus -> SDL_InitStatus
max :: SDL_InitStatus -> SDL_InitStatus -> SDL_InitStatus
$cmin :: SDL_InitStatus -> SDL_InitStatus -> SDL_InitStatus
min :: SDL_InitStatus -> SDL_InitStatus -> SDL_InitStatus
Ord)
  deriving newtype (FFIType SDL_InitStatus -> SDL_InitStatus
SDL_InitStatus -> FFIType SDL_InitStatus
(SDL_InitStatus -> FFIType SDL_InitStatus)
-> (FFIType SDL_InitStatus -> SDL_InitStatus)
-> HasFFIType SDL_InitStatus
forall a. (a -> FFIType a) -> (FFIType a -> a) -> HasFFIType a
$ctoFFIType :: SDL_InitStatus -> FFIType SDL_InitStatus
toFFIType :: SDL_InitStatus -> FFIType SDL_InitStatus
$cfromFFIType :: FFIType SDL_InitStatus -> SDL_InitStatus
fromFFIType :: FFIType SDL_InitStatus -> SDL_InitStatus
BG.HasFFIType)

instance Marshal.StaticSize SDL_InitStatus where
  staticSizeOf :: Proxy SDL_InitStatus -> Int
staticSizeOf = \Proxy SDL_InitStatus
_ -> (Int
4 :: Int)

  staticAlignment :: Proxy SDL_InitStatus -> Int
staticAlignment = \Proxy SDL_InitStatus
_ -> (Int
4 :: Int)

instance Marshal.ReadRaw SDL_InitStatus where
  readRaw :: Ptr SDL_InitStatus -> IO SDL_InitStatus
readRaw =
    \Ptr SDL_InitStatus
ptr0 ->
      (CUInt -> SDL_InitStatus) -> IO (CUInt -> SDL_InitStatus)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CUInt -> SDL_InitStatus
SDL_InitStatus
        IO (CUInt -> SDL_InitStatus) -> IO CUInt -> IO SDL_InitStatus
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Ptr SDL_InitStatus -> Int -> IO CUInt
forall a b. ReadRaw a => Ptr b -> Int -> IO a
Marshal.readRawByteOff Ptr SDL_InitStatus
ptr0 (Int
0 :: Int)

instance Marshal.WriteRaw SDL_InitStatus where
  writeRaw :: Ptr SDL_InitStatus -> SDL_InitStatus -> IO ()
writeRaw =
    \Ptr SDL_InitStatus
ptr0 ->
      \SDL_InitStatus
s1 ->
        case SDL_InitStatus
s1 of
          SDL_InitStatus CUInt
unwrap2 ->
            Ptr SDL_InitStatus -> Int -> CUInt -> IO ()
forall a b. WriteRaw a => Ptr b -> Int -> a -> IO ()
Marshal.writeRawByteOff Ptr SDL_InitStatus
ptr0 (Int
0 :: Int) CUInt
unwrap2

deriving via Marshal.EquivStorable SDL_InitStatus instance BG.Storable SDL_InitStatus

deriving via BG.CUInt instance BG.Prim SDL_InitStatus

instance CEnum.CEnum SDL_InitStatus where
  type CEnumZ SDL_InitStatus = BG.CUInt

  toCEnum :: CEnumZ SDL_InitStatus -> SDL_InitStatus
toCEnum = CUInt -> SDL_InitStatus
CEnumZ SDL_InitStatus -> SDL_InitStatus
SDL_InitStatus

  fromCEnum :: SDL_InitStatus -> CEnumZ SDL_InitStatus
fromCEnum = forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"unwrap"

  declaredValues :: forall (proxy :: * -> *).
proxy SDL_InitStatus -> DeclaredValues SDL_InitStatus
declaredValues =
    \proxy SDL_InitStatus
_ ->
      [(CEnumZ SDL_InitStatus, NonEmpty String)]
-> DeclaredValues SDL_InitStatus
forall a.
Ord (CEnumZ a) =>
[(CEnumZ a, NonEmpty String)] -> DeclaredValues a
CEnum.declaredValuesFromList
        [ (CUInt
CEnumZ SDL_InitStatus
0, String -> NonEmpty String
forall a. a -> NonEmpty a
BG.singleton String
"SDL_INIT_STATUS_UNINITIALIZED")
        , (CUInt
CEnumZ SDL_InitStatus
1, String -> NonEmpty String
forall a. a -> NonEmpty a
BG.singleton String
"SDL_INIT_STATUS_INITIALIZING")
        , (CUInt
CEnumZ SDL_InitStatus
2, String -> NonEmpty String
forall a. a -> NonEmpty a
BG.singleton String
"SDL_INIT_STATUS_INITIALIZED")
        , (CUInt
CEnumZ SDL_InitStatus
3, String -> NonEmpty String
forall a. a -> NonEmpty a
BG.singleton String
"SDL_INIT_STATUS_UNINITIALIZING")
        ]

  showsUndeclared :: forall (proxy :: * -> *).
proxy SDL_InitStatus -> Int -> CEnumZ SDL_InitStatus -> ShowS
showsUndeclared =
    String
-> proxy SDL_InitStatus -> Int -> CEnumZ SDL_InitStatus -> ShowS
forall a (proxy :: * -> *).
Show (CEnumZ a) =>
String -> proxy a -> Int -> CEnumZ a -> ShowS
CEnum.showsWrappedUndeclared String
"SDL_InitStatus"

  readPrecUndeclared :: ReadPrec SDL_InitStatus
readPrecUndeclared =
    String -> ReadPrec SDL_InitStatus
forall a. (CEnum a, Read (CEnumZ a)) => String -> ReadPrec a
CEnum.readPrecWrappedUndeclared String
"SDL_InitStatus"

  isDeclared :: SDL_InitStatus -> Bool
isDeclared = SDL_InitStatus -> Bool
forall a. SequentialCEnum a => a -> Bool
CEnum.seqIsDeclared

  mkDeclared :: CEnumZ SDL_InitStatus -> Maybe SDL_InitStatus
mkDeclared = CEnumZ SDL_InitStatus -> Maybe SDL_InitStatus
forall a. SequentialCEnum a => CEnumZ a -> Maybe a
CEnum.seqMkDeclared

instance CEnum.SequentialCEnum SDL_InitStatus where
  minDeclaredValue :: SDL_InitStatus
minDeclaredValue = SDL_InitStatus
SDL_INIT_STATUS_UNINITIALIZED

  maxDeclaredValue :: SDL_InitStatus
maxDeclaredValue = SDL_InitStatus
SDL_INIT_STATUS_UNINITIALIZING

instance Show SDL_InitStatus where
  showsPrec :: Int -> SDL_InitStatus -> ShowS
showsPrec = Int -> SDL_InitStatus -> ShowS
forall a. CEnum a => Int -> a -> ShowS
CEnum.shows

instance Read SDL_InitStatus where
  readPrec :: ReadPrec SDL_InitStatus
readPrec = ReadPrec SDL_InitStatus
forall a. CEnum a => ReadPrec a
CEnum.readPrec

  readList :: ReadS [SDL_InitStatus]
readList = ReadS [SDL_InitStatus]
forall a. Read a => ReadS [a]
BG.readListDefault

  readListPrec :: ReadPrec [SDL_InitStatus]
readListPrec = ReadPrec [SDL_InitStatus]
forall a. Read a => ReadPrec [a]
BG.readListPrecDefault

instance
  (ty ~ BG.CUInt)
  => BG.CompatHasField.HasField "unwrap" SDL_InitStatus ty
  where
  hasField :: SDL_InitStatus -> (ty -> SDL_InitStatus, ty)
hasField =
    \SDL_InitStatus
x0 ->
      ( \ty
y1 ->
          SDL_InitStatus{unwrap :: CUInt
unwrap = ty
CUInt
y1}
      , forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"unwrap" SDL_InitStatus
x0
      )

instance
  (ty ~ BG.CUInt)
  => BG.HasField "unwrap" (BG.Ptr SDL_InitStatus) (BG.Ptr ty)
  where
  getField :: Ptr SDL_InitStatus -> Ptr ty
getField = Proxy "unwrap"
-> Ptr SDL_InitStatus -> Ptr (CFieldType SDL_InitStatus "unwrap")
forall a (field :: Symbol).
HasCField a field =>
Proxy field -> Ptr a -> Ptr (CFieldType a field)
HasCField.fromPtr (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"unwrap")

instance HasCField.HasCField SDL_InitStatus "unwrap" where
  type CFieldType SDL_InitStatus "unwrap" = BG.CUInt

  offset# :: Proxy# SDL_InitStatus -> Proxy# "unwrap" -> Int
offset# = \Proxy# SDL_InitStatus
_ -> \Proxy# "unwrap"
_ -> Int
0

-- | [C declaration]: @SDL_INIT_STATUS_UNINITIALIZED@, defined at @SDL3\/SDL_mutex.h 977:5@
pattern SDL_INIT_STATUS_UNINITIALIZED :: SDL_InitStatus
pattern $mSDL_INIT_STATUS_UNINITIALIZED :: forall {r}. SDL_InitStatus -> ((# #) -> r) -> ((# #) -> r) -> r
$bSDL_INIT_STATUS_UNINITIALIZED :: SDL_InitStatus
SDL_INIT_STATUS_UNINITIALIZED = SDL_InitStatus 0

-- | [C declaration]: @SDL_INIT_STATUS_INITIALIZING@, defined at @SDL3\/SDL_mutex.h 978:5@
pattern SDL_INIT_STATUS_INITIALIZING :: SDL_InitStatus
pattern $mSDL_INIT_STATUS_INITIALIZING :: forall {r}. SDL_InitStatus -> ((# #) -> r) -> ((# #) -> r) -> r
$bSDL_INIT_STATUS_INITIALIZING :: SDL_InitStatus
SDL_INIT_STATUS_INITIALIZING = SDL_InitStatus 1

-- | [C declaration]: @SDL_INIT_STATUS_INITIALIZED@, defined at @SDL3\/SDL_mutex.h 979:5@
pattern SDL_INIT_STATUS_INITIALIZED :: SDL_InitStatus
pattern $mSDL_INIT_STATUS_INITIALIZED :: forall {r}. SDL_InitStatus -> ((# #) -> r) -> ((# #) -> r) -> r
$bSDL_INIT_STATUS_INITIALIZED :: SDL_InitStatus
SDL_INIT_STATUS_INITIALIZED = SDL_InitStatus 2

-- | [C declaration]: @SDL_INIT_STATUS_UNINITIALIZING@, defined at @SDL3\/SDL_mutex.h 980:5@
pattern SDL_INIT_STATUS_UNINITIALIZING :: SDL_InitStatus
pattern $mSDL_INIT_STATUS_UNINITIALIZING :: forall {r}. SDL_InitStatus -> ((# #) -> r) -> ((# #) -> r) -> r
$bSDL_INIT_STATUS_UNINITIALIZING :: SDL_InitStatus
SDL_INIT_STATUS_UNINITIALIZING = SDL_InitStatus 3

-- | A structure used for thread-safe initialization and shutdown.
--
--     Here is an example of using this:
--
--     @
--     static SDL_InitState init;
--
--     bool InitSystem(void)
--     {
--         if (!SDL_ShouldInit(&init)) {
--             \/\/ The system is initialized
--             return true;
--         }
--
--         \/\/ At this point, you should not leave this function without calling SDL_SetInitialized()
--
--         bool initialized = DoInitTasks();
--         SDL_SetInitialized(&init, initialized);
--         return initialized;
--     }
--
--     bool UseSubsystem(void)
--     {
--         if (SDL_ShouldInit(&init)) {
--             \/\/ Error, the subsystem isn\'t initialized
--             SDL_SetInitialized(&init, false);
--             return false;
--         }
--
--         \/\/ Do work using the initialized subsystem
--
--         return true;
--     }
--
--     void QuitSystem(void)
--     {
--         if (!SDL_ShouldQuit(&init)) {
--             \/\/ The system is not initialized
--             return;
--         }
--
--         \/\/ At this point, you should not leave this function without calling SDL_SetInitialized()
--
--         DoQuitTasks();
--         SDL_SetInitialized(&init, false);
--     }
--     @
--
--     Note that this doesn\'t protect any resources created during initialization, or guarantee that nobody is using those resources during cleanup. You should use other mechanisms to protect those, if that\'s a concern for your code.
--
--     @since 3.2.0
--
--     [C declaration]: @struct SDL_InitState@, defined at @SDL3\/SDL_mutex.h 1039:16@
data SDL_InitState = SDL_InitState
  { SDL_InitState -> SDL_AtomicInt
status :: SDL3.Sys.Bindgen.Atomic.SDL_AtomicInt
  -- ^ [C declaration]: @status@, defined at @SDL3\/SDL_mutex.h 1041:19@
  , SDL_InitState -> SDL_ThreadID
thread :: SDL3.Sys.Bindgen.Thread.SDL_ThreadID
  -- ^ [C declaration]: @thread@, defined at @SDL3\/SDL_mutex.h 1042:18@
  , SDL_InitState -> Ptr Void
reserved :: BG.Ptr BG.Void
  -- ^ [C declaration]: @reserved@, defined at @SDL3\/SDL_mutex.h 1043:11@
  }
  deriving stock ((forall x. SDL_InitState -> Rep SDL_InitState x)
-> (forall x. Rep SDL_InitState x -> SDL_InitState)
-> Generic SDL_InitState
forall x. Rep SDL_InitState x -> SDL_InitState
forall x. SDL_InitState -> Rep SDL_InitState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SDL_InitState -> Rep SDL_InitState x
from :: forall x. SDL_InitState -> Rep SDL_InitState x
$cto :: forall x. Rep SDL_InitState x -> SDL_InitState
to :: forall x. Rep SDL_InitState x -> SDL_InitState
BG.Generic, SDL_InitState -> SDL_InitState -> Bool
(SDL_InitState -> SDL_InitState -> Bool)
-> (SDL_InitState -> SDL_InitState -> Bool) -> Eq SDL_InitState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SDL_InitState -> SDL_InitState -> Bool
== :: SDL_InitState -> SDL_InitState -> Bool
$c/= :: SDL_InitState -> SDL_InitState -> Bool
/= :: SDL_InitState -> SDL_InitState -> Bool
Eq, Int -> SDL_InitState -> ShowS
[SDL_InitState] -> ShowS
SDL_InitState -> String
(Int -> SDL_InitState -> ShowS)
-> (SDL_InitState -> String)
-> ([SDL_InitState] -> ShowS)
-> Show SDL_InitState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SDL_InitState -> ShowS
showsPrec :: Int -> SDL_InitState -> ShowS
$cshow :: SDL_InitState -> String
show :: SDL_InitState -> String
$cshowList :: [SDL_InitState] -> ShowS
showList :: [SDL_InitState] -> ShowS
Show)

instance Marshal.StaticSize SDL_InitState where
  staticSizeOf :: Proxy SDL_InitState -> Int
staticSizeOf = \Proxy SDL_InitState
_ -> (Int
24 :: Int)

  staticAlignment :: Proxy SDL_InitState -> Int
staticAlignment = \Proxy SDL_InitState
_ -> (Int
8 :: Int)

instance Marshal.ReadRaw SDL_InitState where
  readRaw :: Ptr SDL_InitState -> IO SDL_InitState
readRaw =
    \Ptr SDL_InitState
ptr0 ->
      (SDL_AtomicInt -> SDL_ThreadID -> Ptr Void -> SDL_InitState)
-> IO (SDL_AtomicInt -> SDL_ThreadID -> Ptr Void -> SDL_InitState)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SDL_AtomicInt -> SDL_ThreadID -> Ptr Void -> SDL_InitState
SDL_InitState
        IO (SDL_AtomicInt -> SDL_ThreadID -> Ptr Void -> SDL_InitState)
-> IO SDL_AtomicInt
-> IO (SDL_ThreadID -> Ptr Void -> SDL_InitState)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Proxy "status"
-> Ptr SDL_InitState -> IO (CFieldType SDL_InitState "status")
forall a (field :: Symbol).
(HasCField a field, ReadRaw (CFieldType a field)) =>
Proxy field -> Ptr a -> IO (CFieldType a field)
HasCField.readRaw (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"status") Ptr SDL_InitState
ptr0
        IO (SDL_ThreadID -> Ptr Void -> SDL_InitState)
-> IO SDL_ThreadID -> IO (Ptr Void -> SDL_InitState)
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Proxy "thread"
-> Ptr SDL_InitState -> IO (CFieldType SDL_InitState "thread")
forall a (field :: Symbol).
(HasCField a field, ReadRaw (CFieldType a field)) =>
Proxy field -> Ptr a -> IO (CFieldType a field)
HasCField.readRaw (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"thread") Ptr SDL_InitState
ptr0
        IO (Ptr Void -> SDL_InitState) -> IO (Ptr Void) -> IO SDL_InitState
forall a b. IO (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Proxy "reserved"
-> Ptr SDL_InitState -> IO (CFieldType SDL_InitState "reserved")
forall a (field :: Symbol).
(HasCField a field, ReadRaw (CFieldType a field)) =>
Proxy field -> Ptr a -> IO (CFieldType a field)
HasCField.readRaw (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"reserved") Ptr SDL_InitState
ptr0

instance Marshal.WriteRaw SDL_InitState where
  writeRaw :: Ptr SDL_InitState -> SDL_InitState -> IO ()
writeRaw =
    \Ptr SDL_InitState
ptr0 ->
      \SDL_InitState
s1 ->
        case SDL_InitState
s1 of
          SDL_InitState SDL_AtomicInt
status2 SDL_ThreadID
thread3 Ptr Void
reserved4 ->
            Proxy "status"
-> Ptr SDL_InitState -> CFieldType SDL_InitState "status" -> IO ()
forall a (field :: Symbol).
(HasCField a field, WriteRaw (CFieldType a field)) =>
Proxy field -> Ptr a -> CFieldType a field -> IO ()
HasCField.writeRaw (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"status") Ptr SDL_InitState
ptr0 CFieldType SDL_InitState "status"
SDL_AtomicInt
status2
              IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Proxy "thread"
-> Ptr SDL_InitState -> CFieldType SDL_InitState "thread" -> IO ()
forall a (field :: Symbol).
(HasCField a field, WriteRaw (CFieldType a field)) =>
Proxy field -> Ptr a -> CFieldType a field -> IO ()
HasCField.writeRaw (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"thread") Ptr SDL_InitState
ptr0 CFieldType SDL_InitState "thread"
SDL_ThreadID
thread3
              IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Proxy "reserved"
-> Ptr SDL_InitState
-> CFieldType SDL_InitState "reserved"
-> IO ()
forall a (field :: Symbol).
(HasCField a field, WriteRaw (CFieldType a field)) =>
Proxy field -> Ptr a -> CFieldType a field -> IO ()
HasCField.writeRaw (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"reserved") Ptr SDL_InitState
ptr0 Ptr Void
CFieldType SDL_InitState "reserved"
reserved4

deriving via Marshal.EquivStorable SDL_InitState instance BG.Storable SDL_InitState

deriving via Struct.IsStructViaReadRaw SDL_InitState instance Struct.IsStruct SDL_InitState

-- | [C declaration]: @status@, defined at @SDL3\/SDL_mutex.h 1041:19@
instance
  (ty ~ SDL3.Sys.Bindgen.Atomic.SDL_AtomicInt)
  => BG.CompatHasField.HasField "status" SDL_InitState ty
  where
  hasField :: SDL_InitState -> (ty -> SDL_InitState, ty)
hasField =
    \SDL_InitState
x0 ->
      ( \ty
y1 ->
          SDL_InitState
            { status :: SDL_AtomicInt
status = ty
SDL_AtomicInt
y1
            , thread :: SDL_ThreadID
thread = forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"thread" SDL_InitState
x0
            , reserved :: Ptr Void
reserved = forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"reserved" SDL_InitState
x0
            }
      , forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"status" SDL_InitState
x0
      )

instance
  (ty ~ SDL3.Sys.Bindgen.Atomic.SDL_AtomicInt)
  => BG.HasField "status" (BG.Ptr SDL_InitState) (BG.Ptr ty)
  where
  getField :: Ptr SDL_InitState -> Ptr ty
getField = Proxy "status"
-> Ptr SDL_InitState -> Ptr (CFieldType SDL_InitState "status")
forall a (field :: Symbol).
HasCField a field =>
Proxy field -> Ptr a -> Ptr (CFieldType a field)
HasCField.fromPtr (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"status")

instance HasCField.HasCField SDL_InitState "status" where
  type
    CFieldType SDL_InitState "status" =
      SDL3.Sys.Bindgen.Atomic.SDL_AtomicInt

  offset# :: Proxy# SDL_InitState -> Proxy# "status" -> Int
offset# = \Proxy# SDL_InitState
_ -> \Proxy# "status"
_ -> Int
0

-- | [C declaration]: @thread@, defined at @SDL3\/SDL_mutex.h 1042:18@
instance
  (ty ~ SDL3.Sys.Bindgen.Thread.SDL_ThreadID)
  => BG.CompatHasField.HasField "thread" SDL_InitState ty
  where
  hasField :: SDL_InitState -> (ty -> SDL_InitState, ty)
hasField =
    \SDL_InitState
x0 ->
      ( \ty
y1 ->
          SDL_InitState
            { thread :: SDL_ThreadID
thread = ty
SDL_ThreadID
y1
            , status :: SDL_AtomicInt
status = forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"status" SDL_InitState
x0
            , reserved :: Ptr Void
reserved = forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"reserved" SDL_InitState
x0
            }
      , forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"thread" SDL_InitState
x0
      )

instance
  (ty ~ SDL3.Sys.Bindgen.Thread.SDL_ThreadID)
  => BG.HasField "thread" (BG.Ptr SDL_InitState) (BG.Ptr ty)
  where
  getField :: Ptr SDL_InitState -> Ptr ty
getField = Proxy "thread"
-> Ptr SDL_InitState -> Ptr (CFieldType SDL_InitState "thread")
forall a (field :: Symbol).
HasCField a field =>
Proxy field -> Ptr a -> Ptr (CFieldType a field)
HasCField.fromPtr (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"thread")

instance HasCField.HasCField SDL_InitState "thread" where
  type
    CFieldType SDL_InitState "thread" =
      SDL3.Sys.Bindgen.Thread.SDL_ThreadID

  offset# :: Proxy# SDL_InitState -> Proxy# "thread" -> Int
offset# = \Proxy# SDL_InitState
_ -> \Proxy# "thread"
_ -> Int
8

-- | [C declaration]: @reserved@, defined at @SDL3\/SDL_mutex.h 1043:11@
instance
  (ty ~ BG.Ptr BG.Void)
  => BG.CompatHasField.HasField "reserved" SDL_InitState ty
  where
  hasField :: SDL_InitState -> (ty -> SDL_InitState, ty)
hasField =
    \SDL_InitState
x0 ->
      ( \ty
y1 ->
          SDL_InitState
            { reserved :: Ptr Void
reserved = ty
Ptr Void
y1
            , status :: SDL_AtomicInt
status = forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"status" SDL_InitState
x0
            , thread :: SDL_ThreadID
thread = forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"thread" SDL_InitState
x0
            }
      , forall {k} (x :: k) r a. HasField x r a => r -> a
forall (x :: Symbol) r a. HasField x r a => r -> a
BG.getField @"reserved" SDL_InitState
x0
      )

instance
  (ty ~ BG.Ptr BG.Void)
  => BG.HasField "reserved" (BG.Ptr SDL_InitState) (BG.Ptr ty)
  where
  getField :: Ptr SDL_InitState -> Ptr ty
getField = Proxy "reserved"
-> Ptr SDL_InitState -> Ptr (CFieldType SDL_InitState "reserved")
forall a (field :: Symbol).
HasCField a field =>
Proxy field -> Ptr a -> Ptr (CFieldType a field)
HasCField.fromPtr (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
BG.Proxy @"reserved")

instance HasCField.HasCField SDL_InitState "reserved" where
  type
    CFieldType SDL_InitState "reserved" =
      BG.Ptr BG.Void

  offset# :: Proxy# SDL_InitState -> Proxy# "reserved" -> Int
offset# = \Proxy# SDL_InitState
_ -> \Proxy# "reserved"
_ -> Int
16