aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-09-20 15:34:56 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2008-09-20 15:34:56 +0000
commit2a9e6947a1c0cefe24f8ac7f1b4997e0f661572f (patch)
tree487e1efe05d2a1a8b6c60a9f773fe62bc4e04ac8 /src
parent8248aca2825c3650d0aeb43bb999b23fd2997804 (diff)
downloadChibiOS-2a9e6947a1c0cefe24f8ac7f1b4997e0f661572f.tar.gz
ChibiOS-2a9e6947a1c0cefe24f8ac7f1b4997e0f661572f.tar.bz2
ChibiOS-2a9e6947a1c0cefe24f8ac7f1b4997e0f661572f.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@434 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'src')
-rw-r--r--src/chinit.c6
-rw-r--r--src/chthreads.c79
-rw-r--r--src/include/threads.h6
3 files changed, 46 insertions, 45 deletions
diff --git a/src/chinit.c b/src/chinit.c
index 5e6788693..0063fa458 100644
--- a/src/chinit.c
+++ b/src/chinit.c
@@ -49,7 +49,7 @@ void chSysInit(void) {
/*
* Now this instructions flow becomes the main thread.
*/
- init_thread(NORMALPRIO, 0, &mainthread);
+ init_thread(NORMALPRIO, &mainthread);
mainthread.p_state = PRCURR;
currp = &mainthread;
@@ -61,8 +61,8 @@ void chSysInit(void) {
* serve interrupts in its context while keeping the lowest energy saving
* mode compatible with the system status.
*/
- chThdCreateFast(IDLEPRIO, waIdleThread,
- sizeof(waIdleThread), (tfunc_t)_IdleThread);
+ chThdCreateFast(IDLEPRIO, waIdleThread, sizeof(waIdleThread),
+ (tfunc_t)_IdleThread);
}
/**
diff --git a/src/chthreads.c b/src/chthreads.c
index a936fb6dc..e98bb725f 100644
--- a/src/chthreads.c
+++ b/src/chthreads.c
@@ -27,12 +27,13 @@
/*
* Initializes a thread structure.
*/
-void init_thread(tprio_t prio, tmode_t mode, Thread *tp) {
+void init_thread(tprio_t prio, Thread *tp) {
static tid_t nextid = 0;
tp->p_tid = nextid++;
- tp->p_flags = mode;
+ tp->p_flags = 0;
tp->p_prio = prio;
+ tp->p_state = PRSUSPENDED;
#ifdef CH_USE_MUTEXES
/* realprio is the thread's own, non-inherited, priority */
tp->p_realprio = prio;
@@ -64,23 +65,12 @@ static void memfill(uint8_t *p, uint32_t n, uint8_t v) {
#endif
/**
- * Creates a new thread.
+ * Initializes a new thread.
+ * The new thread is initialized but not inserted in the ready list, the
+ * initial state is \p PRSUSPENDED.
* @param prio the priority level for the new thread. Usually the threads are
* created with priority \p NORMALPRIO, priorities
* can range from \p LOWPRIO to \p HIGHPRIO.
- * @param mode the creation option flags for the thread. The following options
- * can be OR'ed in this parameter:<br>
- * <ul>
- * <li>\p P_SUSPENDED, the thread is created in the
- * \p PRSUSPENDED state and a subsequent call to
- * \p chThdResume() will make it ready for
- * execution.</li>
- * <li>\p P_TERMINATED, this flag is usually set
- * by the \p chThdTerminate() function and it is not
- * normally used as parameter for this function. The
- * result would be to create a thread with a termination
- * request already pending.</li>
- * </ul>
* @param workspace pointer to a working area dedicated to the thread stack
* @param wsize size of the working area.
* @param pf the thread function. Returning from this function automatically
@@ -90,31 +80,47 @@ static void memfill(uint8_t *p, uint32_t n, uint8_t v) {
* thread into the working space area.
* @note A thread can terminate by calling \p chThdExit() or by simply
* returning from its main function.
+ * @note This function can be used to start a thead from within an interrupt
+ * handler by manually making it ready with \p chSchReadyI().
*/
-Thread *chThdCreate(tprio_t prio, tmode_t mode, void *workspace,
- size_t wsize, tfunc_t pf, void *arg) {
+Thread *chThdInit(tprio_t prio, void *workspace,
+ size_t wsize, tfunc_t pf, void *arg) {
/* thread structure is layed out in the lower part of the thread workspace */
Thread *tp = workspace;
chDbgAssert((wsize >= UserStackSize(0)) && (prio <= HIGHPRIO) &&
(workspace != NULL) && (pf != NULL),
- "chthreads.c, chThdCreate()");
+ "chthreads.c, chThdInit()");
#ifdef CH_USE_DEBUG
memfill(workspace, wsize, MEM_FILL_PATTERN);
#endif
SETUP_CONTEXT(workspace, wsize, pf, arg);
- init_thread(prio, mode, tp);
-#ifdef CH_USE_RESUME
- if (tp->p_flags & P_SUSPENDED)
- tp->p_state = PRSUSPENDED;
- else {
-#endif
- chSysLock();
- chSchWakeupS(tp, RDY_OK);
- chSysUnlock();
-#ifdef CH_USE_RESUME
- }
-#endif
+ init_thread(prio, tp);
+ return tp;
+}
+
+/**
+ * Creates a new thread.
+ * @param prio the priority level for the new thread. Usually the threads are
+ * created with priority \p NORMALPRIO, priorities
+ * can range from \p LOWPRIO to \p HIGHPRIO.
+ * @param workspace pointer to a working area dedicated to the thread stack
+ * @param wsize size of the working area.
+ * @param pf the thread function. Returning from this function automatically
+ * terminates the thread.
+ * @param arg an argument passed to the thread function. It can be \p NULL.
+ * @return the pointer to the \p Thread structure allocated for the
+ * thread into the working space area.
+ * @note A thread can terminate by calling \p chThdExit() or by simply
+ * returning from its main function.
+ */
+Thread *chThdCreate(tprio_t prio, void *workspace,
+ size_t wsize, tfunc_t pf, void *arg) {
+
+ Thread *tp = chThdInit(prio, workspace, wsize, pf, arg);
+ chSysLock();
+ chSchWakeupS(tp, RDY_OK);
+ chSysUnlock();
return tp;
}
@@ -131,19 +137,12 @@ Thread *chThdCreate(tprio_t prio, tmode_t mode, void *workspace,
* thread into the working space area.
* @note A thread can terminate by calling \p chThdExit() or by simply
* returning from its main function.
+ * @deprecated
*/
Thread *chThdCreateFast(tprio_t prio, void *workspace,
size_t wsize, tfunc_t pf) {
- Thread *tp = workspace;
- chDbgAssert((wsize >= UserStackSize(0)) && (prio <= HIGHPRIO) &&
- (workspace != NULL) && (pf != NULL),
- "chthreads.c, chThdCreateFast()");
-#ifdef CH_USE_DEBUG
- memfill(workspace, wsize, MEM_FILL_PATTERN);
-#endif
- SETUP_CONTEXT(workspace, wsize, pf, NULL);
- init_thread(prio, 0, tp);
+ Thread *tp = chThdInit(prio, workspace, wsize, pf, NULL);
chSysLock();
chSchWakeupS(tp, RDY_OK);
chSysUnlock();
diff --git a/src/include/threads.h b/src/include/threads.h
index 3e70439ac..d630ca16c 100644
--- a/src/include/threads.h
+++ b/src/include/threads.h
@@ -153,7 +153,7 @@ struct Thread {
#define ABSPRIO 255
/* Not an API, don't use into the application code.*/
-void init_thread(tprio_t prio, tmode_t mode, Thread *tp);
+void init_thread(tprio_t prio, Thread *tp);
/** Thread function.*/
typedef msg_t (*tfunc_t)(void *);
@@ -164,7 +164,9 @@ typedef msg_t (*tfunc_t)(void *);
#ifdef __cplusplus
extern "C" {
#endif
- Thread *chThdCreate(tprio_t prio, tmode_t mode, void *workspace,
+ Thread *chThdInit(tprio_t prio, void *workspace,
+ size_t wsize, tfunc_t pf, void *arg);
+ Thread *chThdCreate(tprio_t prio, void *workspace,
size_t wsize, tfunc_t pf, void *arg);
Thread *chThdCreateFast(tprio_t prio, void *workspace,
size_t wsize, tfunc_t pf);