Permalink
Browse files

group locks into structs they protect.

few naming nits.
  • Loading branch information...
1 parent 949e559 commit 34295f461a416e40bb76e67c568a761222dc6913 rsc committed May 31, 2009
Showing with 82 additions and 80 deletions.
  1. +1 −1 bio.c
  2. +15 −12 console.c
  3. +1 −1 file.c
  4. +1 −1 fs.c
  5. +2 −2 ide.c
  6. +2 −2 init.c
  7. +14 −12 kalloc.c
  8. +42 −44 proc.c
  9. +2 −2 proc.h
  10. +2 −3 usertests.c
View
2 bio.c
@@ -41,7 +41,7 @@ binit(void)
{
struct buf *b;
- initlock(&bcache.lock, "buf_table");
+ initlock(&bcache.lock, "bcache");
//PAGEBREAK!
// Create linked list of buffers
View
@@ -17,9 +17,12 @@
static ushort *crt = (ushort*)0xb8000; // CGA memory
-static struct spinlock console_lock;
-int panicked = 0;
-volatile int use_console_lock = 0;
+static struct {
+ struct spinlock lock;
+ int locking;
+} cons;
+
+static int panicked = 0;
static void
cgaputc(int c)
@@ -99,9 +102,9 @@ cprintf(char *fmt, ...)
uint *argp;
char *s;
- locking = use_console_lock;
+ locking = cons.locking;
if(locking)
- acquire(&console_lock);
+ acquire(&cons.lock);
argp = (uint*)(void*)&fmt + 1;
state = 0;
@@ -146,7 +149,7 @@ cprintf(char *fmt, ...)
}
if(locking)
- release(&console_lock);
+ release(&cons.lock);
}
int
@@ -155,10 +158,10 @@ consolewrite(struct inode *ip, char *buf, int n)
int i;
iunlock(ip);
- acquire(&console_lock);
+ acquire(&cons.lock);
for(i = 0; i < n; i++)
consputc(buf[i] & 0xff);
- release(&console_lock);
+ release(&cons.lock);
ilock(ip);
return n;
@@ -255,12 +258,12 @@ consoleread(struct inode *ip, char *dst, int n)
void
consoleinit(void)
{
- initlock(&console_lock, "console");
- initlock(&input.lock, "console input");
+ initlock(&cons.lock, "console");
+ initlock(&input.lock, "input");
devsw[CONSOLE].write = consolewrite;
devsw[CONSOLE].read = consoleread;
- use_console_lock = 1;
+ cons.locking = 1;
picenable(IRQ_KBD);
ioapicenable(IRQ_KBD, 0);
@@ -273,7 +276,7 @@ panic(char *s)
uint pcs[10];
cli();
- use_console_lock = 0;
+ cons.locking = 0;
cprintf("cpu%d: panic: ", cpu());
cprintf(s);
cprintf("\n");
View
2 file.c
@@ -14,7 +14,7 @@ struct {
void
fileinit(void)
{
- initlock(&ftable.lock, "file_table");
+ initlock(&ftable.lock, "ftable");
}
// Allocate a file structure.
View
2 fs.c
@@ -138,7 +138,7 @@ struct {
void
iinit(void)
{
- initlock(&icache.lock, "icache.lock");
+ initlock(&icache.lock, "icache");
}
// Find the inode with number inum on device dev
View
4 ide.c
@@ -30,13 +30,13 @@ static void idestart(struct buf*);
// Wait for IDE disk to become ready.
static int
-idewait(int check_error)
+idewait(int checkerr)
{
int r;
while(((r = inb(0x1f7)) & (IDE_BSY|IDE_DRDY)) != IDE_DRDY)
;
- if(check_error && (r & (IDE_DF|IDE_ERR)) != 0)
+ if(checkerr && (r & (IDE_DF|IDE_ERR)) != 0)
return -1;
return 0;
}
View
4 init.c
@@ -5,7 +5,7 @@
#include "user.h"
#include "fcntl.h"
-char *sh_args[] = { "sh", 0 };
+char *argv[] = { "sh", 0 };
int
main(void)
@@ -27,7 +27,7 @@ main(void)
exit();
}
if(pid == 0){
- exec("sh", sh_args);
+ exec("sh", argv);
printf(1, "init: exec sh failed\n");
exit();
}
View
@@ -10,13 +10,15 @@
#include "param.h"
#include "spinlock.h"
-struct spinlock kalloc_lock;
-
struct run {
struct run *next;
int len; // bytes
};
-struct run *freelist;
+
+struct {
+ struct spinlock lock;
+ struct run *freelist;
+} kmem;
// Initialize free list of physical pages.
// This code cheats by just considering one megabyte of
@@ -29,7 +31,7 @@ kinit(void)
uint mem;
char *start;
- initlock(&kalloc_lock, "kalloc");
+ initlock(&kmem.lock, "kmem");
start = (char*) &end;
start = (char*) (((uint)start + PAGE) & ~(PAGE-1));
mem = 256; // assume computer has 256 pages of RAM
@@ -52,10 +54,10 @@ kfree(char *v, int len)
// Fill with junk to catch dangling refs.
memset(v, 1, len);
- acquire(&kalloc_lock);
+ acquire(&kmem.lock);
p = (struct run*)v;
pend = (struct run*)(v + len);
- for(rp=&freelist; (r=*rp) != 0 && r <= pend; rp=&r->next){
+ for(rp=&kmem.freelist; (r=*rp) != 0 && r <= pend; rp=&r->next){
rend = (struct run*)((char*)r + r->len);
if(r <= p && p < rend)
panic("freeing free page");
@@ -80,7 +82,7 @@ kfree(char *v, int len)
*rp = p;
out:
- release(&kalloc_lock);
+ release(&kmem.lock);
}
// Allocate n bytes of physical memory.
@@ -95,21 +97,21 @@ kalloc(int n)
if(n % PAGE || n <= 0)
panic("kalloc");
- acquire(&kalloc_lock);
- for(rp=&freelist; (r=*rp) != 0; rp=&r->next){
+ acquire(&kmem.lock);
+ for(rp=&kmem.freelist; (r=*rp) != 0; rp=&r->next){
if(r->len == n){
*rp = r->next;
- release(&kalloc_lock);
+ release(&kmem.lock);
return (char*)r;
}
if(r->len > n){
r->len -= n;
p = (char*)r + r->len;
- release(&kalloc_lock);
+ release(&kmem.lock);
return p;
}
}
- release(&kalloc_lock);
+ release(&kmem.lock);
cprintf("kalloc: out of memory\n");
return 0;
Oops, something went wrong.

0 comments on commit 34295f4

Please sign in to comment.