thread: remove struct proc abstraction
struct proc was a redundant abstraction. everything can be tracked by just threads Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
20905ec95f
commit
e41877b268
16 changed files with 646 additions and 120 deletions
|
|
@ -8,12 +8,12 @@
|
|||
|
||||
static struct file *check_fd(int fd)
|
||||
{
|
||||
struct proc *proc = get_cur_proc();
|
||||
struct thread *thread = get_cur_thread();
|
||||
|
||||
if (fd >= proc->fd_array_size)
|
||||
if (fd >= thread->fd_array_size)
|
||||
return NULL;
|
||||
|
||||
struct file *f = proc->fdt + fd;
|
||||
struct file *f = thread->fdt + fd;
|
||||
if (!f->dirent)
|
||||
return NULL;
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ static ssize_t sys_write(int fd, const void *buf, size_t nbyte)
|
|||
|
||||
static int sys_open(const char *path, int flags)
|
||||
{
|
||||
struct proc *proc = get_cur_proc();
|
||||
struct thread *thread = get_cur_thread();
|
||||
|
||||
dirent_t *f;
|
||||
int res = vfs_open(path, &f);
|
||||
|
|
@ -76,12 +76,12 @@ static int sys_open(const char *path, int flags)
|
|||
if (res < 0)
|
||||
return res;
|
||||
|
||||
spinlock_acquire(&proc->fd_lock);
|
||||
spinlock_acquire(&thread->fd_lock);
|
||||
|
||||
int fdno = -1;
|
||||
|
||||
for (int i = 0; i < proc->fd_array_size; i++) {
|
||||
struct file *fd = proc->fdt + i;
|
||||
for (int i = 0; i < thread->fd_array_size; i++) {
|
||||
struct file *fd = thread->fdt + i;
|
||||
if (!fd->dirent) {
|
||||
memset(fd, 0, sizeof(struct file));
|
||||
fdno = i;
|
||||
|
|
@ -90,47 +90,47 @@ static int sys_open(const char *path, int flags)
|
|||
}
|
||||
|
||||
if (fdno == -1) {
|
||||
size_t osize = proc->fd_array_size;
|
||||
size_t osize = thread->fd_array_size;
|
||||
size_t newsize = MAX(osize * 2, 32);
|
||||
void *new = krealloc(proc->fdt, newsize, ALLOC_KERN);
|
||||
void *new = krealloc(thread->fdt, newsize, ALLOC_KERN);
|
||||
if (!new) {
|
||||
vfs_close(f);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
proc->fd_array_size = newsize;
|
||||
proc->fdt = new;
|
||||
thread->fd_array_size = newsize;
|
||||
thread->fdt = new;
|
||||
|
||||
memset(proc->fdt + osize, 0, newsize - osize);
|
||||
struct file *fd = proc->fdt + osize;
|
||||
memset(thread->fdt + osize, 0, newsize - osize);
|
||||
struct file *fd = thread->fdt + osize;
|
||||
fd->dirent = f;
|
||||
fd->flags = flags;
|
||||
fd->refcount = 1;
|
||||
fdno = osize;
|
||||
}
|
||||
|
||||
spinlock_release(&proc->fd_lock);
|
||||
spinlock_release(&thread->fd_lock);
|
||||
|
||||
return fdno;
|
||||
}
|
||||
|
||||
static int sys_close(int fd)
|
||||
{
|
||||
struct proc *proc = get_cur_proc();
|
||||
struct thread *thread = get_cur_thread();
|
||||
|
||||
if (fd >= proc->fd_array_size)
|
||||
if (fd >= thread->fd_array_size)
|
||||
return -EBADF;
|
||||
|
||||
struct file *f = proc->fdt + fd;
|
||||
struct file *f = thread->fdt + fd;
|
||||
if (!f->dirent)
|
||||
return -EBADF;
|
||||
|
||||
spinlock_acquire(&proc->fd_lock);
|
||||
spinlock_acquire(&thread->fd_lock);
|
||||
|
||||
vfs_close(f->dirent);
|
||||
memset(f, 0, sizeof(struct file));
|
||||
|
||||
spinlock_acquire(&proc->fd_lock);
|
||||
spinlock_acquire(&thread->fd_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue