SaturnRingLibrary 0.9.2
SGL wrapper
Loading...
Searching...
No Matches

◆ TestAndSetSemaphore()

uint32_t SRL::System::TestAndSetSemaphore ( uint32_t semaphore)
inlinestatic

Atomically test and set a system semaphore.

Parameters
semaphoreSemaphore number to test and set
Returns
Previous value: 0 if the semaphore was free (now acquired), non-zero if it was already held

Calls the BIOS entry at 0x6000330. Internally uses the SH-2 TAS.B (Test And Set) instruction for atomic read-modify-write.

Warning
Many emulators (including Mednafen) do not correctly emulate the TAS.B instruction's bus cycle. This function may return incorrect results in emulated environments.
Example:
// Semaphore acquired - critical section
}
static void ClearSemaphore(uint32_t semaphore)
Release a system semaphore.
Definition srl_system.hpp:240
static uint32_t TestAndSetSemaphore(uint32_t semaphore)
Atomically test and set a system semaphore.
Definition srl_system.hpp:228
See also
ClearSemaphore()