fd - /* Note that when the system is starting up the lock...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* Note that when the system is starting up the lock maynot be set * which means that the system thinks it owns the lock. * So, to solve the problem we use a conditional locking mechanism. */ #include <fd.h> #include <vfs.h> #include <kern/unistd.h> /* This is an array of all file descriptors available to the system */ static struct fd FDS[MAX_SYS_FDS]; static struct lock *fd_sys_lock; /* Initialize all FDS entries */ void FDS_init() { fd_sys_lock = lock_create("SYS FDS LOCK"); int i; for(i = 0; i < MAX_SYS_FDS; i++) { FDS[i].lock = lock_create("SYS FD LOCK"); FDS[i].offset = 0; FDS[i].vn = NULL; } } /* Allocate the next file descriptor * This is an atomic operation */ struct fd* fd_allocate() { int use_lock = !lock_do_i_hold(fd_sys_lock); //kprintf("FD ALLOCATE. Do I own Lock? %d\n", !use_lock); //if(use_lock) lock_acquire(fd_sys_lock); int i; for(i = 0; i < MAX_SYS_FDS; i++) { if(FDS[i].vn == NULL) { FDS[i].vn = (struct vnode *)kmalloc(sizeof(struct vnode)); return &FDS[i]; } } //if(use_lock) lock_release(fd_sys_lock);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/10/2009 for the course CS 536 taught by Professor Lums during the Spring '09 term at Indiana.

Page1 / 2

fd - /* Note that when the system is starting up the lock...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online