kernel: spinlocks

This commit is contained in:
Matheus
2023-04-23 17:12:05 -03:00
parent f16091656a
commit 0394165361
8 changed files with 59 additions and 30 deletions
+2 -1
View File
@@ -3,6 +3,7 @@
#include <stddef.h>
#include <stdint.h>
#include <spinlock.h>
typedef struct slab_t {
struct slab_t *next;
@@ -13,7 +14,7 @@ typedef struct slab_t {
} slab_t;
typedef struct scache_t {
// TODO lock
spinlock_t lock;
void (*ctor)(struct scache_t *cache, void *obj);
void (*dtor)(struct scache_t *cache, void *obj);
slab_t *full;
+2
View File
@@ -3,6 +3,7 @@
#include <time.h>
#include <arch/context.h>
#include <spinlock.h>
typedef struct timerentry_t {
struct timerentry_t *next;
@@ -12,6 +13,7 @@ typedef struct timerentry_t {
} timerentry_t;
typedef struct {
spinlock_t lock;
time_t ticksperus;
time_t tickcurrent;
void (*arm)(time_t);
+3 -1
View File
@@ -2,6 +2,7 @@
#define _VMM_H
#include <arch/mmu.h>
#include <spinlock.h>
#define VMM_FLAGS_PAGESIZE 1
#define VMM_FLAGS_ALLOCATE 2
@@ -29,7 +30,7 @@ typedef struct vmmrange_t{
} vmmrange_t;
typedef struct {
// TODO lock
spinlock_t lock;
struct vmmcache_t *next;
size_t freecount;
uintmax_t firstfree;
@@ -43,6 +44,7 @@ typedef struct vmmcache_t {
} vmmcache_t;
typedef struct {
spinlock_t lock;
vmmrange_t *ranges;
void *start;
void *end;
+22
View File
@@ -0,0 +1,22 @@
#ifndef _SPINLOCK_H
#define _SPINLOCK_H
#include <stdbool.h>
typedef int spinlock_t;
#define SPINLOCK_INIT(x) x = 0;
static inline void spinlock_acquire(spinlock_t *lock){
while(!__sync_bool_compare_and_swap(lock, 0, 1)) asm("pause");
}
static inline bool spinlock_try(spinlock_t *lock){
return __sync_bool_compare_and_swap(lock, 0, 1);
}
static inline void spinlock_release(spinlock_t *lock){
*lock = 0;
}
#endif