My Kernel v0.1.0
semaphore.h
1
7#ifndef KERNEL_SEMAPHORE_H
8#define KERNEL_SEMAPHORE_H
9
10#include <kernel/spinlock.h>
11#include <kernel/waitqueue.h>
12
14struct semaphore {
15 spinlock_t lock;
16 struct waitqueue waitqueue;
17 unsigned int count;
18};
19
20typedef struct semaphore semaphore_t;
21
23#define INIT_SEMAPHORE(_name, _count) \
24 _name = ((struct semaphore){ \
25 .count = (_count), \
26 __INIT_SPINLOCK(.lock), \
27 .waitqueue = __WAITQUEUE_INIT(_name.waitqueue), \
28 })
29
31#define DECLARE_SEMAPHORE(_name, _count) \
32 struct semaphore _name = SEMAPHORE_INIT(_count)
33
35#define INIT_MUTEX(_name) INIT_SEMAPHORE(_name, 1)
36
38#define DECLARE_MUTEX(_name) semaphore_t INIT_MUTEX(_name)
39
45struct semaphore *semaphore_acquire(struct semaphore *);
46
50void semaphore_release(struct semaphore *);
51
52#endif /* KERNEL_SEMAPHORE_H */
A semaphore.
Definition: semaphore.h:14
Spinlock.
Definition: spinlock.h:29
Waiting Queue.
Definition: waitqueue.h:39