aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-03-27 12:33:31 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-03-27 12:33:31 +0000
commit165bcc4a0708ff3252fe73156eace36b5980dbf9 (patch)
tree713cd625a9645d3313a773f696e3ad09df58b93b /src
parentef14f74f92fb52d0028eb36b7b48b7e7c4ef52c4 (diff)
downloadChibiOS-165bcc4a0708ff3252fe73156eace36b5980dbf9.tar.gz
ChibiOS-165bcc4a0708ff3252fe73156eace36b5980dbf9.tar.bz2
ChibiOS-165bcc4a0708ff3252fe73156eace36b5980dbf9.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@249 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'src')
-rw-r--r--src/chsem.c12
-rw-r--r--src/include/semaphores.h4
-rw-r--r--src/lib/ch.cpp13
-rw-r--r--src/lib/ch.hpp76
4 files changed, 60 insertions, 45 deletions
diff --git a/src/chsem.c b/src/chsem.c
index 14b8567ad..d1199f072 100644
--- a/src/chsem.c
+++ b/src/chsem.c
@@ -188,10 +188,12 @@ void chSemSignalI(Semaphore *sp) {
* Performs atomic signal and wait operations on two semaphores.
* @param sps pointer to a \p Semaphore structure to be signaled
* @param spw pointer to a \p Semaphore structure to be wait on
- * @note The function is available only if the \p CH_USE_SEMAPHORES
+ * @return the function can return \p RDY_OK or \p RDY_RESET.
+ * @note The function is available only if the \p CH_USE_SEMSW
* option is enabled in \p chconf.h.
*/
-void chSemSignalWait(Semaphore *sps, Semaphore *spw) {
+msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw) {
+ msg_t msg;
chSysLock();
@@ -202,11 +204,15 @@ void chSemSignalWait(Semaphore *sps, Semaphore *spw) {
fifo_insert(currp, &spw->s_queue);
currp->p_wtsemp = spw;
chSchGoSleepS(PRWTSEM);
+ msg = currp->p_rdymsg;
}
- else
+ else {
chSchRescheduleS();
+ msg = RDY_OK;
+ }
chSysUnlock();
+ return msg;
}
#endif /* CH_USE_SEMSW */
diff --git a/src/include/semaphores.h b/src/include/semaphores.h
index c894629a4..45486874b 100644
--- a/src/include/semaphores.h
+++ b/src/include/semaphores.h
@@ -51,7 +51,9 @@ extern "C" {
#endif
void chSemSignal(Semaphore *sp);
void chSemSignalI(Semaphore *sp);
- void chSemSignalWait(Semaphore *sps, Semaphore *spw);
+#ifdef CH_USE_SEMSW
+ msg_t chSemSignalWait(Semaphore *sps, Semaphore *spw);
+#endif
#ifdef __cplusplus
}
#endif
diff --git a/src/lib/ch.cpp b/src/lib/ch.cpp
index ad4be5f4d..d1e739915 100644
--- a/src/lib/ch.cpp
+++ b/src/lib/ch.cpp
@@ -70,13 +70,11 @@ namespace chibios_rt {
* chibios_rt::BaseThread *
*------------------------------------------------------------------------*/
static msg_t thdstart(void *arg) {
- BaseThread *btp = (BaseThread *)arg;
- return btp->Main();
+ return ((BaseThread *)arg)->Main();
}
BaseThread::BaseThread(tprio_t prio, tmode_t mode, void *workspace, size_t wsize) {
- msg_t thdstart(void *arg);
thread_ref = chThdCreate(prio, mode, workspace, wsize, thdstart, this);
}
@@ -149,7 +147,7 @@ namespace chibios_rt {
bool BaseThread::IsPendingMessage(void) {
- return chMsgIsPendingI(thread_ref);
+ return chMsgIsPendingI(currp);
}
#endif /* CH_USE_MESSAGES */
@@ -188,6 +186,13 @@ namespace chibios_rt {
chSemSignal(&sem);
}
+
+#ifdef CH_USE_SEMSW
+ msg_t Semaphore::SignalWait(Semaphore *ssem, Semaphore *wsem) {
+
+ return chSemSignalWait(&ssem->sem, &wsem->sem);
+ }
+#endif /* CH_USE_SEMSW */
#endif /* CH_USE_SEMAPHORES */
#ifdef CH_USE_MUTEXES
diff --git a/src/lib/ch.hpp b/src/lib/ch.hpp
index 9f46b757b..d9fffc229 100644
--- a/src/lib/ch.hpp
+++ b/src/lib/ch.hpp
@@ -92,40 +92,6 @@ namespace chibios_rt {
* function /p Main().
*/
class BaseThread {
- protected:
- /**
- * Thread exit.
- */
-// __attribute__((noreturn))
- void Exit(msg_t msg);
-
- /**
- * Change thread priority.
- */
- void SetPriority(tprio_t newprio);
-
-#ifdef CH_USE_MESSAGES
- /**
- * Waits for a message and returns it.
- */
- msg_t WaitMessage(void);
-
- /**
- * Returns an enqueued message or /p NULL.
- */
- msg_t GetMessage(void);
-
- /**
- * Releases the next message in queue with a reply.
- */
- void ReleaseMessage(msg_t msg);
-
- /**
- * Returns true if there is at least one message in queue.
- */
- bool IsPendingMessage(void);
-#endif /* CH_USE_MESSAGES */
-
public:
::Thread *thread_ref;
@@ -134,6 +100,11 @@ namespace chibios_rt {
*/
BaseThread(tprio_t prio, tmode_t mode, void *workspace, size_t wsize);
+ /**
+ * Thread exit.
+ */
+ static void Exit(msg_t msg);
+
#ifdef CH_USE_WAITEXIT
/**
* Synchronization on Thread exit.
@@ -148,6 +119,11 @@ namespace chibios_rt {
void Resume(void);
#endif /* CH_USE_RESUME */
+ /**
+ * Change thread priority.
+ */
+ static void SetPriority(tprio_t newprio);
+
#ifdef CH_USE_TERMINATE
/**
* Requests thread termination.
@@ -159,13 +135,13 @@ namespace chibios_rt {
/**
* Suspends the thread execution for the specified number of system ticks.
*/
- void Sleep(systime_t n);
+ static void Sleep(systime_t n);
#ifdef CH_USE_SYSTEMTIME
/**
* Suspends the thread execution until the specified time arrives.
*/
- void SleepUntil(systime_t time);
+ static void SleepUntil(systime_t time);
#endif /* CH_USE_SYSTEMTIME */
#endif /* CH_USE_SLEEP */
@@ -174,12 +150,31 @@ namespace chibios_rt {
* Sends a message to the thread and returns the answer.
*/
msg_t SendMessage(msg_t msg);
+
+ /**
+ * Waits for a message and returns it.
+ */
+ static msg_t WaitMessage(void);
+
+ /**
+ * Returns an enqueued message or /p NULL.
+ */
+ static msg_t GetMessage(void);
+
+ /**
+ * Releases the next message in queue with a reply.
+ */
+ static void ReleaseMessage(msg_t msg);
+
+ /**
+ * Returns true if there is at least one message in queue.
+ */
+ static bool IsPendingMessage(void);
#endif /* CH_USE_MESSAGES */
/**
* Thread body function.
*/
-// __attribute__((naked))
virtual msg_t Main(void);
};
@@ -217,6 +212,13 @@ namespace chibios_rt {
* Signal operation on the semaphore.
*/
void Signal(void);
+
+#ifdef CH_USE_SEMSW
+ /**
+ * Atomic signal and wait operations.
+ */
+ msg_t SignalWait(Semaphore *ssem, Semaphore *wsem);
+#endif /* CH_USE_SEMSW */
};
#endif /* CH_USE_SEMAPHORES */