KallistiOS git master
Independent SDK for the Sega Dreamcast
|
Simple locking. More...
Go to the source code of this file.
Macros | |
#define | SPINLOCK_INITIALIZER 0 |
Spinlock initializer. | |
#define | spinlock_lock_scoped(lock) |
Spin on a lock with scope management. | |
Typedefs | |
typedef volatile int | spinlock_t |
Spinlock data type. | |
Functions | |
static void | spinlock_init (spinlock_t *lock) |
Initialize a spinlock. | |
static bool | spinlock_trylock (spinlock_t *lock) |
Try to lock, without spinning. | |
static void | spinlock_lock (spinlock_t *lock) |
Spin on a lock. | |
static bool | spinlock_lock_irqsafe (spinlock_t *lock) |
Spin on a lock. | |
static void | spinlock_unlock (spinlock_t *lock) |
Free a lock. | |
static bool | spinlock_is_locked (spinlock_t *lock) |
Determine if a lock is locked. | |
Simple locking.
This file contains definitions for very simple locks. Most of the time, you will probably not use such low-level locking, but will opt for something more fully featured like mutexes, semaphores, reader-writer semaphores, or recursive locks.
#define SPINLOCK_INITIALIZER 0 |
Spinlock initializer.
All created spinlocks should be initialized with this initializer so that they are in a sane state, ready to be used.
Referenced by spinlock_init().
#define spinlock_lock_scoped | ( | lock | ) |
Spin on a lock with scope management.
This macro will spin on the lock, similar to spinlock_lock(), with the difference that the lock will automatically be freed once the execution exits the functional block in which the macro was called.
lock | A pointer to the spinlock to be locked. |
typedef volatile int spinlock_t |
Spinlock data type.
|
inlinestatic |
Initialize a spinlock.
This function abstracts initializing a spinlock, in case the initializer is not applicable to what you are doing.
lock | A pointer to the spinlock to be initialized. |
References SPINLOCK_INITIALIZER.
|
inlinestatic |
Determine if a lock is locked.
This function will return whether or not the lock specified is actually locked when it is called. This is NOT a thread-safe way of determining if a lock will be locked when you get around to locking it!
lock | A pointer to the spinlock to be checked. |
|
inlinestatic |
Spin on a lock.
This function will spin on the lock, and will not return until the lock has been obtained for the calling thread.
lock | A pointer to the spinlock to be locked. |
References spinlock_trylock(), and thd_pass().
Referenced by spinlock_lock_irqsafe().
|
inlinestatic |
Spin on a lock.
This function will spin on the lock, and will not return until the lock has been obtained for the calling thread, unless it is called from within an interrupt context.
lock | A pointer to the spinlock to be locked. |
References irq_inside_int(), spinlock_lock(), and spinlock_trylock().
|
inlinestatic |
Try to lock, without spinning.
This function will attempt to lock the lock, but will not spin. Instead, it will return whether the lock was obtained or not.
lock | A pointer to the spinlock to be locked. |
Referenced by spinlock_lock(), and spinlock_lock_irqsafe().
|
inlinestatic |
Free a lock.
This function will unlock the lock that is currently held by the calling thread. Do not use this function unless you actually hold the lock!
lock | A pointer to the spinlock to be unlocked. |