1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/net/sixlowpan/semaphore.c
mlenders f40ed36802 [sys/net/sixlowpan/flowcontrol.*]
* fixed sem_init()
2011-07-28 18:25:57 +02:00

32 lines
591 B
C

#include <mutex.h>
#include "semaphore.h"
void sem_init(sem_t *sem, int8_t value) {
sem->value = value;
mutex_init(&sem->mutex);
sem->locked = 0;
}
int sem_wait(sem_t *sem) {
int res;
if(--(sem->value) <= 0 && !sem->locked) {
sem->locked = !(sem->locked);
res = mutex_lock(&(sem->mutex));
if (res < 0) {
return res;
}
}
return 0;
}
int sem_signal(sem_t *sem) {
if (++(sem->value) > 0 && sem->locked) {
sem->locked = !(sem->locked);
mutex_unlock(&(sem->mutex),0);
}
return 0;
}