diff options
-rw-r--r-- | sys/include/sys/spinlock.h | 3 | ||||
-rw-r--r-- | sys/kern/kern_synch.c | 26 |
2 files changed, 29 insertions, 0 deletions
diff --git a/sys/include/sys/spinlock.h b/sys/include/sys/spinlock.h index b416152..140addc 100644 --- a/sys/include/sys/spinlock.h +++ b/sys/include/sys/spinlock.h @@ -44,6 +44,9 @@ void spinlock_release(struct spinlock *lock); int spinlock_try_acquire(struct spinlock *lock); int spinlock_usleep(struct spinlock *lock, size_t usec_max); +/* System-wide locking (be careful!!) */ +int syslock(void); +void sysrel(void); #endif #endif /* !_SYS_SPINLOCK_H_ */ 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); +} |