Skip to content

Commit dec637b

Browse files
committed
Replace I_BUSY with sleep locks
1 parent 2adb7c2 commit dec637b

File tree

7 files changed

+20
-21
lines changed

7 files changed

+20
-21
lines changed

console.c

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "param.h"
88
#include "traps.h"
99
#include "spinlock.h"
10+
#include "sleeplock.h"
1011
#include "fs.h"
1112
#include "file.h"
1213
#include "memlayout.h"

file.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#include "defs.h"
77
#include "param.h"
88
#include "fs.h"
9-
#include "file.h"
109
#include "spinlock.h"
10+
#include "sleeplock.h"
11+
#include "file.h"
1112

1213
struct devsw devsw[NDEV];
1314
struct {

file.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ struct inode {
1414
uint dev; // Device number
1515
uint inum; // Inode number
1616
int ref; // Reference count
17-
int flags; // I_BUSY, I_VALID
17+
struct sleeplock lock;
18+
int flags; // I_VALID
1819

1920
short type; // copy of disk inode
2021
short major;
@@ -23,7 +24,6 @@ struct inode {
2324
uint size;
2425
uint addrs[NDIRECT+1];
2526
};
26-
#define I_BUSY 0x1
2727
#define I_VALID 0x2
2828

2929
// table mapping major device number to

fs.c

+10-17
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ bfree(int dev, uint b)
135135
//
136136
// * Locked: file system code may only examine and modify
137137
// the information in an inode and its content if it
138-
// has first locked the inode. The I_BUSY flag indicates
139-
// that the inode is locked. ilock() sets I_BUSY,
140-
// while iunlock clears it.
138+
// has first locked the inode.
141139
//
142140
// Thus a typical sequence is:
143141
// ip = iget(dev, inum)
@@ -165,7 +163,13 @@ struct {
165163
void
166164
iinit(int dev)
167165
{
166+
int i = 0;
167+
168168
initlock(&icache.lock, "icache");
169+
for(i = 0; i < NINODE; i++) {
170+
initsleeplock(&icache.inode[i].lock, "inode");
171+
}
172+
169173
readsb(dev, &sb);
170174
cprintf("sb: size %d nblocks %d ninodes %d nlog %d logstart %d\
171175
inodestart %d bmap start %d\n", sb.size, sb.nblocks,
@@ -277,11 +281,7 @@ ilock(struct inode *ip)
277281
if(ip == 0 || ip->ref < 1)
278282
panic("ilock");
279283

280-
acquire(&icache.lock);
281-
while(ip->flags & I_BUSY)
282-
sleep(ip, &icache.lock);
283-
ip->flags |= I_BUSY;
284-
release(&icache.lock);
284+
acquiresleep(&ip->lock);
285285

286286
if(!(ip->flags & I_VALID)){
287287
bp = bread(ip->dev, IBLOCK(ip->inum, sb));
@@ -303,13 +303,10 @@ ilock(struct inode *ip)
303303
void
304304
iunlock(struct inode *ip)
305305
{
306-
if(ip == 0 || !(ip->flags & I_BUSY) || ip->ref < 1)
306+
if(ip == 0 || !holdingsleep(&ip->lock) || ip->ref < 1)
307307
panic("iunlock");
308308

309-
acquire(&icache.lock);
310-
ip->flags &= ~I_BUSY;
311-
wakeup(ip);
312-
release(&icache.lock);
309+
releasesleep(&ip->lock);
313310
}
314311

315312
// Drop a reference to an in-memory inode.
@@ -325,16 +322,12 @@ iput(struct inode *ip)
325322
acquire(&icache.lock);
326323
if(ip->ref == 1 && (ip->flags & I_VALID) && ip->nlink == 0){
327324
// inode has no links and no other references: truncate and free.
328-
if(ip->flags & I_BUSY)
329-
panic("iput busy");
330-
ip->flags |= I_BUSY;
331325
release(&icache.lock);
332326
itrunc(ip);
333327
ip->type = 0;
334328
iupdate(ip);
335329
acquire(&icache.lock);
336330
ip->flags = 0;
337-
wakeup(ip);
338331
}
339332
ip->ref--;
340333
release(&icache.lock);

pipe.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
#include "mmu.h"
55
#include "proc.h"
66
#include "fs.h"
7-
#include "file.h"
87
#include "spinlock.h"
8+
#include "sleeplock.h"
9+
#include "file.h"
910

1011
#define PIPESIZE 512
1112

sysfile.c

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "mmu.h"
1212
#include "proc.h"
1313
#include "fs.h"
14+
#include "spinlock.h"
15+
#include "sleeplock.h"
1416
#include "file.h"
1517
#include "fcntl.h"
1618

uart.c

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "param.h"
66
#include "traps.h"
77
#include "spinlock.h"
8+
#include "sleeplock.h"
89
#include "fs.h"
910
#include "file.h"
1011
#include "mmu.h"

0 commit comments

Comments
 (0)