From 2a9e6947a1c0cefe24f8ac7f1b4997e0f661572f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 20 Sep 2008 15:34:56 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@434 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- src/chinit.c | 6 ++-- src/chthreads.c | 79 +++++++++++++++++++++++++-------------------------- src/include/threads.h | 6 ++-- 3 files changed, 46 insertions(+), 45 deletions(-) (limited to 'src') 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:
- * * @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); -- cgit v1.2.3