25#define LOCK_DEADLOCK_ITERATIONS 1000000
30#define LOCK_CANARY 0xDEADBEEF
57#define LOCK_SCOPE(lock) \
58 __attribute__((cleanup(lock_cleanup))) lock_t* CONCAT(l, __COUNTER__) = (lock); \
66#define LOCK_CREATE (lock_t){.nextTicket = ATOMIC_VAR_INIT(0), .nowServing = ATOMIC_VAR_INIT(0), .canary = 0xDEADBEEF}
71 .nextTicket = ATOMIC_VAR_INIT(0), .nowServing = ATOMIC_VAR_INIT(0) \
114 asm volatile(
"pause");
120 panic(
NULL,
"Lock canary corrupted after %d iterations", iterations);
125 panic(
NULL,
"Deadlock detected in lock last acquired from %p", (
void*)
lock->calledFrom);
void interrupt_disable(void)
Disable interrupts and increment the disableDepth.
void interrupt_enable(void)
Decrement the CLI depth and enable interrupts if depth reaches zero and interrupts were previously en...
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 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 has occurred in lock_acquire. This is only used in...
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 NULL
Pointer error value.
#define atomic_fetch_add_explicit(object, operand, order)
#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