diff options
author | Ian Moffett <ian@osmora.org> | 2025-04-17 02:58:20 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-04-17 02:58:20 -0400 |
commit | e30fcbe3822ab740cef6ff2584dd0a1429ab10a5 (patch) | |
tree | e43512298ed3375d0dd701f02f8f9ccdf489ef51 /sys/kern/kern_synch.c | |
parent | 53c172acbb921adfc28bea1cabf8ac983c7ecebd (diff) |
kernel: synch: Add system-wide locking
Add system-wide locking for critical code sections.
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/kern/kern_synch.c')
-rw-r--r-- | sys/kern/kern_synch.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 2b64673..57b27d0 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -38,6 +38,9 @@ #define pr_trace(fmt, ...) kprintf("synch: " fmt, ##__VA_ARGS__) #define pr_error(...) pr_trace(__VA_ARGS__) +/* XXX: Be very careful with this */ +static struct spinlock __syslock; + /* * Returns 0 on success, returns non-zero value * on timeout/failure. @@ -110,3 +113,26 @@ spinlock_release(struct spinlock *lock) { __atomic_clear(&lock->lock, __ATOMIC_RELEASE); } + +/* + * Attempt to hold the system-wide lock, returns 1 + * if already held. + * + * XXX: Only use for CRITICAL code sections. + */ +int +syslock(void) +{ + return spinlock_try_acquire(&__syslock); +} + +/* + * Release the system-wide lock + * + * XXX: Only use for CRITICAL code sections. + */ +void +sysrel(void) +{ + spinlock_release(&__syslock); +} |