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,26 @@
|
||||
#include <kernel/sync.h>
|
||||
#include <kernel/sched.h>
|
||||
|
||||
void sem_init(semaphore_t* sem, int value) {
|
||||
spinlock_init(&sem->lock);
|
||||
sem->count = value;
|
||||
}
|
||||
|
||||
void sem_wait(semaphore_t* sem) {
|
||||
while (1) {
|
||||
spin_lock(&sem->lock);
|
||||
if (sem->count > 0) {
|
||||
sem->count--;
|
||||
spin_unlock(&sem->lock);
|
||||
return;
|
||||
}
|
||||
spin_unlock(&sem->lock);
|
||||
sched_yield();
|
||||
}
|
||||
}
|
||||
|
||||
void sem_post(semaphore_t* sem) {
|
||||
spin_lock(&sem->lock);
|
||||
sem->count++;
|
||||
spin_unlock(&sem->lock);
|
||||
}
|
||||
Reference in new issue
Block a user