- add some additional error checks
git-svn-id: http://svn.lfbs.rwth-aachen.de/svn/scc/trunk/MetalSVM@19 315a16e6-25f9-4109-90ae-ca3045a26c18
This commit is contained in:
parent
44f4de6e80
commit
4b3c070275
1 changed files with 35 additions and 3 deletions
|
@ -35,21 +35,34 @@ typedef struct {
|
|||
spinlock_t lock;
|
||||
} sem_t;
|
||||
|
||||
inline static void sem_init(sem_t* s, unsigned int v) {
|
||||
inline static int sem_init(sem_t* s, unsigned int v) {
|
||||
unsigned int i;
|
||||
|
||||
if (BUILTIN_EXPECT(!s, 0))
|
||||
return -1;
|
||||
|
||||
s->value = v;
|
||||
s->pos = 0;
|
||||
for(i=0; i<MAX_TASKS; i++)
|
||||
s->queue[i] = MAX_TASKS;
|
||||
spinlock_init(&s->lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline static void sem_destroy(sem_t* s) {
|
||||
inline static int sem_destroy(sem_t* s) {
|
||||
if (BUILTIN_EXPECT(!s, 0))
|
||||
return -1;
|
||||
|
||||
spinlock_destroy(&s->lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline static int sem_wait(sem_t* s) {
|
||||
if (BUILTIN_EXPECT(!s, 0))
|
||||
return -1;
|
||||
|
||||
next_try:
|
||||
spinlock_lock(&s->lock);
|
||||
if (s->value > 0) {
|
||||
|
@ -67,7 +80,26 @@ next_try:
|
|||
return 0;
|
||||
}
|
||||
|
||||
inline static int sem_trywait(sem_t* s) {
|
||||
int ret = -1;
|
||||
|
||||
if (BUILTIN_EXPECT(!s, 0))
|
||||
return -1;
|
||||
|
||||
spinlock_lock(&s->lock);
|
||||
if (s->value > 0) {
|
||||
s->value--;
|
||||
ret = 0;
|
||||
}
|
||||
spinlock_unlock(&s->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline static int sem_post(sem_t* s) {
|
||||
if (BUILTIN_EXPECT(!s, 0))
|
||||
return -1;
|
||||
|
||||
spinlock_lock(&s->lock);
|
||||
if (s->value > 0) {
|
||||
s->value++;
|
||||
|
@ -75,8 +107,8 @@ inline static int sem_post(sem_t* s) {
|
|||
} else {
|
||||
unsigned int k, i;
|
||||
|
||||
i = s->pos;
|
||||
s->value++;
|
||||
i = s->pos;
|
||||
for(k=0; k<MAX_TASKS; k++) {
|
||||
if (s->queue[i] < MAX_TASKS) {
|
||||
wakeup_task(s->queue[i]);
|
||||
|
|
Loading…
Add table
Reference in a new issue