Added spinlocks
This commit is contained in:
parent
c5c9782535
commit
817995394b
|
|
@ -57,7 +57,7 @@ extern void kmain(kernel_info_t *kernel_info){
|
|||
pic_init(0x20);
|
||||
pic_setmask(0x0, PIC1_DATA);
|
||||
pic_setmask(0x0, PIC2_DATA);
|
||||
|
||||
vfs_init();
|
||||
fcreate("/dev", FS_FILE_IS_DIR);
|
||||
fcreate("/dev/disk", FS_FILE_IS_DIR);
|
||||
fcreate("/tmp", FS_FILE_IS_DIR);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
#include <stdatomic.h>
|
||||
|
||||
typedef struct spinlock{
|
||||
atomic_flag lock;
|
||||
}spinlock_t;
|
||||
|
||||
inline void spinlock_acquire(spinlock_t spinlock){
|
||||
// atomic_compare_exchange_strong(&spinlock.lock, &spinlock.unlocked, spinlock.locked);
|
||||
while(atomic_flag_test_and_set_explicit(&spinlock.lock, memory_order_acquire));
|
||||
}
|
||||
inline void spinlock_release(spinlock_t spinlock){
|
||||
atomic_flag_clear_explicit(&spinlock.lock, memory_order_release);
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
#include "../shared/kstdlib.h"
|
||||
#include "../shared/memory.h"
|
||||
#include "../shared/string.h"
|
||||
#include "../shared/spinlock.h"
|
||||
#define MODULE_NAME "KVFS"
|
||||
|
||||
// !TODO: Modify code to become thread-safe
|
||||
|
|
@ -13,9 +14,17 @@
|
|||
// return;
|
||||
// }
|
||||
|
||||
spinlock_t vfs_lock;
|
||||
|
||||
void vfs_init(){
|
||||
spinlock_release(vfs_lock);
|
||||
}
|
||||
|
||||
vfile_t *fcreate(char *path, FS_FILE_FLAGS flags){
|
||||
// return 0;
|
||||
spinlock_acquire(vfs_lock);
|
||||
vfile_t *returnable = vfcreate(get_root_dir(), path, flags);
|
||||
spinlock_release(vfs_lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -60,9 +69,11 @@ vfile_t *vfcreate(vfile_t *parent_dir, char *relpath, FS_FILE_FLAGS flags){
|
|||
}
|
||||
|
||||
int fdelete(vfile_t *file_entry){
|
||||
spinlock_acquire(vfs_lock);
|
||||
if(!file_entry || !file_entry->fileops || !file_entry->fileops->delete){
|
||||
return 0;
|
||||
}
|
||||
spinlock_release(vfs_lock);
|
||||
return file_entry->fileops->delete(file_entry);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ typedef struct virtual_file{
|
|||
|
||||
}vfile_t;
|
||||
|
||||
void vfs_init();
|
||||
|
||||
// vfile_t *rfopen(char *name, vfile_t dir);
|
||||
vfile_t *fcreate(char *path, FS_FILE_FLAGS flags);
|
||||
int fdelete(vfile_t* file_entry);
|
||||
|
|
|
|||
|
|
@ -379,7 +379,8 @@ int ata_read(vfile_t *file, uint8_t *ptr, uint32_t offset, uint32_t count) {
|
|||
transferring_pid = cpid;
|
||||
|
||||
outb(bm_base, 0x09);
|
||||
asm("sti");
|
||||
// asm("sti"); // TODO: Make it so that instead of sti(), restore interrupt flag
|
||||
if(!api(MODULE_API_IS_INTERRUPT)) asm("sti");
|
||||
|
||||
uint8_t status = inb(ctrl_base);
|
||||
uint8_t bm_status = inb(bm_base + 2);
|
||||
|
|
|
|||
Loading…
Reference in New Issue