*
* \brief Semaphore based synchronization services.
*
- * \version $Id$
* \author Bernie Innocenti <bernie@codewiz.org>
*/
proc_forbid();
sem_verify(s);
- if ((!s->owner) || (s->owner == CurrentProcess))
+ if ((!s->owner) || (s->owner == current_process))
{
- s->owner = CurrentProcess;
+ s->owner = current_process;
s->nest_count++;
result = true;
}
sem_verify(s);
/* Is the semaphore already locked by another process? */
- if (UNLIKELY(s->owner && (s->owner != CurrentProcess)))
+ if (UNLIKELY(s->owner && (s->owner != current_process)))
{
/* Append calling process to the wait queue */
- ADDTAIL(&s->wait_queue, (Node *)CurrentProcess);
+ ADDTAIL(&s->wait_queue, (Node *)current_process);
/*
* We will wake up only when the current owner calls
ASSERT(LIST_EMPTY(&s->wait_queue));
/* The semaphore was free: lock it */
- s->owner = CurrentProcess;
+ s->owner = current_process;
s->nest_count++;
proc_permit();
}
*/
void sem_release(struct Semaphore *s)
{
+ Process *proc = NULL;
+
proc_forbid();
sem_verify(s);
- ASSERT(s->owner == CurrentProcess);
+ ASSERT(s->owner == current_process);
/*
* Decrement nesting count and check if the semaphore
*/
if (--s->nest_count == 0)
{
- Process *proc;
-
/* Disown semaphore */
s->owner = NULL;
{
s->nest_count = 1;
s->owner = proc;
- ATOMIC(SCHED_ENQUEUE(proc));
}
}
-
proc_permit();
+
+ if (proc)
+ ATOMIC(proc_wakeup(proc));
}