projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
USB: add doxygen documentation
[bertos.git]
/
bertos
/
kern
/
sem.c
diff --git
a/bertos/kern/sem.c
b/bertos/kern/sem.c
index 0f31fa067b9fff651945b60076adaf3e855e05f4..df74355501e32e7e9d53f0828d596bdf0ffbcfa0 100644
(file)
--- a/
bertos/kern/sem.c
+++ b/
bertos/kern/sem.c
@@
-27,22
+27,22
@@
* the GNU General Public License.
*
* Copyright 2001, 2004 Develer S.r.l. (http://www.develer.com/)
* 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.
*
* -->
*
* \brief Semaphore based synchronization services.
*
- * \version $Id$
- *
- * \author Bernardo Innocenti <bernie@develer.com>
+ * \author Bernie Innocenti <bernie@codewiz.org>
*/
#include "sem.h"
*/
#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 <kern/proc.h>
#include <kern/proc_p.h>
#include <kern/signal.h>
-#include <cfg/debug.h>
INLINE void sem_verify(struct Semaphore *s)
{
INLINE void sem_verify(struct Semaphore *s)
{
@@
-53,7
+53,6
@@
INLINE void sem_verify(struct Semaphore *s)
ASSERT(s->nest_count < 128); // heuristic max
}
ASSERT(s->nest_count < 128); // heuristic max
}
-
/**
* \brief Initialize a Semaphore structure.
*/
/**
* \brief Initialize a Semaphore structure.
*/
@@
-82,9
+81,9
@@
bool sem_attempt(struct Semaphore *s)
proc_forbid();
sem_verify(s);
proc_forbid();
sem_verify(s);
- if ((!s->owner) || (s->owner ==
CurrentP
rocess))
+ if ((!s->owner) || (s->owner ==
current_p
rocess))
{
{
- s->owner =
CurrentP
rocess;
+ s->owner =
current_p
rocess;
s->nest_count++;
result = true;
}
s->nest_count++;
result = true;
}
@@
-117,10
+116,10
@@
void sem_obtain(struct Semaphore *s)
sem_verify(s);
/* Is the semaphore already locked by another process? */
sem_verify(s);
/* Is the semaphore already locked by another process? */
- if (UNLIKELY(s->owner && (s->owner !=
CurrentP
rocess)))
+ if (UNLIKELY(s->owner && (s->owner !=
current_p
rocess)))
{
/* Append calling process to the wait queue */
{
/* Append calling process to the wait queue */
- ADDTAIL(&s->wait_queue, (Node *)
CurrentP
rocess);
+ ADDTAIL(&s->wait_queue, (Node *)
current_p
rocess);
/*
* We will wake up only when the current owner calls
/*
* We will wake up only when the current owner calls
@@
-128,14
+127,14
@@
void sem_obtain(struct Semaphore *s)
* be locked for us.
*/
proc_permit();
* be locked for us.
*/
proc_permit();
- proc_s
chedule
();
+ proc_s
witch
();
}
else
{
ASSERT(LIST_EMPTY(&s->wait_queue));
/* The semaphore was free: lock it */
}
else
{
ASSERT(LIST_EMPTY(&s->wait_queue));
/* The semaphore was free: lock it */
- s->owner =
CurrentP
rocess;
+ s->owner =
current_p
rocess;
s->nest_count++;
proc_permit();
}
s->nest_count++;
proc_permit();
}
@@
-157,10
+156,12
@@
void sem_obtain(struct Semaphore *s)
*/
void sem_release(struct Semaphore *s)
{
*/
void sem_release(struct Semaphore *s)
{
+ Process *proc = NULL;
+
proc_forbid();
sem_verify(s);
proc_forbid();
sem_verify(s);
- ASSERT(s->owner ==
CurrentP
rocess);
+ ASSERT(s->owner ==
current_p
rocess);
/*
* Decrement nesting count and check if the semaphore
/*
* Decrement nesting count and check if the semaphore
@@
-168,8
+169,6
@@
void sem_release(struct Semaphore *s)
*/
if (--s->nest_count == 0)
{
*/
if (--s->nest_count == 0)
{
- Process *proc;
-
/* Disown semaphore */
s->owner = NULL;
/* Disown semaphore */
s->owner = NULL;
@@
-178,9
+177,10
@@
void sem_release(struct Semaphore *s)
{
s->nest_count = 1;
s->owner = proc;
{
s->nest_count = 1;
s->owner = proc;
- SCHED_ENQUEUE(proc);
}
}
}
}
-
proc_permit();
proc_permit();
+
+ if (proc)
+ ATOMIC(proc_wakeup(proc));
}
}