diff options
author | stefan <stefan@s00.xyz> | 2023-04-15 05:02:02 +0000 |
---|---|---|
committer | stefan <stefan@s00.xyz> | 2023-04-15 05:02:02 +0000 |
commit | af1ce4b2e637ceb418ea72d51c49a3eee276a938 (patch) | |
tree | 4d6a33644f8489e4f582f6e320bd6581b94fb642 /sys/kern/spinlock.c | |
parent | 8cceb31dcaf4641d43f324fa3301b37859ebfade (diff) | |
download | sv-af1ce4b2e637ceb418ea72d51c49a3eee276a938.tar.gz |
added multiprocessor support
Diffstat (limited to 'sys/kern/spinlock.c')
-rw-r--r-- | sys/kern/spinlock.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/sys/kern/spinlock.c b/sys/kern/spinlock.c index a35b8ce..ade270f 100644 --- a/sys/kern/spinlock.c +++ b/sys/kern/spinlock.c @@ -1,15 +1,38 @@ +#include <asm.h> #include <spinlock.h> void -init_locklock(struct spinlock *l, const char *_name) +initlock(struct spinlock *l) { - l->name = _name; l->locked = 0; - l->cpu = 0; } void -acquire_lock(struct spinlock *l) +acquire(struct spinlock *l) { - asm volatile("csrr sie, zero"); + sie_disable(); + + if (l->locked) + return; + + while (__sync_lock_test_and_set(&l->locked, 1)) + ; + + __sync_synchronize(); +} + +void +release(struct spinlock *l) +{ + sie_disable(); // avoid deadlock + + if (l->locked) + return; // interrupts are still disabled, what to do here? + + /* fence */ + __sync_synchronize(); + + __sync_lock_release(&l->locked); + + sie_enable(); } |