mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-26 00:52:50 +00:00
Initial commit: SUB-OS 64-Bit Production Monolithic Operating System with LazyBox userland suite
This commit is contained in:
commit
cd9c786d14
88 files changed
+7132
No files matched your search
@@ -0,0 +1,36 @@
|
||||
#ifndef _KERNEL_SYNC_H
|
||||
#define _KERNEL_SYNC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
volatile uint32_t lock;
|
||||
} spinlock_t;
|
||||
|
||||
#define SPINLOCK_INIT { .lock = 0 }
|
||||
|
||||
static inline void spinlock_init(spinlock_t* lock) {
|
||||
lock->lock = 0;
|
||||
}
|
||||
|
||||
static inline void spin_lock(spinlock_t* lock) {
|
||||
while (__atomic_test_and_set(&lock->lock, __ATOMIC_ACQUIRE)) {
|
||||
__asm__ volatile ("pause");
|
||||
}
|
||||
}
|
||||
|
||||
static inline void spin_unlock(spinlock_t* lock) {
|
||||
__atomic_clear(&lock->lock, __ATOMIC_RELEASE);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
spinlock_t lock;
|
||||
volatile int count;
|
||||
} semaphore_t;
|
||||
|
||||
void sem_init(semaphore_t* sem, int value);
|
||||
void sem_wait(semaphore_t* sem);
|
||||
void sem_post(semaphore_t* sem);
|
||||
|
||||
#endif // _KERNEL_SYNC_H
|
||||
Reference in new issue
Block a user