mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
vfs: use mutexes for locking
This commit is contained in:
@@ -331,9 +331,7 @@ static vops_t vnops = {
|
|||||||
static void ctor(scache_t *cache, void *obj) {
|
static void ctor(scache_t *cache, void *obj) {
|
||||||
devnode_t *node = obj;
|
devnode_t *node = obj;
|
||||||
memset(node, 0, sizeof(devnode_t));
|
memset(node, 0, sizeof(devnode_t));
|
||||||
node->vnode.refcount = 1;
|
VOP_INIT(&node->vnode, &vnops, 0, 0, NULL)
|
||||||
SPINLOCK_INIT(node->vnode.lock);
|
|
||||||
node->vnode.ops = &vnops;
|
|
||||||
node->attr.inode = ++currentinode;
|
node->attr.inode = ++currentinode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#include <kernel/alloc.h>
|
#include <kernel/alloc.h>
|
||||||
#include <kernel/timekeeper.h>
|
#include <kernel/timekeeper.h>
|
||||||
#include <kernel/slab.h>
|
#include <kernel/slab.h>
|
||||||
|
#include <kernel/vmm.h>
|
||||||
|
#include <arch/cpu.h>
|
||||||
#include <kernel/pmm.h>
|
#include <kernel/pmm.h>
|
||||||
#include <hashtable.h>
|
#include <hashtable.h>
|
||||||
#include <mutex.h>
|
#include <mutex.h>
|
||||||
|
|||||||
@@ -234,13 +234,10 @@ static vops_t vnops = {
|
|||||||
static void ctor(scache_t *cache, void *obj) {
|
static void ctor(scache_t *cache, void *obj) {
|
||||||
pipenode_t *node = obj;
|
pipenode_t *node = obj;
|
||||||
memset(node, 0, sizeof(pipenode_t));
|
memset(node, 0, sizeof(pipenode_t));
|
||||||
node->vnode.refcount = 1;
|
VOP_INIT(&node->vnode, &vnops, 0, 0, NULL);
|
||||||
SPINLOCK_INIT(node->vnode.lock);
|
|
||||||
node->vnode.ops = &vnops;
|
|
||||||
node->attr.inode = ++currentinode;
|
node->attr.inode = ++currentinode;
|
||||||
EVENT_INIT(&node->writeevent);
|
EVENT_INIT(&node->writeevent);
|
||||||
EVENT_INIT(&node->readevent);
|
EVENT_INIT(&node->readevent);
|
||||||
node->vnode.type = V_TYPE_FIFO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pipefs_init() {
|
void pipefs_init() {
|
||||||
|
|||||||
@@ -530,11 +530,7 @@ static tmpfsnode_t *newnode(vfs_t *vfs, int type) {
|
|||||||
|
|
||||||
node->attr.type = type;
|
node->attr.type = type;
|
||||||
node->attr.inode = ++((tmpfs_t *)vfs)->inodenumber;
|
node->attr.inode = ++((tmpfs_t *)vfs)->inodenumber;
|
||||||
node->vnode.type = type;
|
VOP_INIT(&node->vnode, &vnops, 0, type, vfs);
|
||||||
node->vnode.refcount = 1;
|
|
||||||
SPINLOCK_INIT(node->vnode.lock);
|
|
||||||
node->vnode.ops = &vnops;
|
|
||||||
node->vnode.vfs = vfs;
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef _VFS_H
|
#ifndef _VFS_H
|
||||||
#define _VFS_H
|
#define _VFS_H
|
||||||
|
|
||||||
|
#include <mutex.h>
|
||||||
#include <spinlock.h>
|
#include <spinlock.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -57,7 +58,7 @@ typedef struct vfs_t {
|
|||||||
|
|
||||||
typedef struct vnode_t {
|
typedef struct vnode_t {
|
||||||
struct vops_t *ops;
|
struct vops_t *ops;
|
||||||
spinlock_t lock;
|
mutex_t lock;
|
||||||
int refcount;
|
int refcount;
|
||||||
int flags;
|
int flags;
|
||||||
int type;
|
int type;
|
||||||
@@ -112,15 +113,15 @@ typedef struct vops_t {
|
|||||||
|
|
||||||
#define VOP_INIT(vn, o, f, t, v) \
|
#define VOP_INIT(vn, o, f, t, v) \
|
||||||
(vn)->ops = o; \
|
(vn)->ops = o; \
|
||||||
SPINLOCK_INIT((vn)->lock); \
|
MUTEX_INIT(&(vn)->lock); \
|
||||||
(vn)->refcount = 1; \
|
(vn)->refcount = 1; \
|
||||||
(vn)->flags = f; \
|
(vn)->flags = f; \
|
||||||
(vn)->type = t; \
|
(vn)->type = t; \
|
||||||
(vn)->vfs = v; \
|
(vn)->vfs = v; \
|
||||||
(vn)->vfsmounted = NULL;
|
(vn)->vfsmounted = NULL;
|
||||||
|
|
||||||
#define VOP_LOCK(v) spinlock_acquire(&(v)->lock)
|
#define VOP_LOCK(v) MUTEX_ACQUIRE(&(v)->lock, false)
|
||||||
#define VOP_UNLOCK(v) spinlock_release(&(v)->lock)
|
#define VOP_UNLOCK(v) MUTEX_RELEASE(&(v)->lock)
|
||||||
|
|
||||||
#define VOP_OPEN(v, f, c) (*v)->ops->open(v, f, c)
|
#define VOP_OPEN(v, f, c) (*v)->ops->open(v, f, c)
|
||||||
#define VOP_CLOSE(v, f, c) (v)->ops->close(v, f, c)
|
#define VOP_CLOSE(v, f, c) (v)->ops->close(v, f, c)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#define _VMM_H
|
#define _VMM_H
|
||||||
|
|
||||||
#include <arch/mmu.h>
|
#include <arch/mmu.h>
|
||||||
#include <spinlock.h>
|
#include <mutex.h>
|
||||||
#include <kernel/vfs.h>
|
#include <kernel/vfs.h>
|
||||||
|
|
||||||
#define VMM_FLAGS_PAGESIZE 1
|
#define VMM_FLAGS_PAGESIZE 1
|
||||||
|
|||||||
@@ -27,6 +27,4 @@ void semaphore_signal(semaphore_t *sem);
|
|||||||
bool semaphore_test(semaphore_t *sem);
|
bool semaphore_test(semaphore_t *sem);
|
||||||
bool semaphore_haswaiters(semaphore_t *sem);
|
bool semaphore_haswaiters(semaphore_t *sem);
|
||||||
|
|
||||||
#include <kernel/scheduler.h>
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
|
#include <kernel/scheduler.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user