SpinLock is a mechanism that uses the ARM processor swp
command to perform exclusion control among threads and processors.
Mutex and Message can also be used to perform exclusion control among threads, but unlike those mechanisms, spin lock does not cause thread switching when locked. Instead, it loops, waiting for the locks to become unlocked.
CAUTION: There are no reference materials for OS_InitLock()
. GamePak access exclusion control between processors Card access exclusion control between processors VRAM C and VRAM D access exclusion control between processors Synchronization between processors at initialization ( OS_InitLock()
)
This page describes the synchronization processing functions that use these NitroSDK spin locks.
Initializing a Spin Lock Used by the SDK
OS_InitLock()
performs the initialization for spin locks used by the SDK. However, since this is called from inside OS_Init()
, there is no need to call it with the application if OS_Init()
is called.
OS_InitLock()
also performs the process for synchronizing with the OS_InitLock()
on other processors.
CAUTION: There are no reference materials for OS_InitLock()
.
Card Access Exclusion Control
Generally, ARM7 has Game Card access privileges. Calling OS_LockCard()
gives access privileges to ARM9, and locks out access from ARM7.
Calling OS_UnlockCard()
returns the access privileges to ARM7 and removes the lock.
OS_LockCard()
does not return from the function until there is a lock, but OS_TryLockCard()
only attempts the lock once. The return value indicates whether or not the lock was successful.
GamePak Access Exclusion Control
Generally, ARM7 has Game Pak access privileges. Calling OS_LockCartridge()
gives access privileges. to ARM9 and locks out access from ARM7.
Calling OS_UnlockCartridge()
returns the access privileges to ARM7 and removes the lock.
OS_LockCartridge()
does not return from the function until there is a lock, but OS_TryLockCartridge()
only attempts the lock once and returns immediately. The return value indicates whether or not the lock was successful.
ID Used in the Lock Function
When the ID used in the lock (a u16
value) attempts to access the same resources between threads or between processors (cards, GamePaks, etc.), they must have different values. The following functions are configured to use these lock IDs in the NitroSDK.
OS_GetLockID()
returns a value that is not in use from among the ID candidates available on ARM9. This value guarantees that there is no conflict with other modules regardless of whether it is on ARM9 or ARM7. However, one of the conditions is that other modules are also using OS_GetLockID()
to obtain values. OS_GetLockID()
is also used in places that need it inside the NitroSDK, so there is no overlap with the values if the application performs the configuration.
Once an ID is no longer in use, unlock it with OS_ReleaseLockID()
. By calling this function, the specified ID is returned to the OS_GetLockID()
candidates and can be used in other locks from any subsequent OS_GetLockID()
.
The values that can be obtained with OS_GetLockID()
range from 0x40 - 0x6F
.
The same function is also in the ARM7-side library, and can obtain values from 0x80 - 0xA0
.
Overview of OS Functions (Exclusion Control)
12/14/2004 Corrected typos
11/15/2004 Initial version