From 0d96f5c78e54d267ef1ca230fe20af1ca090e1d6 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 16 Jun 2013 12:21:30 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5859 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chthreads.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chthreads.c') diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 9f6973c90..7652cbfb1 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -302,7 +302,7 @@ void chThdSleep(systime_t time) { void chThdSleepUntil(systime_t time) { chSysLock(); - if ((time -= chTimeNow()) > 0) + if ((time -= chVTGetSystemTimeI()) > 0) chThdSleepS(time); chSysUnlock(); } -- cgit v1.2.3 From 2e4ba09bb54f415e7f8fd66f4ccddbf421612820 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 16 Jun 2013 16:12:33 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5860 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chthreads.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chthreads.c') diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 7652cbfb1..37d25eb7b 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -364,7 +364,7 @@ void chThdExitS(msg_t msg) { THREAD_EXT_EXIT_HOOK(tp); #endif #if CH_USE_WAITEXIT - while (notempty(&tp->p_waiting)) + while (list_notempty(&tp->p_waiting)) chSchReadyI(list_remove(&tp->p_waiting)); #endif #if CH_USE_REGISTRY -- cgit v1.2.3 From 43a7a0820fa1873dba8e77d7890b614fb5dd93dd Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 16 Jun 2013 16:48:40 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5862 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chthreads.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'os/kernel/src/chthreads.c') diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 37d25eb7b..9f176c6a0 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -56,6 +56,30 @@ #include "ch.h" +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /** * @brief Initializes a thread structure. * @note This is an internal functions, do not use it in application code. -- cgit v1.2.3 From 84e044f176cee7c6946b24c36c90f63534b5b369 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 19 Jul 2013 12:22:31 +0000 Subject: Renamed Thread to thread_t. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5995 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chthreads.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'os/kernel/src/chthreads.c') diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 9f176c6a0..bc161ba52 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -90,7 +90,7 @@ * * @notapi */ -Thread *_thread_init(Thread *tp, tprio_t prio) { +thread_t *_thread_init(thread_t *tp, tprio_t prio) { tp->p_prio = prio; tp->p_state = THD_STATE_SUSPENDED; @@ -166,15 +166,16 @@ void _thread_memfill(uint8_t *startp, uint8_t *endp, uint8_t v) { * @param[in] pf the thread function * @param[in] arg an argument passed to the thread function. It can be * @p NULL. - * @return The pointer to the @p Thread structure allocated for + * @return The pointer to the @p thread_t structure allocated for * the thread into the working space area. * * @iclass */ -Thread *chThdCreateI(void *wsp, size_t size, +thread_t *chThdCreateI(void *wsp, size_t size, tprio_t prio, tfunc_t pf, void *arg) { - /* Thread structure is laid out in the lower part of the thread workspace.*/ - Thread *tp = wsp; + /* The thread structure is laid out in the lower part of the thread + workspace.*/ + thread_t *tp = wsp; chDbgCheckClassI(); @@ -196,20 +197,20 @@ Thread *chThdCreateI(void *wsp, size_t size, * @param[in] pf the thread function * @param[in] arg an argument passed to the thread function. It can be * @p NULL. - * @return The pointer to the @p Thread structure allocated for + * @return The pointer to the @p thread_t structure allocated for * the thread into the working space area. * * @api */ -Thread *chThdCreateStatic(void *wsp, size_t size, - tprio_t prio, tfunc_t pf, void *arg) { - Thread *tp; +thread_t *chThdCreateStatic(void *wsp, size_t size, + tprio_t prio, tfunc_t pf, void *arg) { + thread_t *tp; #if CH_DBG_FILL_THREADS _thread_memfill((uint8_t *)wsp, - (uint8_t *)wsp + sizeof(Thread), + (uint8_t *)wsp + sizeof(thread_t), CH_THREAD_FILL_VALUE); - _thread_memfill((uint8_t *)wsp + sizeof(Thread), + _thread_memfill((uint8_t *)wsp + sizeof(thread_t), (uint8_t *)wsp + size, CH_STACK_FILL_VALUE); #endif @@ -264,7 +265,7 @@ tprio_t chThdSetPriority(tprio_t newprio) { * * @api */ -Thread *chThdResume(Thread *tp) { +thread_t *chThdResume(thread_t *tp) { chSysLock(); chDbgAssert(tp->p_state == THD_STATE_SUSPENDED, @@ -287,7 +288,7 @@ Thread *chThdResume(Thread *tp) { * * @api */ -void chThdTerminate(Thread *tp) { +void chThdTerminate(thread_t *tp) { chSysLock(); tp->p_flags |= THD_TERMINATE; @@ -381,7 +382,7 @@ void chThdExit(msg_t msg) { * @sclass */ void chThdExitS(msg_t msg) { - Thread *tp = currp; + thread_t *tp = currp; tp->p_u.exitcode = msg; #if defined(THREAD_EXT_EXIT_HOOK) @@ -423,7 +424,7 @@ void chThdExitS(msg_t msg) { * @pre The configuration option @p CH_USE_WAITEXIT must be enabled in * order to use this function. * @post Enabling @p chThdWait() requires 2-4 (depending on the - * architecture) extra bytes in the @p Thread structure. + * architecture) extra bytes in the @p thread_t structure. * @post After invoking @p chThdWait() the thread pointer becomes invalid * and must not be used as parameter for further system calls. * @note If @p CH_USE_DYNAMIC is not specified this function just waits for @@ -434,7 +435,7 @@ void chThdExitS(msg_t msg) { * * @api */ -msg_t chThdWait(Thread *tp) { +msg_t chThdWait(thread_t *tp) { msg_t msg; chDbgCheck(tp != NULL, "chThdWait"); -- cgit v1.2.3 From 390ed322cb8f40cb9250021cde5f48acb928d291 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 20 Jul 2013 07:24:12 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6001 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chthreads.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chthreads.c') diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index bc161ba52..47f53e10d 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -280,7 +280,7 @@ thread_t *chThdResume(thread_t *tp) { * @brief Requests a thread termination. * @pre The target thread must be written to invoke periodically * @p chThdShouldTerminate() and terminate cleanly if it returns - * @p TRUE. + * @p true. * @post The specified thread will terminate after detecting the termination * condition. * @@ -400,7 +400,7 @@ void chThdExitS(msg_t msg) { #endif chSchGoSleepS(THD_STATE_FINAL); /* The thread never returns here.*/ - chDbgAssert(FALSE, "chThdExitS(), #1", "zombies apocalypse"); + chDbgAssert(false, "chThdExitS(), #1", "zombies apocalypse"); } #if CH_USE_WAITEXIT || defined(__DOXYGEN__) -- cgit v1.2.3 From 49d71a01abeefa000a4cd7a556052d826b096d49 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 20 Jul 2013 10:12:44 +0000 Subject: Renamed or added prefix to all hernel configuration options. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6010 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chthreads.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'os/kernel/src/chthreads.c') diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 47f53e10d..17eeb763b 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -49,7 +49,7 @@ * . * The threads subsystem is implicitly included in kernel however * some of its part may be excluded by disabling them in @p chconf.h, - * see the @p CH_USE_WAITEXIT and @p CH_USE_DYNAMIC configuration + * see the @p CH_CFG_USE_WAITEXIT and @p CH_CFG_USE_DYNAMIC configuration * options. * @{ */ @@ -95,37 +95,37 @@ thread_t *_thread_init(thread_t *tp, tprio_t prio) { tp->p_prio = prio; tp->p_state = THD_STATE_SUSPENDED; tp->p_flags = THD_MEM_MODE_STATIC; -#if CH_TIME_QUANTUM > 0 - tp->p_preempt = CH_TIME_QUANTUM; +#if CH_CFG_TIME_QUANTUM > 0 + tp->p_preempt = CH_CFG_TIME_QUANTUM; #endif -#if CH_USE_MUTEXES +#if CH_CFG_USE_MUTEXES tp->p_realprio = prio; tp->p_mtxlist = NULL; #endif -#if CH_USE_EVENTS +#if CH_CFG_USE_EVENTS tp->p_epending = 0; #endif #if CH_DBG_THREADS_PROFILING tp->p_time = 0; #endif -#if CH_USE_DYNAMIC +#if CH_CFG_USE_DYNAMIC tp->p_refs = 1; #endif -#if CH_USE_REGISTRY +#if CH_CFG_USE_REGISTRY tp->p_name = NULL; REG_INSERT(tp); #endif -#if CH_USE_WAITEXIT +#if CH_CFG_USE_WAITEXIT list_init(&tp->p_waiting); #endif -#if CH_USE_MESSAGES +#if CH_CFG_USE_MESSAGES queue_init(&tp->p_msgqueue); #endif #if CH_DBG_ENABLE_STACK_CHECK tp->p_stklimit = (stkalign_t *)(tp + 1); #endif -#if defined(THREAD_EXT_INIT_HOOK) - THREAD_EXT_INIT_HOOK(tp); +#if defined(CH_CFG_THREAD_INIT_HOOK) + CH_CFG_THREAD_INIT_HOOK(tp); #endif return tp; } @@ -238,7 +238,7 @@ tprio_t chThdSetPriority(tprio_t newprio) { chDbgCheck(newprio <= HIGHPRIO, "chThdSetPriority"); chSysLock(); -#if CH_USE_MUTEXES +#if CH_CFG_USE_MUTEXES oldprio = currp->p_realprio; if ((currp->p_prio == currp->p_realprio) || (newprio > currp->p_prio)) currp->p_prio = newprio; @@ -385,14 +385,14 @@ void chThdExitS(msg_t msg) { thread_t *tp = currp; tp->p_u.exitcode = msg; -#if defined(THREAD_EXT_EXIT_HOOK) - THREAD_EXT_EXIT_HOOK(tp); +#if defined(CH_CFG_THREAD_EXIT_HOOK) + CH_CFG_THREAD_EXIT_HOOK(tp); #endif -#if CH_USE_WAITEXIT +#if CH_CFG_USE_WAITEXIT while (list_notempty(&tp->p_waiting)) chSchReadyI(list_remove(&tp->p_waiting)); #endif -#if CH_USE_REGISTRY +#if CH_CFG_USE_REGISTRY /* Static threads are immediately removed from the registry because there is no memory to recover.*/ if ((tp->p_flags & THD_MEM_MODE_MASK) == THD_MEM_MODE_STATIC) @@ -403,7 +403,7 @@ void chThdExitS(msg_t msg) { chDbgAssert(false, "chThdExitS(), #1", "zombies apocalypse"); } -#if CH_USE_WAITEXIT || defined(__DOXYGEN__) +#if CH_CFG_USE_WAITEXIT || defined(__DOXYGEN__) /** * @brief Blocks the execution of the invoking thread until the specified * thread terminates then the exit code is returned. @@ -421,13 +421,13 @@ void chThdExitS(msg_t msg) { * - If the thread was spawned by @p chThdCreateFromMemoryPool() * then the working area is returned to the owning memory pool. * . - * @pre The configuration option @p CH_USE_WAITEXIT must be enabled in + * @pre The configuration option @p CH_CFG_USE_WAITEXIT must be enabled in * order to use this function. * @post Enabling @p chThdWait() requires 2-4 (depending on the * architecture) extra bytes in the @p thread_t structure. * @post After invoking @p chThdWait() the thread pointer becomes invalid * and must not be used as parameter for further system calls. - * @note If @p CH_USE_DYNAMIC is not specified this function just waits for + * @note If @p CH_CFG_USE_DYNAMIC is not specified this function just waits for * the thread termination, no memory allocators are involved. * * @param[in] tp pointer to the thread @@ -442,7 +442,7 @@ msg_t chThdWait(thread_t *tp) { chSysLock(); chDbgAssert(tp != currp, "chThdWait(), #1", "waiting self"); -#if CH_USE_DYNAMIC +#if CH_CFG_USE_DYNAMIC chDbgAssert(tp->p_refs > 0, "chThdWait(), #2", "not referenced"); #endif if (tp->p_state != THD_STATE_FINAL) { @@ -451,11 +451,11 @@ msg_t chThdWait(thread_t *tp) { } msg = tp->p_u.exitcode; chSysUnlock(); -#if CH_USE_DYNAMIC +#if CH_CFG_USE_DYNAMIC chThdRelease(tp); #endif return msg; } -#endif /* CH_USE_WAITEXIT */ +#endif /* CH_CFG_USE_WAITEXIT */ /** @} */ -- cgit v1.2.3 From 40f413d3c97a7694703938cd031ce15912b29ff7 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 24 Jul 2013 14:54:26 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6025 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chthreads.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'os/kernel/src/chthreads.c') diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 17eeb763b..9017a59b7 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -93,8 +93,8 @@ thread_t *_thread_init(thread_t *tp, tprio_t prio) { tp->p_prio = prio; - tp->p_state = THD_STATE_SUSPENDED; - tp->p_flags = THD_MEM_MODE_STATIC; + tp->p_state = CH_STATE_SUSPENDED; + tp->p_flags = CH_FLAG_MODE_STATIC; #if CH_CFG_TIME_QUANTUM > 0 tp->p_preempt = CH_CFG_TIME_QUANTUM; #endif @@ -150,7 +150,7 @@ void _thread_memfill(uint8_t *startp, uint8_t *endp, uint8_t v) { /** * @brief Creates a new thread into a static memory area. * @details The new thread is initialized but not inserted in the ready list, - * the initial state is @p THD_STATE_SUSPENDED. + * the initial state is @p CH_STATE_SUSPENDED. * @post The initialized thread can be subsequently started by invoking * @p chThdResume(), @p chThdResumeI() or @p chSchWakeupS() * depending on the execution context. @@ -255,7 +255,7 @@ tprio_t chThdSetPriority(tprio_t newprio) { /** * @brief Resumes a suspended thread. * @pre The specified thread pointer must refer to an initialized thread - * in the @p THD_STATE_SUSPENDED state. + * in the @p CH_STATE_SUSPENDED state. * @post The specified thread is immediately started or put in the ready * list depending on the relative priority levels. * @note Use this function to start threads created with @p chThdCreateI(). @@ -268,9 +268,9 @@ tprio_t chThdSetPriority(tprio_t newprio) { thread_t *chThdResume(thread_t *tp) { chSysLock(); - chDbgAssert(tp->p_state == THD_STATE_SUSPENDED, + chDbgAssert(tp->p_state == CH_STATE_SUSPENDED, "chThdResume(), #1", - "thread not in THD_STATE_SUSPENDED state"); + "thread not in CH_STATE_SUSPENDED state"); chSchWakeupS(tp, RDY_OK); chSysUnlock(); return tp; @@ -291,7 +291,7 @@ thread_t *chThdResume(thread_t *tp) { void chThdTerminate(thread_t *tp) { chSysLock(); - tp->p_flags |= THD_TERMINATE; + tp->p_flags |= CH_FLAG_TERMINATE; chSysUnlock(); } @@ -348,7 +348,7 @@ void chThdYield(void) { /** * @brief Terminates the current thread. - * @details The thread goes in the @p THD_STATE_FINAL state holding the + * @details The thread goes in the @p CH_STATE_FINAL state holding the * specified exit status code, other threads can retrieve the * exit status code by invoking the function @p chThdWait(). * @post Eventual code after this function will never be executed, @@ -369,7 +369,7 @@ void chThdExit(msg_t msg) { /** * @brief Terminates the current thread. - * @details The thread goes in the @p THD_STATE_FINAL state holding the + * @details The thread goes in the @p CH_STATE_FINAL state holding the * specified exit status code, other threads can retrieve the * exit status code by invoking the function @p chThdWait(). * @post Eventual code after this function will never be executed, @@ -395,10 +395,10 @@ void chThdExitS(msg_t msg) { #if CH_CFG_USE_REGISTRY /* Static threads are immediately removed from the registry because there is no memory to recover.*/ - if ((tp->p_flags & THD_MEM_MODE_MASK) == THD_MEM_MODE_STATIC) + if ((tp->p_flags & CH_FLAG_MODE_MASK) == CH_FLAG_MODE_STATIC) REG_REMOVE(tp); #endif - chSchGoSleepS(THD_STATE_FINAL); + chSchGoSleepS(CH_STATE_FINAL); /* The thread never returns here.*/ chDbgAssert(false, "chThdExitS(), #1", "zombies apocalypse"); } @@ -445,9 +445,9 @@ msg_t chThdWait(thread_t *tp) { #if CH_CFG_USE_DYNAMIC chDbgAssert(tp->p_refs > 0, "chThdWait(), #2", "not referenced"); #endif - if (tp->p_state != THD_STATE_FINAL) { + if (tp->p_state != CH_STATE_FINAL) { list_insert(currp, &tp->p_waiting); - chSchGoSleepS(THD_STATE_WTEXIT); + chSchGoSleepS(CH_STATE_WTEXIT); } msg = tp->p_u.exitcode; chSysUnlock(); -- cgit v1.2.3 From 0cb6bc9b9d260beb05fcc9e2ec4d72f0ba621b71 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 28 Jul 2013 12:15:57 +0000 Subject: RT measurements unit added. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6036 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chthreads.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chthreads.c') diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 9017a59b7..b707b4562 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -327,7 +327,7 @@ void chThdSleep(systime_t time) { void chThdSleepUntil(systime_t time) { chSysLock(); - if ((time -= chVTGetSystemTimeI()) > 0) + if ((time -= chVTGetSystemTimeX()) > 0) chThdSleepS(time); chSysUnlock(); } -- cgit v1.2.3 From ceea042aaf3e373b598b3295c256feaef4e4236c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 31 Jul 2013 12:26:02 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6056 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chthreads.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'os/kernel/src/chthreads.c') diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index b707b4562..ff6e5e597 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -124,6 +124,9 @@ thread_t *_thread_init(thread_t *tp, tprio_t prio) { #if CH_DBG_ENABLE_STACK_CHECK tp->p_stklimit = (stkalign_t *)(tp + 1); #endif +#if CH_DBG_STATISTICS || defined(__DOXYGEN__) + chTMStartMeasurementX(&tp->p_stats); +#endif #if defined(CH_CFG_THREAD_INIT_HOOK) CH_CFG_THREAD_INIT_HOOK(tp); #endif -- cgit v1.2.3 From 649decd10516a30886d05f5afca3d425d836db0e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 10 Aug 2013 10:17:45 +0000 Subject: Cleanup debug module. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6120 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chthreads.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chthreads.c') diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index ff6e5e597..a18e82005 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -212,10 +212,10 @@ thread_t *chThdCreateStatic(void *wsp, size_t size, #if CH_DBG_FILL_THREADS _thread_memfill((uint8_t *)wsp, (uint8_t *)wsp + sizeof(thread_t), - CH_THREAD_FILL_VALUE); + CH_DBG_THREAD_FILL_VALUE); _thread_memfill((uint8_t *)wsp + sizeof(thread_t), (uint8_t *)wsp + size, - CH_STACK_FILL_VALUE); + CH_DBG_STACK_FILL_VALUE); #endif chSysLock(); chSchWakeupS(tp = chThdCreateI(wsp, size, prio, pf, arg), RDY_OK); -- cgit v1.2.3 From eb7a1a15b23341693864c6fc13ac5eab5c1d6122 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 10 Aug 2013 14:50:32 +0000 Subject: Removed 2nd parameter to assertion and check macros. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6122 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chthreads.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'os/kernel/src/chthreads.c') diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index a18e82005..073b6eed7 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -183,8 +183,7 @@ thread_t *chThdCreateI(void *wsp, size_t size, chDbgCheckClassI(); chDbgCheck((wsp != NULL) && (size >= THD_WA_SIZE(0)) && - (prio <= HIGHPRIO) && (pf != NULL), - "chThdCreateI"); + (prio <= HIGHPRIO) && (pf != NULL)); SETUP_CONTEXT(wsp, size, pf, arg); return _thread_init(tp, prio); } @@ -238,7 +237,7 @@ thread_t *chThdCreateStatic(void *wsp, size_t size, tprio_t chThdSetPriority(tprio_t newprio) { tprio_t oldprio; - chDbgCheck(newprio <= HIGHPRIO, "chThdSetPriority"); + chDbgCheck(newprio <= HIGHPRIO); chSysLock(); #if CH_CFG_USE_MUTEXES @@ -272,7 +271,6 @@ thread_t *chThdResume(thread_t *tp) { chSysLock(); chDbgAssert(tp->p_state == CH_STATE_SUSPENDED, - "chThdResume(), #1", "thread not in CH_STATE_SUSPENDED state"); chSchWakeupS(tp, RDY_OK); chSysUnlock(); @@ -312,7 +310,7 @@ void chThdTerminate(thread_t *tp) { */ void chThdSleep(systime_t time) { - chDbgCheck(time != TIME_IMMEDIATE, "chThdSleep"); + chDbgCheck(time != TIME_IMMEDIATE); chSysLock(); chThdSleepS(time); @@ -403,7 +401,7 @@ void chThdExitS(msg_t msg) { #endif chSchGoSleepS(CH_STATE_FINAL); /* The thread never returns here.*/ - chDbgAssert(false, "chThdExitS(), #1", "zombies apocalypse"); + chDbgAssert(false, "zombies apocalypse"); } #if CH_CFG_USE_WAITEXIT || defined(__DOXYGEN__) @@ -441,12 +439,12 @@ void chThdExitS(msg_t msg) { msg_t chThdWait(thread_t *tp) { msg_t msg; - chDbgCheck(tp != NULL, "chThdWait"); + chDbgCheck(tp != NULL); chSysLock(); - chDbgAssert(tp != currp, "chThdWait(), #1", "waiting self"); + chDbgAssert(tp != currp, "waiting self"); #if CH_CFG_USE_DYNAMIC - chDbgAssert(tp->p_refs > 0, "chThdWait(), #2", "not referenced"); + chDbgAssert(tp->p_refs > 0, "not referenced"); #endif if (tp->p_state != CH_STATE_FINAL) { list_insert(currp, &tp->p_waiting); -- cgit v1.2.3 From a1435e018bfc9919cb76b1356509ecc883767fb4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 10 Aug 2013 14:51:16 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6123 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chthreads.c | 462 ---------------------------------------------- 1 file changed, 462 deletions(-) delete mode 100644 os/kernel/src/chthreads.c (limited to 'os/kernel/src/chthreads.c') diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c deleted file mode 100644 index 073b6eed7..000000000 --- a/os/kernel/src/chthreads.c +++ /dev/null @@ -1,462 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file chthreads.c - * @brief Threads code. - * - * @addtogroup threads - * @details Threads related APIs and services. - * - *

Operation mode

- * A thread is an abstraction of an independent instructions flow. - * In ChibiOS/RT a thread is represented by a "C" function owning - * a processor context, state informations and a dedicated stack - * area. In this scenario static variables are shared among all - * threads while automatic variables are local to the thread.
- * Operations defined for threads: - * - Create, a thread is started on the specified thread - * function. This operation is available in multiple variants, - * both static and dynamic. - * - Exit, a thread terminates by returning from its top - * level function or invoking a specific API, the thread can - * return a value that can be retrieved by other threads. - * - Wait, a thread waits for the termination of another - * thread and retrieves its return value. - * - Resume, a thread created in suspended state is started. - * - Sleep, the execution of a thread is suspended for the - * specified amount of time or the specified future absolute time - * is reached. - * - SetPriority, a thread changes its own priority level. - * - Yield, a thread voluntarily renounces to its time slot. - * . - * The threads subsystem is implicitly included in kernel however - * some of its part may be excluded by disabling them in @p chconf.h, - * see the @p CH_CFG_USE_WAITEXIT and @p CH_CFG_USE_DYNAMIC configuration - * options. - * @{ - */ - -#include "ch.h" - -/*===========================================================================*/ -/* Module local definitions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Initializes a thread structure. - * @note This is an internal functions, do not use it in application code. - * - * @param[in] tp pointer to the thread - * @param[in] prio the priority level for the new thread - * @return The same thread pointer passed as parameter. - * - * @notapi - */ -thread_t *_thread_init(thread_t *tp, tprio_t prio) { - - tp->p_prio = prio; - tp->p_state = CH_STATE_SUSPENDED; - tp->p_flags = CH_FLAG_MODE_STATIC; -#if CH_CFG_TIME_QUANTUM > 0 - tp->p_preempt = CH_CFG_TIME_QUANTUM; -#endif -#if CH_CFG_USE_MUTEXES - tp->p_realprio = prio; - tp->p_mtxlist = NULL; -#endif -#if CH_CFG_USE_EVENTS - tp->p_epending = 0; -#endif -#if CH_DBG_THREADS_PROFILING - tp->p_time = 0; -#endif -#if CH_CFG_USE_DYNAMIC - tp->p_refs = 1; -#endif -#if CH_CFG_USE_REGISTRY - tp->p_name = NULL; - REG_INSERT(tp); -#endif -#if CH_CFG_USE_WAITEXIT - list_init(&tp->p_waiting); -#endif -#if CH_CFG_USE_MESSAGES - queue_init(&tp->p_msgqueue); -#endif -#if CH_DBG_ENABLE_STACK_CHECK - tp->p_stklimit = (stkalign_t *)(tp + 1); -#endif -#if CH_DBG_STATISTICS || defined(__DOXYGEN__) - chTMStartMeasurementX(&tp->p_stats); -#endif -#if defined(CH_CFG_THREAD_INIT_HOOK) - CH_CFG_THREAD_INIT_HOOK(tp); -#endif - return tp; -} - -#if CH_DBG_FILL_THREADS || defined(__DOXYGEN__) -/** - * @brief Memory fill utility. - * - * @param[in] startp first address to fill - * @param[in] endp last address to fill +1 - * @param[in] v filler value - * - * @notapi - */ -void _thread_memfill(uint8_t *startp, uint8_t *endp, uint8_t v) { - - while (startp < endp) - *startp++ = v; -} -#endif /* CH_DBG_FILL_THREADS */ - -/** - * @brief Creates a new thread into a static memory area. - * @details The new thread is initialized but not inserted in the ready list, - * the initial state is @p CH_STATE_SUSPENDED. - * @post The initialized thread can be subsequently started by invoking - * @p chThdResume(), @p chThdResumeI() or @p chSchWakeupS() - * depending on the execution context. - * @note A thread can terminate by calling @p chThdExit() or by simply - * returning from its main function. - * @note Threads created using this function do not obey to the - * @p CH_DBG_FILL_THREADS debug option because it would keep - * the kernel locked for too much time. - * - * @param[out] wsp pointer to a working area dedicated to the thread stack - * @param[in] size size of the working area - * @param[in] prio the priority level for the new thread - * @param[in] pf the thread function - * @param[in] arg an argument passed to the thread function. It can be - * @p NULL. - * @return The pointer to the @p thread_t structure allocated for - * the thread into the working space area. - * - * @iclass - */ -thread_t *chThdCreateI(void *wsp, size_t size, - tprio_t prio, tfunc_t pf, void *arg) { - /* The thread structure is laid out in the lower part of the thread - workspace.*/ - thread_t *tp = wsp; - - chDbgCheckClassI(); - - chDbgCheck((wsp != NULL) && (size >= THD_WA_SIZE(0)) && - (prio <= HIGHPRIO) && (pf != NULL)); - SETUP_CONTEXT(wsp, size, pf, arg); - return _thread_init(tp, prio); -} - -/** - * @brief Creates a new thread into a static memory area. - * @note A thread can terminate by calling @p chThdExit() or by simply - * returning from its main function. - * - * @param[out] wsp pointer to a working area dedicated to the thread stack - * @param[in] size size of the working area - * @param[in] prio the priority level for the new thread - * @param[in] pf the thread function - * @param[in] arg an argument passed to the thread function. It can be - * @p NULL. - * @return The pointer to the @p thread_t structure allocated for - * the thread into the working space area. - * - * @api - */ -thread_t *chThdCreateStatic(void *wsp, size_t size, - tprio_t prio, tfunc_t pf, void *arg) { - thread_t *tp; - -#if CH_DBG_FILL_THREADS - _thread_memfill((uint8_t *)wsp, - (uint8_t *)wsp + sizeof(thread_t), - CH_DBG_THREAD_FILL_VALUE); - _thread_memfill((uint8_t *)wsp + sizeof(thread_t), - (uint8_t *)wsp + size, - CH_DBG_STACK_FILL_VALUE); -#endif - chSysLock(); - chSchWakeupS(tp = chThdCreateI(wsp, size, prio, pf, arg), RDY_OK); - chSysUnlock(); - return tp; -} - -/** - * @brief Changes the running thread priority level then reschedules if - * necessary. - * @note The function returns the real thread priority regardless of the - * current priority that could be higher than the real priority - * because the priority inheritance mechanism. - * - * @param[in] newprio the new priority level of the running thread - * @return The old priority level. - * - * @api - */ -tprio_t chThdSetPriority(tprio_t newprio) { - tprio_t oldprio; - - chDbgCheck(newprio <= HIGHPRIO); - - chSysLock(); -#if CH_CFG_USE_MUTEXES - oldprio = currp->p_realprio; - if ((currp->p_prio == currp->p_realprio) || (newprio > currp->p_prio)) - currp->p_prio = newprio; - currp->p_realprio = newprio; -#else - oldprio = currp->p_prio; - currp->p_prio = newprio; -#endif - chSchRescheduleS(); - chSysUnlock(); - return oldprio; -} - -/** - * @brief Resumes a suspended thread. - * @pre The specified thread pointer must refer to an initialized thread - * in the @p CH_STATE_SUSPENDED state. - * @post The specified thread is immediately started or put in the ready - * list depending on the relative priority levels. - * @note Use this function to start threads created with @p chThdCreateI(). - * - * @param[in] tp pointer to the thread - * @return The pointer to the thread. - * - * @api - */ -thread_t *chThdResume(thread_t *tp) { - - chSysLock(); - chDbgAssert(tp->p_state == CH_STATE_SUSPENDED, - "thread not in CH_STATE_SUSPENDED state"); - chSchWakeupS(tp, RDY_OK); - chSysUnlock(); - return tp; -} - -/** - * @brief Requests a thread termination. - * @pre The target thread must be written to invoke periodically - * @p chThdShouldTerminate() and terminate cleanly if it returns - * @p true. - * @post The specified thread will terminate after detecting the termination - * condition. - * - * @param[in] tp pointer to the thread - * - * @api - */ -void chThdTerminate(thread_t *tp) { - - chSysLock(); - tp->p_flags |= CH_FLAG_TERMINATE; - chSysUnlock(); -} - -/** - * @brief Suspends the invoking thread for the specified time. - * - * @param[in] time the delay in system ticks, the special values are - * handled as follow: - * - @a TIME_INFINITE the thread enters an infinite sleep - * state. - * - @a TIME_IMMEDIATE this value is not allowed. - * . - * - * @api - */ -void chThdSleep(systime_t time) { - - chDbgCheck(time != TIME_IMMEDIATE); - - chSysLock(); - chThdSleepS(time); - chSysUnlock(); -} - -/** - * @brief Suspends the invoking thread until the system time arrives to the - * specified value. - * - * @param[in] time absolute system time - * - * @api - */ -void chThdSleepUntil(systime_t time) { - - chSysLock(); - if ((time -= chVTGetSystemTimeX()) > 0) - chThdSleepS(time); - chSysUnlock(); -} - -/** - * @brief Yields the time slot. - * @details Yields the CPU control to the next thread in the ready list with - * equal priority, if any. - * - * @api - */ -void chThdYield(void) { - - chSysLock(); - chSchDoYieldS(); - chSysUnlock(); -} - -/** - * @brief Terminates the current thread. - * @details The thread goes in the @p CH_STATE_FINAL state holding the - * specified exit status code, other threads can retrieve the - * exit status code by invoking the function @p chThdWait(). - * @post Eventual code after this function will never be executed, - * this function never returns. The compiler has no way to - * know this so do not assume that the compiler would remove - * the dead code. - * - * @param[in] msg thread exit code - * - * @api - */ -void chThdExit(msg_t msg) { - - chSysLock(); - chThdExitS(msg); - /* The thread never returns here.*/ -} - -/** - * @brief Terminates the current thread. - * @details The thread goes in the @p CH_STATE_FINAL state holding the - * specified exit status code, other threads can retrieve the - * exit status code by invoking the function @p chThdWait(). - * @post Eventual code after this function will never be executed, - * this function never returns. The compiler has no way to - * know this so do not assume that the compiler would remove - * the dead code. - * - * @param[in] msg thread exit code - * - * @sclass - */ -void chThdExitS(msg_t msg) { - thread_t *tp = currp; - - tp->p_u.exitcode = msg; -#if defined(CH_CFG_THREAD_EXIT_HOOK) - CH_CFG_THREAD_EXIT_HOOK(tp); -#endif -#if CH_CFG_USE_WAITEXIT - while (list_notempty(&tp->p_waiting)) - chSchReadyI(list_remove(&tp->p_waiting)); -#endif -#if CH_CFG_USE_REGISTRY - /* Static threads are immediately removed from the registry because - there is no memory to recover.*/ - if ((tp->p_flags & CH_FLAG_MODE_MASK) == CH_FLAG_MODE_STATIC) - REG_REMOVE(tp); -#endif - chSchGoSleepS(CH_STATE_FINAL); - /* The thread never returns here.*/ - chDbgAssert(false, "zombies apocalypse"); -} - -#if CH_CFG_USE_WAITEXIT || defined(__DOXYGEN__) -/** - * @brief Blocks the execution of the invoking thread until the specified - * thread terminates then the exit code is returned. - * @details This function waits for the specified thread to terminate then - * decrements its reference counter, if the counter reaches zero then - * the thread working area is returned to the proper allocator.
- * The memory used by the exited thread is handled in different ways - * depending on the API that spawned the thread: - * - If the thread was spawned by @p chThdCreateStatic() or by - * @p chThdCreateI() then nothing happens and the thread working - * area is not released or modified in any way. This is the - * default, totally static, behavior. - * - If the thread was spawned by @p chThdCreateFromHeap() then - * the working area is returned to the system heap. - * - If the thread was spawned by @p chThdCreateFromMemoryPool() - * then the working area is returned to the owning memory pool. - * . - * @pre The configuration option @p CH_CFG_USE_WAITEXIT must be enabled in - * order to use this function. - * @post Enabling @p chThdWait() requires 2-4 (depending on the - * architecture) extra bytes in the @p thread_t structure. - * @post After invoking @p chThdWait() the thread pointer becomes invalid - * and must not be used as parameter for further system calls. - * @note If @p CH_CFG_USE_DYNAMIC is not specified this function just waits for - * the thread termination, no memory allocators are involved. - * - * @param[in] tp pointer to the thread - * @return The exit code from the terminated thread. - * - * @api - */ -msg_t chThdWait(thread_t *tp) { - msg_t msg; - - chDbgCheck(tp != NULL); - - chSysLock(); - chDbgAssert(tp != currp, "waiting self"); -#if CH_CFG_USE_DYNAMIC - chDbgAssert(tp->p_refs > 0, "not referenced"); -#endif - if (tp->p_state != CH_STATE_FINAL) { - list_insert(currp, &tp->p_waiting); - chSchGoSleepS(CH_STATE_WTEXIT); - } - msg = tp->p_u.exitcode; - chSysUnlock(); -#if CH_CFG_USE_DYNAMIC - chThdRelease(tp); -#endif - return msg; -} -#endif /* CH_CFG_USE_WAITEXIT */ - -/** @} */ -- cgit v1.2.3