25#define LOCK_DEADLOCK_ITERATIONS 10000000
30#define LOCK_CANARY 0xDEADBEEF
57#define LOCK_SCOPE(lock) \
58 __attribute__((cleanup(lock_cleanup))) lock_t* CONCAT(l, __COUNTER__) = (lock); \
68#define LOCK_CREATE() \
71 .nextTicket = ATOMIC_VAR_INIT(0), .nowServing = ATOMIC_VAR_INIT(0), .canary = LOCK_CANARY \
74#define LOCK_CREATE() \
77 .nextTicket = ATOMIC_VAR_INIT(0), .nowServing = ATOMIC_VAR_INIT(0) \
120 asm volatile(
"pause");
126 panic(
NULL,
"Lock canary corrupted after %d iterations", iterations);
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 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 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