git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Support to multi-threading and pthread interface (POSIX.1-2008) (#23)
[lunaix-os.git]
/
lunaix-os
/
kernel
/
ds
/
semaphore.c
diff --git
a/lunaix-os/kernel/ds/semaphore.c
b/lunaix-os/kernel/ds/semaphore.c
index 21d0e3399d761f3aaf2d3528a83dd55187144143..b02266c0574c8918824852790911188a597752e4 100644
(file)
--- a/
lunaix-os/kernel/ds/semaphore.c
+++ b/
lunaix-os/kernel/ds/semaphore.c
@@
-1,17
+1,25
@@
#include <lunaix/ds/semaphore.h>
#include <lunaix/ds/semaphore.h>
+#include <lunaix/sched.h>
-void sem_init(struct sem_t *sem, unsigned int initial) {
+void
+sem_init(struct sem_t* sem, unsigned int initial)
+{
sem->counter = ATOMIC_VAR_INIT(initial);
}
sem->counter = ATOMIC_VAR_INIT(initial);
}
-void sem_wait(struct sem_t *sem) {
+void
+sem_wait(struct sem_t* sem)
+{
while (!atomic_load(&sem->counter)) {
while (!atomic_load(&sem->counter)) {
- // TODO: yield the cpu
+ // FIXME: better thing like wait queue
+ sched_pass();
}
atomic_fetch_sub(&sem->counter, 1);
}
}
atomic_fetch_sub(&sem->counter, 1);
}
-void sem_post(struct sem_t *sem) {
+void
+sem_post(struct sem_t* sem)
+{
atomic_fetch_add(&sem->counter, 1);
// TODO: wake up a thread
}
\ No newline at end of file
atomic_fetch_add(&sem->counter, 1);
// TODO: wake up a thread
}
\ No newline at end of file