PatchworkOS
Loading...
Searching...
No Matches
lock.h File Reference
#include <kernel/cpu/interrupt.h>
#include <kernel/log/panic.h>
#include <kernel/defs.h>
#include <kernel/drivers/com.h>
#include <stdatomic.h>

Go to the source code of this file.

Data Structures

struct  lock_t
 A simple ticket lock implementation. More...
 

Macros

#define LOCK_DEADLOCK_ITERATIONS   1000000
 Number of iterations before we consider a deadlock has occurred in lock_acquire. This is only used in debug builds.
 
#define LOCK_CANARY   0xDEADBEEF
 Lock canary value to detect memory corruption.
 
#define LOCK_SCOPE(lock)
 Acquires a lock for the reminder of the current scope.
 
#define LOCK_CREATE   (lock_t){.nextTicket = ATOMIC_VAR_INIT(0), .nowServing = ATOMIC_VAR_INIT(0), .canary = 0xDEADBEEF}
 Create a lock initializer. @macro LOCK_CREATE.
 

Functions

static void lock_init (lock_t *lock)
 Initializes a lock.
 
static void lock_acquire (lock_t *lock)
 Acquires a lock, blocking until it is available.
 
static void lock_release (lock_t *lock)
 Releases a lock.
 
static void lock_cleanup (lock_t **lock)