lab lock has been finished
This commit is contained in:
parent
39d5972dbd
commit
80fbb50f09
14
kernel/bio.c
14
kernel/bio.c
@ -52,7 +52,7 @@ uint hasher(uint dev,uint blockno){
|
|||||||
int hash_get(uint dev,uint blockno){
|
int hash_get(uint dev,uint blockno){
|
||||||
const uint hash_pos=hasher(dev, blockno);
|
const uint hash_pos=hasher(dev, blockno);
|
||||||
int pos=-1;
|
int pos=-1;
|
||||||
acquire(&bcache.hashlock[hash_pos]);
|
// acquire(&bcache.hashlock[hash_pos]);
|
||||||
for(int cur=bcache.hash_head[hash_pos];cur!=-1;cur=bcache.nxt[cur])
|
for(int cur=bcache.hash_head[hash_pos];cur!=-1;cur=bcache.nxt[cur])
|
||||||
if(bcache.buf[cur].dev==dev && bcache.buf[cur].blockno==blockno){
|
if(bcache.buf[cur].dev==dev && bcache.buf[cur].blockno==blockno){
|
||||||
pos=cur;
|
pos=cur;
|
||||||
@ -61,17 +61,17 @@ int hash_get(uint dev,uint blockno){
|
|||||||
|
|
||||||
RET:
|
RET:
|
||||||
|
|
||||||
release(&bcache.hashlock[hash_pos]);
|
// release(&bcache.hashlock[hash_pos]);
|
||||||
// printf("%u\n",pos);
|
// printf("%u\n",pos);
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hash_add(uint dev,uint blockno,uint buf_pos){
|
void hash_add(uint dev,uint blockno,uint buf_pos){
|
||||||
const uint hash_pos=hasher(dev, blockno);
|
const uint hash_pos=hasher(dev, blockno);
|
||||||
acquire(&bcache.hashlock[hash_pos]);
|
// acquire(&bcache.hashlock[hash_pos]);
|
||||||
bcache.nxt[buf_pos]=bcache.hash_head[hash_pos];
|
bcache.nxt[buf_pos]=bcache.hash_head[hash_pos];
|
||||||
bcache.hash_head[hash_pos]=buf_pos;
|
bcache.hash_head[hash_pos]=buf_pos;
|
||||||
release(&bcache.hashlock[hash_pos]);
|
// release(&bcache.hashlock[hash_pos]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hash_del(uint dev,uint blockno){
|
void hash_del(uint dev,uint blockno){
|
||||||
@ -157,6 +157,8 @@ bget(uint dev, uint blockno)
|
|||||||
{
|
{
|
||||||
struct buf *b;
|
struct buf *b;
|
||||||
// acquire(&bcache.lock);
|
// acquire(&bcache.lock);
|
||||||
|
const uint hash_pos=hasher(dev, blockno);
|
||||||
|
acquire(&bcache.hashlock[hash_pos]);
|
||||||
const int pos=hash_get(dev, blockno);
|
const int pos=hash_get(dev, blockno);
|
||||||
// Is the block already cached?
|
// Is the block already cached?
|
||||||
// for(b = bcache.head.next; b != &bcache.head; b = b->next){
|
// for(b = bcache.head.next; b != &bcache.head; b = b->next){
|
||||||
@ -169,8 +171,7 @@ bget(uint dev, uint blockno)
|
|||||||
// }
|
// }
|
||||||
if(pos>=0){
|
if(pos>=0){
|
||||||
b=&bcache.buf[pos];
|
b=&bcache.buf[pos];
|
||||||
const uint hash_pos=hasher(dev, blockno);
|
// acquire(&bcache.hashlock[hash_pos]);
|
||||||
acquire(&bcache.hashlock[hash_pos]);
|
|
||||||
++bcache.buf[pos].refcnt;
|
++bcache.buf[pos].refcnt;
|
||||||
release(&bcache.hashlock[hash_pos]);
|
release(&bcache.hashlock[hash_pos]);
|
||||||
acquiresleep(&b->lock);
|
acquiresleep(&b->lock);
|
||||||
@ -214,6 +215,7 @@ bget(uint dev, uint blockno)
|
|||||||
const int ori=bcache.freelist_head[i];
|
const int ori=bcache.freelist_head[i];
|
||||||
bcache.freelist_head[i]=bcache.nxt[bcache.freelist_head[i]];
|
bcache.freelist_head[i]=bcache.nxt[bcache.freelist_head[i]];
|
||||||
hash_add(dev,blockno,ori);
|
hash_add(dev,blockno,ori);
|
||||||
|
release(&bcache.hashlock[hash_pos]);
|
||||||
b->dev=dev;
|
b->dev=dev;
|
||||||
b->blockno=blockno;
|
b->blockno=blockno;
|
||||||
b->valid=0;
|
b->valid=0;
|
||||||
|
|||||||
@ -93,8 +93,8 @@ bfree(int dev, uint b)
|
|||||||
{
|
{
|
||||||
struct buf *bp;
|
struct buf *bp;
|
||||||
int bi, m;
|
int bi, m;
|
||||||
DEBUG();
|
// DEBUG();
|
||||||
printf("%d %d\n",dev,b);
|
// printf("%d %d\n",dev,b);
|
||||||
bp = bread(dev, BBLOCK(b, sb));
|
bp = bread(dev, BBLOCK(b, sb));
|
||||||
bi = b % BPB;
|
bi = b % BPB;
|
||||||
m = 1 << (bi % 8);
|
m = 1 << (bi % 8);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user