26#define LOCK_DEADLOCK_ITERATIONS 10000000
31#define LOCK_CANARY 0xDEADBEEF
58#define LOCK_SCOPE(lock) \
59 __attribute__((cleanup(lock_cleanup))) lock_t* CONCAT(l, __COUNTER__) = (lock); \
69#define LOCK_CREATE() {.nextTicket = ATOMIC_VAR_INIT(0), .nowServing = ATOMIC_VAR_INIT(0), .canary = LOCK_CANARY}
71#define LOCK_CREATE() {.nextTicket = ATOMIC_VAR_INIT(0), .nowServing = ATOMIC_VAR_INIT(0)}
119 panic(
NULL,
"Lock canary corrupted after %d iterations", iterations);
static void cli_pop(void)
Decrements the CLI depth, re-enabling interrupts if depth reaches zero and interrupts were enabled pr...
static void cli_push(void)
Increments the CLI depth, disabling interrupts if depth was zero.
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
static void lock_init(lock_t *lock)
Initializes a lock.
static bool lock_try_acquire(lock_t *lock)
Tries to acquire a lock.
static void lock_cleanup(lock_t **lock)
static void lock_release(lock_t *lock)
Releases a lock.
#define LOCK_DEADLOCK_ITERATIONS
Number of iterations before we consider a deadlock to have occurred in lock_acquire....
static void lock_acquire(lock_t *lock)
Acquires a lock, blocking until it is available.
#define LOCK_CANARY
Lock canary value to detect memory corruption.
#define ASM(...)
Inline assembly macro.
#define NULL
Pointer error value.
#define atomic_fetch_add_explicit(object, operand, order)
#define atomic_compare_exchange_strong_explicit(object, expected, desired, success, failure)
#define atomic_load_explicit(object, order)
#define atomic_thread_fence(order)
#define atomic_init(obj, value)
__UINTPTR_TYPE__ uintptr_t
A simple ticket lock implementation.
atomic_uint16_t nextTicket
atomic_uint16_t nowServing