another test, to help with locking exercises
This commit is contained in:
parent
4bc900e78b
commit
7797a38423
3 changed files with 47 additions and 5 deletions
|
@ -55,8 +55,9 @@ kfree(void *pa)
|
|||
// Fill with junk to catch dangling refs.
|
||||
memset(pa, 1, PGSIZE);
|
||||
|
||||
acquire(&kmem.lock);
|
||||
r = (struct run*)pa;
|
||||
|
||||
acquire(&kmem.lock);
|
||||
r->next = kmem.freelist;
|
||||
kmem.freelist = r;
|
||||
release(&kmem.lock);
|
||||
|
@ -75,6 +76,7 @@ kalloc(void)
|
|||
if(r)
|
||||
kmem.freelist = r->next;
|
||||
release(&kmem.lock);
|
||||
|
||||
if(r)
|
||||
memset((char*)r, 5, PGSIZE); // fill with junk
|
||||
return (void*)r;
|
||||
|
|
|
@ -25,7 +25,7 @@ acquire(struct spinlock *lk)
|
|||
if(holding(lk))
|
||||
panic("acquire");
|
||||
|
||||
// On RISC-V, this turns into an atomic swap:
|
||||
// On RISC-V, sync_lock_test_and_set turns into an atomic swap:
|
||||
// a5 = 1
|
||||
// s1 = &lk->locked
|
||||
// amoswap.w.aq a5, a5, (s1)
|
||||
|
@ -57,9 +57,10 @@ release(struct spinlock *lk)
|
|||
__sync_synchronize();
|
||||
|
||||
// Release the lock, equivalent to lk->locked = 0.
|
||||
// This code can't use a C assignment, since it might
|
||||
// not be atomic.
|
||||
// On RISC-V, this turns into an atomic swap:
|
||||
// This code doesn't use a C assignment, since the C standard
|
||||
// implies that an assignment might be implemented with
|
||||
// multiple store instructions.
|
||||
// On RISC-V, sync_lock_release turns into an atomic swap:
|
||||
// s1 = &lk->locked
|
||||
// amoswap.w zero, zero, (s1)
|
||||
__sync_lock_release(&lk->locked);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue