From 634a41725aa4d605ea3483aa61175248b1b3631c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 30 Sep 2002 03:48:59 +0000 Subject: [PATCH] The main reason I commit this: the last change also made set_sem_owner() to check for a valid team id. Added a comment about a race condition in set_sem_owner(). Some minor style changes. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1309 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/sem.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/kernel/core/sem.c b/src/kernel/core/sem.c index 97ff8bd891..6b35aef22d 100644 --- a/src/kernel/core/sem.c +++ b/src/kernel/core/sem.c @@ -739,6 +739,9 @@ set_sem_owner(sem_id id, team_id team) return B_BAD_SEM_ID; } + // Todo: this is a small race condition: the team ID could already + // be invalid at this point - we would lose one semaphore slot in + // this case! gSems[slot].owner = team; RELEASE_SEM_LOCK(gSems[slot]); @@ -799,7 +802,7 @@ remove_thread_from_sem(struct thread *t, struct sem_entry *sem, struct thread_qu // remove the thread from the queue and place it in the supplied queue t1 = thread_dequeue_id(&sem->q, t->id); - if(t != t1) + if (t != t1) return ERR_NOT_FOUND; sem->count += t->sem_acquire_count; t->state = B_THREAD_READY; @@ -811,7 +814,7 @@ remove_thread_from_sem(struct thread *t, struct sem_entry *sem, struct thread_qu int delta = min(t->sem_count, sem->count); t->sem_count -= delta; - if(t->sem_count <= 0) { + if (t->sem_count <= 0) { t = thread_dequeue(&sem->q); t->state = B_THREAD_READY; thread_enqueue(t, queue);