kernel: semaphores

This commit is contained in:
Matheus
2023-05-03 21:07:43 -03:00
parent 433155bb74
commit c1c84cffbb
2 changed files with 95 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
#ifndef _SEMAPHORE_H
#define _SEMAPHORE_H
#include <stdbool.h>
#include <spinlock.h>
#include <kernel/scheduler.h>
#define SEM_TAIL 0
#define SEM_HEAD 1
typedef struct {
int i;
spinlock_t lock;
thread_t *tail;
thread_t *head;
} semaphore_t;
#define SEMAPHORE_INIT(x, v) { \
(x)->val = v; \
SPINLOCK_INIT((x)->lock); \
(x)->list = NULL; \
}
int semaphore_wait(semaphore_t *sem, bool interruptible);
void semaphore_signal(semaphore_t *sem);
bool semaphore_test(semaphore_t *sem);
#endif