Be principled: acquire lock first

This commit is contained in:
Frans Kaashoek 2020-11-05 11:09:21 -05:00
parent 774288e05a
commit b63d3506e9

View file

@ -216,12 +216,12 @@ log_write(struct buf *b)
{ {
int i; int i;
acquire(&log.lock);
if (log.lh.n >= LOGSIZE || log.lh.n >= log.size - 1) if (log.lh.n >= LOGSIZE || log.lh.n >= log.size - 1)
panic("too big a transaction"); panic("too big a transaction");
if (log.outstanding < 1) if (log.outstanding < 1)
panic("log_write outside of trans"); panic("log_write outside of trans");
acquire(&log.lock);
for (i = 0; i < log.lh.n; i++) { for (i = 0; i < log.lh.n; i++) {
if (log.lh.block[i] == b->blockno) // log absorbtion if (log.lh.block[i] == b->blockno) // log absorbtion
break; break;