| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
SDL3.Sys.Bindgen.Mutex
Synopsis
- data SDL_Mutex
- data SDL_RWLock
- data SDL_Semaphore
- data SDL_Condition
- newtype SDL_InitStatus = SDL_InitStatus {}
- pattern SDL_INIT_STATUS_UNINITIALIZED :: SDL_InitStatus
- pattern SDL_INIT_STATUS_INITIALIZING :: SDL_InitStatus
- pattern SDL_INIT_STATUS_INITIALIZED :: SDL_InitStatus
- pattern SDL_INIT_STATUS_UNINITIALIZING :: SDL_InitStatus
- data SDL_InitState = SDL_InitState {
- status :: SDL_AtomicInt
- thread :: SDL_ThreadID
- reserved :: Ptr Void
Documentation
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
- C declaration
struct SDL_Mutex, defined atSDL3/SDL_mutex.h 296:16
Since: 3.2.0
data SDL_RWLock Source #
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.
- C declaration
struct SDL_RWLock, defined atSDL3/SDL_mutex.h 438:16
Since: 3.2.0
data SDL_Semaphore Source #
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))
- C declaration
struct SDL_Semaphore, defined atSDL3/SDL_mutex.h 684:16
Since: 3.2.0
data SDL_Condition Source #
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
- C declaration
struct SDL_Condition, defined atSDL3/SDL_mutex.h 841:16
Since: 3.2.0
newtype SDL_InitStatus Source #
The current status of an SDL_InitState structure.
- C declaration
enum SDL_InitStatus, defined atSDL3/SDL_mutex.h 975:14
Since: 3.2.0
Constructors
| SDL_InitStatus | |
Instances
pattern SDL_INIT_STATUS_UNINITIALIZED :: SDL_InitStatus Source #
- C declaration
SDL_INIT_STATUS_UNINITIALIZED, defined atSDL3/SDL_mutex.h 977:5
pattern SDL_INIT_STATUS_INITIALIZING :: SDL_InitStatus Source #
- C declaration
SDL_INIT_STATUS_INITIALIZING, defined atSDL3/SDL_mutex.h 978:5
pattern SDL_INIT_STATUS_INITIALIZED :: SDL_InitStatus Source #
- C declaration
SDL_INIT_STATUS_INITIALIZED, defined atSDL3/SDL_mutex.h 979:5
pattern SDL_INIT_STATUS_UNINITIALIZING :: SDL_InitStatus Source #
- C declaration
SDL_INIT_STATUS_UNINITIALIZING, defined atSDL3/SDL_mutex.h 980:5
data SDL_InitState Source #
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.
- C declaration
struct SDL_InitState, defined atSDL3/SDL_mutex.h 1039:16
Since: 3.2.0
Constructors
| SDL_InitState | |
Fields
| |
Instances
| Storable SDL_InitState Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex Methods sizeOf :: SDL_InitState -> Int # alignment :: SDL_InitState -> Int # peekElemOff :: Ptr SDL_InitState -> Int -> IO SDL_InitState # pokeElemOff :: Ptr SDL_InitState -> Int -> SDL_InitState -> IO () # peekByteOff :: Ptr b -> Int -> IO SDL_InitState # pokeByteOff :: Ptr b -> Int -> SDL_InitState -> IO () # peek :: Ptr SDL_InitState -> IO SDL_InitState # poke :: Ptr SDL_InitState -> SDL_InitState -> IO () # | |||||
| Generic SDL_InitState Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex Associated Types
| |||||
| Show SDL_InitState Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex Methods showsPrec :: Int -> SDL_InitState -> ShowS # show :: SDL_InitState -> String # showList :: [SDL_InitState] -> ShowS # | |||||
| Eq SDL_InitState Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex Methods (==) :: SDL_InitState -> SDL_InitState -> Bool # (/=) :: SDL_InitState -> SDL_InitState -> Bool # | |||||
| ReadRaw SDL_InitState Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex Methods readRaw :: Ptr SDL_InitState -> IO SDL_InitState # | |||||
| StaticSize SDL_InitState Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex | |||||
| WriteRaw SDL_InitState Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex Methods writeRaw :: Ptr SDL_InitState -> SDL_InitState -> IO () # | |||||
| IsStruct SDL_InitState Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex Methods zero :: SDL_InitState # | |||||
| HasCField SDL_InitState "reserved" Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex Associated Types
| |||||
| HasCField SDL_InitState "status" Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex Associated Types
| |||||
| HasCField SDL_InitState "thread" Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex Associated Types
| |||||
| ty ~ Ptr Void => HasField "reserved" SDL_InitState ty Source # |
| ||||
Defined in SDL3.Sys.Bindgen.Mutex Methods hasField :: SDL_InitState -> (ty -> SDL_InitState, ty) # | |||||
| ty ~ SDL_AtomicInt => HasField "status" SDL_InitState ty Source # |
| ||||
Defined in SDL3.Sys.Bindgen.Mutex Methods hasField :: SDL_InitState -> (ty -> SDL_InitState, ty) # | |||||
| ty ~ SDL_ThreadID => HasField "thread" SDL_InitState ty Source # |
| ||||
Defined in SDL3.Sys.Bindgen.Mutex Methods hasField :: SDL_InitState -> (ty -> SDL_InitState, ty) # | |||||
| ty ~ Ptr Void => HasField "reserved" (Ptr SDL_InitState) (Ptr ty :: Type) Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex Methods getField :: Ptr SDL_InitState -> Ptr ty # | |||||
| ty ~ SDL_AtomicInt => HasField "status" (Ptr SDL_InitState) (Ptr ty :: Type) Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex Methods getField :: Ptr SDL_InitState -> Ptr ty # | |||||
| ty ~ SDL_ThreadID => HasField "thread" (Ptr SDL_InitState) (Ptr ty :: Type) Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex Methods getField :: Ptr SDL_InitState -> Ptr ty # | |||||
| type Rep SDL_InitState Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex type Rep SDL_InitState = D1 ('MetaData "SDL_InitState" "SDL3.Sys.Bindgen.Mutex" "sdl3-bindgen-sys-0.0.1.0-inplace" 'False) (C1 ('MetaCons "SDL_InitState" 'PrefixI 'True) (S1 ('MetaSel ('Just "status") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 SDL_AtomicInt) :*: (S1 ('MetaSel ('Just "thread") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 SDL_ThreadID) :*: S1 ('MetaSel ('Just "reserved") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 (Ptr Void))))) | |||||
| type CFieldType SDL_InitState "reserved" Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex | |||||
| type CFieldType SDL_InitState "status" Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex | |||||
| type CFieldType SDL_InitState "thread" Source # | |||||
Defined in SDL3.Sys.Bindgen.Mutex | |||||