* the GNU General Public License.
*
* Copyright 2001, 2004 Develer S.r.l. (http://www.develer.com/)
- * Copyright 1999, 2000, 2001 Bernardo Innocenti <bernie@develer.com>
- *
+ * Copyright 1999, 2000, 2001 Bernie Innocenti <bernie@codewiz.org>
* -->
*
* \brief Semaphore based synchronization services.
*
* \version $Id$
- *
- * \author Bernardo Innocenti <bernie@develer.com>
+ * \author Bernie Innocenti <bernie@codewiz.org>
*/
#include "sem.h"
+#include <cfg/debug.h>
+
+#include <cpu/irq.h> // ASSERT_IRQ_DISABLED()
+
#include <kern/proc.h>
#include <kern/proc_p.h>
#include <kern/signal.h>
-#include <cfg/debug.h>
INLINE void sem_verify(struct Semaphore *s)
{
ASSERT(s->nest_count < 128); // heuristic max
}
-
/**
* \brief Initialize a Semaphore structure.
*/
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
* be locked for us.
*/
proc_permit();
- proc_schedule();
+ proc_switch();
}
else
{
ASSERT(LIST_EMPTY(&s->wait_queue));
/* The semaphore was free: lock it */
- s->owner = CurrentProcess;
+ s->owner = current_process;
s->nest_count++;
proc_permit();
}
proc_forbid();
sem_verify(s);
- ASSERT(s->owner == CurrentProcess);
+ ASSERT(s->owner == current_process);
/*
* Decrement nesting count and check if the semaphore
{
s->nest_count = 1;
s->owner = proc;
- SCHED_ENQUEUE(proc);
+ ATOMIC(SCHED_ENQUEUE(proc));
}
}