-
Notifications
You must be signed in to change notification settings - Fork 13
Signals
This section explains how to create and manage Signals.
A Signal is a Kernel-Level object used to notify one or multiple waiting Threads.
It internally contains a Value which is either fplSignalValue_Set or fplSignalValue_Unset.
When this value gets changed, all Threads which wait on that Signal will wake up.
They can be shared across process boundaries and may be used as standalone locks to shared data, but the number of Signals is limited by the OS that can be allocated at a time.
See Synchronization methods for a comparison with the other synchronization primitives.
Call fplSignalInit() with a pointer to fplSignalHandle as an argument, to initialize a Signal.
Also, you need to specify if the Signal starts as fplSignalValue_Set or fplSignalValue_Unset as a second argument.
When you are done with that Signal, you need to call fplSignalDestroy() to release its internal resources.
mutex;
// Initialize a Signal as "unset"
if (!(&mutex, )) {
// Error: Signal failed initializing -> Too many active Signals
}
// ... Signal is not required anymore
(&mutex);Call fplSignalWaitForOne() with a pointer to fplSignalHandle and a fplTimeoutValue argument, to let the current thread wait until the Signal is set.
// Wait until the Signal is set
(thread, );
// ... or
// Wait at max for 5 seconds or until the Signal is set
(thread, 5000);Call fplSignalWaitForAny() to let the current thread wait until at least one Signal is set.
Example, default signal handle array:
**signals; // Signals array already initialized
// Wait until one of the Signal is set
(signals, numOfSignals, sizeof( *), );
// ... or
// Wait at max for 5 seconds or until one of the Signal is set
(signals, numOfSignals, sizeof( *), 5000);Example, custom struct with stored signal handle:
typedef struct MyCustomStruct {
int a;
void *ptr;
*signal;
short b;
} MyCustomStruct;
MyCustomStruct *customSignals; // Struct array already initialized
*firstPointerToSignal = &customSignals[0].signal;
// Wait until one of the Signal is set
(firstPointerToSignal, numOfSignals, sizeof(MyCustomStruct), );
// ... or
// Wait at max for 5 seconds or until one of the Signal is set
(firstPointerToSignal, numOfSignals, sizeof(MyCustomStruct), 5000);Call fplSignalWaitForAll() to let the current thread wait until all Signals are set.
Example, default signal handle array:
**signals; // Signals array already initialized
// Wait until all of the Signals are set
(signals, numOfSignals, sizeof( *), );
// ... or
// Wait at max for 5 seconds or until all of the Signal are set
(signals, numOfSignals, sizeof( *), 5000);Example, custom struct with stored signal handle:
typedef struct MyCustomStruct {
int a;
void *ptr;
*signal;
short b;
} MyCustomStruct;
MyCustomStruct *customSignals; // Struct array already initialized
*firstPointerToSignal = &customSignals[0].signal;
// Wait until all of the Signals are set
(firstPointerToSignal, numOfSignals, sizeof(MyCustomStruct), );
// ... or
// Wait at max for 5 seconds or until all of the Signal are set
(firstPointerToSignal, numOfSignals, sizeof(MyCustomStruct), 5000);Call fplSignalSet() with a pointer to fplSignalHandle as an argument, to set a Signal and wakeup all waiting Threads.
Note: Unlike
fplConditionVariable , setting a Signal is not Thread-Safe so you should ensure that only one thread at a time will set it!
// Use a mutex or another synchronization method to ensure that only one thread can set the Signal
(&mutex);
(signal);
(&mutex);Call fplSignalReset() with a pointer to fplSignalHandle as an argument, to reset a Signal.
Note: Unlike
fplConditionVariable , resetting a Signal is not Thread-Safe so you should ensure that only one thread at a time will set it!
// Use a mutex or another synchronization method to ensure that only one thread can reset the Signal
(&mutex);
(signal);
(&mutex);- Assertion & Debug
- Atomic operations
- Audio functions
- Clipboard functions
- Console functions
- Constants
- Display/Monitor functions
- Dynamic library loading
- Error Handling
- Files/IO functions
- Function macros
- Hardware Infos
- Input types and functions
- Localization functions
- Logging
- Memory Macros
- Memory functions
- Operating system Infos
- Path functions
- Platform functions
- Session Infos
- Settings & Configurations
- Storage class identifiers
- String functions
- Threading and synchronizations routines
- Timing functions
- Video functions
- Window events
- Window functions
- fplARMCPUCapabilities
- fplAudioChannelMap
- fplAudioDeviceID
- fplAudioDeviceInfo
- fplAudioFormat
- fplAudioSettings
- fplColor32
- fplConditionVariable
- fplConsoleSettings
- fplCPUCapabilities
- fplCPUIDLeaf
- fplDateTime
- fplDateTimeCreationResult
- fplDateTimeResult
- fplDisplayInfo
- fplDisplayMode
- fplDynamicLibraryHandle
- fplEndianess
- fplEvent
- fplFileEntry
- fplFileHandle
- fplFilePermissions
- fplFileTimeStamps
- fplGamepadButton
- fplGamepadData
- fplGamepadEvent
- fplGamepadInfo
- fplGamepadInputBinding
- fplGamepadMapping
- fplGamepadSettings
- fplGamepadState
- fplGamepadStates
- fplGraphicsApiSettings
- fplImageSource
- fplInputBackendMask
- fplInputBackendSupport
- fplInputDevice
- fplInputDeviceGuid
- fplInputSettings
- fplInternalConditionVariable
- fplInternalDynamicLibraryHandle
- fplInternalFileEntryHandle
- fplInternalFileHandle
- fplInternalFileRootInfo
- fplInternalMutexHandle
- fplInternalSemaphoreHandle
- fplInternalSignalHandle
- fplInternalThreadHandle
- fplKeyboardEvent
- fplKeyboardState
- fplLogSettings
- fplLogWriter
- fplLogWriterConsole
- fplLogWriterCustom
- fplMemoryAllocationSettings
- fplMemoryBlock
- fplMemoryInfos
- fplMemorySettings
- fplMouseEvent
- fplMouseState
- fplMutexHandle
- fplOpenGLSettings
- fplOSVersionInfos
- fplSemaphoreHandle
- fplSettings
- fplSignalHandle
- fplSpecificAudioSettings
- fplThreadHandle
- fplThreadParameters
- fplTimestamp
- fplVersionInfo
- fplVideoBackBuffer
- fplVideoRect
- fplVideoRequirements
- fplVideoRequirementsVulkan
- fplVideoSettings
- fplVideoSurface
- fplVideoSurfaceOpenGL
- fplVideoSurfaceVulkan
- fplVideoWindow
- fplVulkanSettings
- fplWindowCallbacks
- fplWindowDropFiles
- fplWindowEvent
- fplWindowPosition
- fplWindowSettings
- fplWindowSize
- fplX86CPUCapabilities