ref: cae437ccbbb8859686eb1a5a37e598624026befa
parent: 8a9740a385460c91c2791182170b78980d417bd8
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Dec 10 16:34:25 EST 2023
blk: more asserts on what we enqueue
--- a/blk.c
+++ b/blk.c
@@ -943,7 +943,7 @@
if(a->bp.addr != b->bp.addr)
return (a->bp.addr < b->bp.addr) ? -1 : 1;
if(a->op != b->op){
- if(a->op == Qflush)
+ if(a->op == Qfence)
return -1;
if(a->op == Qfree)
return 1;
@@ -956,6 +956,12 @@
{
int i;
+ if(qe.op == Qfree || qe.op == Qwrite)
+ assert((qe.bp.addr & (Blksz-1)) == 0);
+ else if(qe.op == Qfence)
+ assert(fs->syncing > 0);
+ else
+ abort();
qlock(&q->lk);
qe.qgen = agetv(&fs->qgen);
while(q->nheap == q->heapsz)
@@ -1022,7 +1028,8 @@
q = p;
while(1){
qe = qpop(q);
- if(qe.op == Qfree){
+ switch(qe.op){
+ case Qfree:
a = getarena(qe.bp.addr);
qlock(a);
cachedel(qe.bp.addr);
@@ -1030,15 +1037,20 @@
if(qe.b != nil)
dropblk(qe.b);
qunlock(a);
- }else if(qe.op == Qflush){
+ break;
+ case Qfence:
qlock(&fs->synclk);
if(--fs->syncing == 0)
rwakeupall(&fs->syncrz);
qunlock(&fs->synclk);
- }else{
+ break;
+ case Qwrite:
if(checkflag(qe.b, Bfreed) == 0)
syncblk(qe.b);
dropblk(qe.b);
+ break;
+ default:
+ abort();
}
assert(estacksz() == 0);
}
@@ -1069,7 +1081,7 @@
gen = aincv(&fs->qgen, 1);
fs->syncing = fs->nsyncers;
for(i = 0; i < fs->nsyncers; i++){
- qe.op = Qflush;
+ qe.op = Qfence;
qe.bp.addr = 0;
qe.bp.hash = -1;
qe.bp.gen = -1;
--- a/dat.h
+++ b/dat.h
@@ -454,7 +454,8 @@
};
enum {
- Qflush,
+ Qnone,
+ Qfence,
Qwrite,
Qfree,
};