PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
lock.h File Reference
#include <kernel/cpu/cli.h>
#include <kernel/log/panic.h>
#include <kernel/drivers/com.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <sys/defs.h>
Include dependency graph for lock.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   10000000
 Number of iterations before we consider a deadlock to have 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()   {.nextTicket = ATOMIC_VAR_INIT(0), .nowServing = ATOMIC_VAR_INIT(0), .canary = LOCK_CANARY}
 Create a lock initializer.
 

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 bool lock_try_acquire (lock_t *lock)
 Tries to acquire a lock.
 
static void lock_release (lock_t *lock)
 Releases a lock.
 
static void lock_cleanup (lock_t **lock)