|
PatchworkOS
|
Ticket spinlock. More...
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) |
Ticket spinlock.
| #define LOCK_CANARY 0xDEADBEEF |
| #define LOCK_CREATE (lock_t){.nextTicket = ATOMIC_VAR_INIT(0), .nowServing = ATOMIC_VAR_INIT(0), .canary = 0xDEADBEEF} |
| #define LOCK_DEADLOCK_ITERATIONS 1000000 |
| #define LOCK_SCOPE | ( | lock | ) |
Acquires a lock for the reminder of the current scope.
| lock | Pointer to the lock to acquire. |
|
inlinestatic |
Acquires a lock, blocking until it is available.
This function disables interrupts on the current CPU.. It is not recursive, and attempting to acquire a lock that is already held by the same CPU will result in a deadlock.
| lock | Pointer to the lock to acquire. |
Definition at line 97 of file lock.h.
References atomic_fetch_add_explicit, atomic_load_explicit, atomic_thread_fence, interrupt_disable(), interrupt_enable(), lock, LOCK_CANARY, LOCK_DEADLOCK_ITERATIONS, memory_order_acquire, memory_order_relaxed, memory_order_seq_cst, NULL, and panic().
Referenced by _heap_acquire(), local_listen_free(), local_socket_accept(), local_socket_deinit(), mutex_acquire_timeout(), note_interrupt_handler(), pipe_close(), ramfs_dentry_deinit(), sched_invoke(), sched_load_balance(), socket_family_register(), space_load(), space_mapping_start(), space_tlb_shootdown(), thread_free(), thread_init(), vmm_cpu_ctx_init_common(), vmm_shootdown_handler(), wait_block_setup(), wait_remove_wait_entries(), wait_unblock(), and wait_unblock_thread().
|
inlinestatic |
Definition at line 153 of file lock.h.
References lock, and lock_release().
|
inlinestatic |
Initializes a lock.
| lock | Pointer to the lock to initialize. |
Definition at line 80 of file lock.h.
References atomic_init, lock, and LOCK_CANARY.
Referenced by _heap_init(), futex_ctx_init(), kbd_new(), local_conn_new(), local_listen_new(), local_socket_init(), mouse_new(), mutex_init(), note_queue_init(), pipe_open(), pipe_open2(), process_init(), ramfs_mount(), rwmutex_init(), sched_cpu_ctx_init(), shmem_object_new(), space_init(), statistics_cpu_ctx_init(), timer_ctx_init(), vfs_ctx_init(), vmm_cpu_ctx_init_common(), wait_cpu_ctx_init(), and wait_queue_init().
|
inlinestatic |
Releases a lock.
This function restores the interrupt state on the current CPU to what it was before the lock was acquired.
| lock | Pointer to the lock to release. |
Definition at line 140 of file lock.h.
References atomic_fetch_add_explicit, interrupt_enable(), lock, LOCK_CANARY, memory_order_release, NULL, and panic().
Referenced by _heap_release(), local_listen_free(), local_socket_accept(), local_socket_deinit(), lock_cleanup(), mutex_acquire_timeout(), note_interrupt_handler(), pipe_close(), ramfs_dentry_deinit(), sched_invoke(), sched_load_balance(), socket_family_register(), space_load(), space_mapping_end(), space_mapping_start(), space_tlb_shootdown(), thread_free(), thread_init(), vmm_cpu_ctx_init_common(), vmm_shootdown_handler(), wait_block_setup(), wait_remove_wait_entries(), wait_unblock(), and wait_unblock_thread().