Files
Astral/kernel-src/include/semaphore.h
T
8infy f306edb5ec semaphore: introduce a semaphore_reset helper
This simply clears the internal counter of a semaphore.
2024-09-01 23:12:44 +03:00

35 lines
724 B
C

#ifndef _SEMAPHORE_H
#define _SEMAPHORE_H
#include <stddef.h>
#include <stdbool.h>
#include <spinlock.h>
#include <time.h>
#define SEM_TAIL 0
#define SEM_HEAD 1
typedef struct semaphore_t{
int i;
spinlock_t lock;
struct thread_t *tail;
struct thread_t *head;
} semaphore_t;
#define SEMAPHORE_INIT(x, v) { \
(x)->i = v; \
SPINLOCK_INIT((x)->lock); \
(x)->tail = NULL; \
(x)->head = NULL; \
}
int semaphore_wait(semaphore_t *sem, bool interruptible);
int semaphore_timedwait(semaphore_t *sem, time_t timeoutusec, bool interruptible);
void semaphore_signal(semaphore_t *sem);
void semaphore_reset(semaphore_t *sem);
bool semaphore_test(semaphore_t *sem);
bool semaphore_haswaiters(semaphore_t *sem);
#endif