aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/chinit.c3
-rw-r--r--src/chthreads.c39
-rw-r--r--src/include/threads.h2
3 files changed, 38 insertions, 6 deletions
diff --git a/src/chinit.c b/src/chinit.c
index ec7626e6a..5b2c0cd24 100644
--- a/src/chinit.c
+++ b/src/chinit.c
@@ -55,7 +55,8 @@ void chSysInit(void) {
* serve interrupts in its context while keeping the lowest energy saving
* mode compatible with the system status.
*/
- chThdCreate(IDLEPRIO, 0, waIdleThread, sizeof(waIdleThread), (tfunc_t)_IdleThread, NULL);
+ chThdCreateFast(IDLEPRIO, waIdleThread,
+ sizeof(waIdleThread), (tfunc_t)_IdleThread);
}
/**
diff --git a/src/chthreads.c b/src/chthreads.c
index 33c75dd45..d12bced10 100644
--- a/src/chthreads.c
+++ b/src/chthreads.c
@@ -62,9 +62,8 @@ static void memfill(uint8_t *p, uint32_t n, uint8_t v) {
/**
* Creates a new thread.
* @param prio the priority level for the new thread. Usually the threads are
- * created with priority \p NORMALPRIO (128), priorities
- * can range from \p LOWPRIO (1) to \p HIGHPRIO
- * (255).
+ * 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>
@@ -106,9 +105,7 @@ Thread *chThdCreate(tprio_t prio, tmode_t mode, void *workspace,
else {
#endif
chSysLock();
-
chSchWakeupS(tp, RDY_OK);
-
chSysUnlock();
#ifdef CH_USE_RESUME
}
@@ -117,6 +114,38 @@ Thread *chThdCreate(tprio_t prio, tmode_t mode, void *workspace,
}
/**
+ * 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.
+ * @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 *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
+ init_thread(prio, 0, tp);
+ SETUP_CONTEXT(workspace, wsize, pf, NULL);
+ chSysLock();
+ chSchWakeupS(tp, RDY_OK);
+ chSysUnlock();
+ return tp;
+}
+
+/**
* Changes the thread priority, reschedules if necessary.
* @param newprio the new priority of the invoking thread
*/
diff --git a/src/include/threads.h b/src/include/threads.h
index 297c56a68..5bfd51423 100644
--- a/src/include/threads.h
+++ b/src/include/threads.h
@@ -170,6 +170,8 @@ extern "C" {
#endif
Thread *chThdCreate(tprio_t prio, tmode_t mode, void *workspace,
size_t wsize, tfunc_t pf, void *arg);
+ Thread *chThdCreateFast(tprio_t prio, void *workspace,
+ size_t wsize, tfunc_t pf);
void chThdSetPriority(tprio_t newprio);
void chThdExit(msg_t msg);
#ifdef CH_USE_RESUME