From 6d6284c9e6d1e3d1f0083c153ee21235771e1014 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Wed, 24 Feb 2016 14:44:50 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8941 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/rt/include/chdynamic.h | 4 +- os/rt/include/chevents.h | 8 -- os/rt/include/chthreads.h | 14 ++++ os/rt/src/chdynamic.c | 129 +++++++++++++++++++++++++-------- os/rt/src/chsys.c | 1 - os/rt/src/chthreads.c | 74 ++++++++++++++++--- os/various/shell/shell_cmd.c | 7 +- release_note_next.txt | 4 - test/rt/test.c | 13 ++++ test/rt/test.h | 1 + test/rt/test.mk | 1 + test/rt/testbmk.c | 43 +++++------ test/rt/testdyn.c | 15 ++-- testhal/STM32/STM32F7xx/USB_CDC/main.c | 3 +- 14 files changed, 222 insertions(+), 95 deletions(-) diff --git a/os/rt/include/chdynamic.h b/os/rt/include/chdynamic.h index fa42bf3ae..9b653cc5c 100644 --- a/os/rt/include/chdynamic.h +++ b/os/rt/include/chdynamic.h @@ -71,16 +71,16 @@ #ifdef __cplusplus extern "C" { #endif + thread_t *chThdAddRef(thread_t *tp); + void chThdRelease(thread_t *tp); #if CH_CFG_USE_HEAP == TRUE thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size, const char *name, tprio_t prio, tfunc_t pf, void *arg); - void chThdFreeToHeap(thread_t *tp); #endif #if CH_CFG_USE_MEMPOOLS == TRUE thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, const char *name, tprio_t prio, tfunc_t pf, void *arg); - void chThdFreeToMemoryPool(thread_t *tp, memory_pool_t *mp); #endif #ifdef __cplusplus } diff --git a/os/rt/include/chevents.h b/os/rt/include/chevents.h index fa8e4d7a5..8432eea8e 100644 --- a/os/rt/include/chevents.h +++ b/os/rt/include/chevents.h @@ -37,14 +37,6 @@ /* Module constants. */ /*===========================================================================*/ -/** - * @brief Event bit reserved for thread termination request. - * @note The most significant bit of the events mask is conventionally - * used for thread termination but it can eventually be used for - * other events. - */ -#define CH_EVENT_TERMINATE ~(((eventmask_t)-1) >> 1U) - /*===========================================================================*/ /* Module pre-compile time settings. */ /*===========================================================================*/ diff --git a/os/rt/include/chthreads.h b/os/rt/include/chthreads.h index 8d632d59e..d4f2a68d0 100644 --- a/os/rt/include/chthreads.h +++ b/os/rt/include/chthreads.h @@ -182,6 +182,7 @@ extern "C" { tprio_t prio, tfunc_t pf, void *arg); thread_t *chThdStart(thread_t *tp); tprio_t chThdSetPriority(tprio_t newprio); + void chThdTerminate(thread_t *tp); msg_t chThdSuspendS(thread_reference_t *trp); msg_t chThdSuspendTimeoutS(thread_reference_t *trp, systime_t timeout); void chThdResumeI(thread_reference_t *trp, msg_t msg); @@ -276,6 +277,19 @@ static inline bool chThdTerminatedX(thread_t *tp) { return (bool)(tp->state == CH_STATE_FINAL); } +/** + * @brief Verifies if the current thread has a termination request pending. + * + * @retval true termination request pending. + * @retval false termination request not pending. + * + * @xclass + */ +static inline bool chThdShouldTerminateX(void) { + + return (bool)((chThdGetSelfX()->flags & CH_FLAG_TERMINATE) != (tmode_t)0); +} + /** * @brief Resumes a thread created with @p chThdCreateI(). * diff --git a/os/rt/src/chdynamic.c b/os/rt/src/chdynamic.c index 414cfe2c8..60b0cbe19 100644 --- a/os/rt/src/chdynamic.c +++ b/os/rt/src/chdynamic.c @@ -54,6 +54,78 @@ /* Module exported functions. */ /*===========================================================================*/ +/** + * @brief Adds a reference to a thread object. + * @pre The configuration option @p CH_CFG_USE_DYNAMIC must be enabled in + * order to use this function. + * + * @param[in] tp pointer to the thread + * @return The same thread pointer passed as parameter + * representing the new reference. + * + * @api + */ +thread_t *chThdAddRef(thread_t *tp) { + + chSysLock(); + chDbgAssert(tp->refs < (trefs_t)255, "too many references"); + tp->refs++; + chSysUnlock(); + + return tp; +} + +/** + * @brief Releases a reference to a thread object. + * @details If the references counter reaches zero and the thread + * is in the @p CH_STATE_FINAL state then the thread's memory is + * returned to the proper allocator. + * @pre The configuration option @p CH_CFG_USE_DYNAMIC must be enabled in + * order to use this function. + * @note Static threads are not affected. + * + * @param[in] tp pointer to the thread + * + * @api + */ +void chThdRelease(thread_t *tp) { + trefs_t refs; + + chSysLock(); + chDbgAssert(tp->refs > (trefs_t)0, "not referenced"); + tp->refs--; + refs = tp->refs; + chSysUnlock(); + + /* If the references counter reaches zero and the thread is in its + terminated state then the memory can be returned to the proper + allocator. Of course static threads are not affected.*/ + if ((refs == (trefs_t)0) && (tp->state == CH_STATE_FINAL)) { + switch (tp->flags & CH_FLAG_MODE_MASK) { +#if CH_CFG_USE_HEAP == TRUE + case CH_FLAG_MODE_HEAP: +#if CH_CFG_USE_REGISTRY == TRUE + REG_REMOVE(tp); +#endif + chHeapFree(chthdGetStackLimitX(tp)); + break; +#endif +#if CH_CFG_USE_MEMPOOLS == TRUE + case CH_FLAG_MODE_MPOOL: +#if CH_CFG_USE_REGISTRY == TRUE + REG_REMOVE(tp); +#endif + chPoolFree(tp->mpool, chthdGetStackLimitX(tp)); + break; +#endif + default: + /* Nothing to do for static threads, those are removed from the + registry on exit.*/ + break; + } + } +} + #if (CH_CFG_USE_HEAP == TRUE) || defined(__DOXYGEN__) /** * @brief Creates a new thread allocating the memory from the heap. @@ -82,6 +154,7 @@ thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size, const char *name, tprio_t prio, tfunc_t pf, void *arg) { + thread_t *tp; void *wsp; wsp = chHeapAllocAligned(heapp, size, PORT_WORKING_AREA_ALIGN); @@ -98,24 +171,19 @@ thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size, arg }; - return chThdCreate(&td); -} - -/** - * @brief Releases a thread working area into the owner heap. - * @pre The thread must have been created using @p chThdCreateFromHeap(). - * @pre The thread must be in the state @p CH_STATE_FINAL (terminated). - * - * @param[in] tp the pointer to the thread - * - * @api - */ -void chThdFreeToHeap(thread_t *tp) { +#if CH_DBG_FILL_THREADS == TRUE + _thread_memfill((uint8_t *)wsp, + (uint8_t *)wsp + size, + CH_DBG_STACK_FILL_VALUE); +#endif - chDbgCheck(tp != NULL); - chDbgAssert(tp->state == CH_STATE_FINAL, "not terminated"); + chSysLock(); + tp = chThdCreateSuspendedI(&td); + tp->flags = CH_FLAG_MODE_HEAP; + chSchWakeupS(tp, MSG_OK); + chSysUnlock(); - chHeapFree(chthdGetStackLimitX(tp)); + return tp; } #endif /* CH_CFG_USE_HEAP == TRUE */ @@ -148,6 +216,7 @@ void chThdFreeToHeap(thread_t *tp) { */ thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, const char *name, tprio_t prio, tfunc_t pf, void *arg) { + thread_t *tp; void *wsp; chDbgCheck(mp != NULL); @@ -166,25 +235,21 @@ thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, const char *name, arg }; - return chThdCreate(&td); -} +#if CH_DBG_FILL_THREADS == TRUE + _thread_memfill((uint8_t *)wsp, + (uint8_t *)wsp + mp->object_size, + CH_DBG_STACK_FILL_VALUE); +#endif -/** - * @brief Releases a thread working area into a memory pool. - * @pre The thread must have been created using @p chThdCreateFromMemoryPool(). - * @pre The thread must be in the state @p CH_STATE_FINAL (terminated). - * - * @param[in] tp the pointer to the thread - * @param[in] mp pointer to a @p memory_pool_t structure - * - * @api - */ -void chThdFreeToMemoryPool(thread_t *tp, memory_pool_t *mp) { - chDbgCheck((tp != NULL) && (mp != NULL)); - chDbgAssert(tp->state == CH_STATE_FINAL, "not terminated"); + chSysLock(); + tp = chThdCreateSuspendedI(&td); + tp->flags = CH_FLAG_MODE_MPOOL; + tp->mpool = mp; + chSchWakeupS(tp, MSG_OK); + chSysUnlock(); - chPoolFree(mp, (void *)chthdGetStackLimitX(tp)); + return tp; } #endif /* CH_CFG_USE_MEMPOOLS == TRUE */ diff --git a/os/rt/src/chsys.c b/os/rt/src/chsys.c index 18459849d..d9ca6d81a 100644 --- a/os/rt/src/chsys.c +++ b/os/rt/src/chsys.c @@ -129,7 +129,6 @@ void chSysInit(void) { /* Setting up the caller as current thread.*/ currp->state = CH_STATE_CURRENT; - currp->flags = CH_FLAG_MODE_STATIC; /* Port layer initialization last because it depend on some of the initializations performed before.*/ diff --git a/os/rt/src/chthreads.c b/os/rt/src/chthreads.c index 0fff76604..ed5b19e15 100644 --- a/os/rt/src/chthreads.c +++ b/os/rt/src/chthreads.c @@ -87,22 +87,27 @@ */ thread_t *_thread_init(thread_t *tp, const char *name, tprio_t prio) { - tp->prio = prio; + tp->prio = prio; + tp->state = CH_STATE_WTSTART; + tp->flags = CH_FLAG_MODE_STATIC; #if CH_CFG_TIME_QUANTUM > 0 - tp->preempt = (tslices_t)CH_CFG_TIME_QUANTUM; + tp->preempt = (tslices_t)CH_CFG_TIME_QUANTUM; #endif #if CH_CFG_USE_MUTEXES == TRUE - tp->realprio = prio; - tp->mtxlist = NULL; + tp->realprio = prio; + tp->mtxlist = NULL; #endif #if CH_CFG_USE_EVENTS == TRUE - tp->epending = (eventmask_t)0; + tp->epending = (eventmask_t)0; #endif #if CH_DBG_THREADS_PROFILING == TRUE - tp->time = (systime_t)0; + tp->time = (systime_t)0; +#endif +#if CH_CFG_USE_DYNAMIC == TRUE + tp->refs = (trefs_t)1; #endif #if CH_CFG_USE_REGISTRY == TRUE - tp->name = name; + tp->name = name; REG_INSERT(tp); #endif #if CH_CFG_USE_WAITEXIT == TRUE @@ -173,10 +178,6 @@ thread_t *chThdCreateSuspendedI(const thread_descriptor_t *tdp) { tp = (thread_t *)((uint8_t *)tdp->wend - MEM_ALIGN_NEXT(sizeof (thread_t), PORT_STACK_ALIGN)); - /* Initial state.*/ - tp->state = CH_STATE_WTSTART; - tp->flags = CH_FLAG_MODE_STATIC; - /* Stack boundary.*/ tp->stklimit = tdp->wbase; @@ -379,6 +380,25 @@ tprio_t chThdSetPriority(tprio_t newprio) { return oldprio; } +/** + * @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->flags |= CH_FLAG_TERMINATE; + chSysUnlock(); +} + /** * @brief Suspends the invoking thread for the specified time. * @@ -501,14 +521,20 @@ void chThdExitS(msg_t msg) { thread_t *tp = currp; tp->u.exitcode = msg; +#if defined(CH_CFG_THREAD_EXIT_HOOK) CH_CFG_THREAD_EXIT_HOOK(tp); +#endif #if CH_CFG_USE_WAITEXIT == TRUE while (list_notempty(&tp->waiting)) { (void) chSchReadyI(list_remove(&tp->waiting)); } #endif #if CH_CFG_USE_REGISTRY == TRUE - REG_REMOVE(tp); + /* Static threads are immediately removed from the registry because + there is no memory to recover.*/ + if ((tp->flags & CH_FLAG_MODE_MASK) == CH_FLAG_MODE_STATIC) { + REG_REMOVE(tp); + } #endif chSchGoSleepS(CH_STATE_FINAL); @@ -520,12 +546,28 @@ void chThdExitS(msg_t msg) { /** * @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. @@ -539,6 +581,9 @@ msg_t chThdWait(thread_t *tp) { chSysLock(); chDbgAssert(tp != currp, "waiting self"); +#if CH_CFG_USE_DYNAMIC == TRUE + chDbgAssert(tp->refs > (trefs_t)0, "not referenced"); +#endif if (tp->state != CH_STATE_FINAL) { list_insert(currp, &tp->waiting); chSchGoSleepS(CH_STATE_WTEXIT); @@ -546,6 +591,11 @@ msg_t chThdWait(thread_t *tp) { msg = tp->u.exitcode; chSysUnlock(); +#if CH_CFG_USE_DYNAMIC == TRUE + /* Releasing a lock if it is a dynamic thread.*/ + chThdRelease(tp); +#endif + return msg; } #endif /* CH_CFG_USE_WAITEXIT */ diff --git a/os/various/shell/shell_cmd.c b/os/various/shell/shell_cmd.c index 80d683583..f8a8a0c06 100644 --- a/os/various/shell/shell_cmd.c +++ b/os/various/shell/shell_cmd.c @@ -144,12 +144,12 @@ static void cmd_threads(BaseSequentialStream *chp, int argc, char *argv[]) { chprintf(chp, "Usage: threads\r\n"); return; } - chprintf(chp, "stklimit stack addr prio state name\r\n"); + chprintf(chp, "stklimit stack addr refs prio state name\r\n"); tp = chRegFirstThread(); do { - chprintf(chp, "%08lx %08lx %08lx %4lu %9s %12s\r\n", + chprintf(chp, "%08lx %08lx %08lx %4lu %4lu %9s %12s\r\n", (uint32_t)tp->stklimit, (uint32_t)tp->ctx.sp, (uint32_t)tp, - (uint32_t)tp->prio, states[tp->state], + (uint32_t)tp->refs - 1, (uint32_t)tp->prio, states[tp->state], tp->name == NULL ? "" : tp->name); tp = chRegNextThread(tp); } while (tp != NULL); @@ -173,7 +173,6 @@ static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) { return; } chThdWait(tp); - chThdFreeToHeap(tp); } #endif diff --git a/release_note_next.txt b/release_note_next.txt index 4026ad9e8..525aa8a9c 100644 --- a/release_note_next.txt +++ b/release_note_next.txt @@ -26,11 +26,7 @@ a series of important new features. - Enhanced trace buffer, it is able to store events regarding not just threads but also IRQs, halts and user events. - Enhanced Registry, it is now possible to find threads by name or by pointer. -- Simplified the dynamic threading model, now it is the thread creator - responsible for memory release, the references counter has been removed - and the code is much simpler. - New threading API, now creating static threads is even faster. -- Saved space in thread_t structure. - Extended priority range to 1..255. - Experimental NASA OSAL implementation. diff --git a/test/rt/test.c b/test/rt/test.c index fcba9607d..f4a08eeea 100644 --- a/test/rt/test.c +++ b/test/rt/test.c @@ -35,6 +35,7 @@ #include "testevt.h" #include "testheap.h" #include "testpools.h" +#include "testdyn.h" #include "testqueues.h" #include "testbmk.h" @@ -51,6 +52,7 @@ static ROMCONST struct testcase * ROMCONST *patterns[] = { patternevt, patternheap, patternpools, + patterndyn, patternqueues, patternbmk, NULL @@ -191,6 +193,17 @@ bool _test_assert_time_window(unsigned point, systime_t start, systime_t end) { * Threads utils. */ +/** + * @brief Sets a termination request in all the test-spawned threads. + */ +void test_terminate_threads(void) { + int i; + + for (i = 0; i < MAX_THREADS; i++) + if (threads[i]) + chThdTerminate(threads[i]); +} + /** * @brief Waits for the completion of all the test-spawned threads. */ diff --git a/test/rt/test.h b/test/rt/test.h index eb1f35c54..da080db2d 100644 --- a/test/rt/test.h +++ b/test/rt/test.h @@ -90,6 +90,7 @@ extern "C" { bool _test_assert(unsigned point, bool condition); bool _test_assert_sequence(unsigned point, char *expected); bool _test_assert_time_window(unsigned point, systime_t start, systime_t end); + void test_terminate_threads(void); void test_wait_threads(void); systime_t test_wait_tick(void); void test_start_timer(unsigned ms); diff --git a/test/rt/test.mk b/test/rt/test.mk index 1a3b368bb..03de3c89a 100644 --- a/test/rt/test.mk +++ b/test/rt/test.mk @@ -8,6 +8,7 @@ TESTSRC = ${CHIBIOS}/test/rt/test.c \ ${CHIBIOS}/test/rt/testevt.c \ ${CHIBIOS}/test/rt/testheap.c \ ${CHIBIOS}/test/rt/testpools.c \ + ${CHIBIOS}/test/rt/testdyn.c \ ${CHIBIOS}/test/rt/testqueues.c \ ${CHIBIOS}/test/rt/testsys.c \ ${CHIBIOS}/test/rt/testbmk.c diff --git a/test/rt/testbmk.c b/test/rt/testbmk.c index 639ba2b7b..1bffbc4df 100644 --- a/test/rt/testbmk.c +++ b/test/rt/testbmk.c @@ -344,7 +344,8 @@ ROMCONST struct testcase testbmk6 = { static THD_FUNCTION(thread3, p) { - while (!*(bool *)p) + (void)p; + while (!chThdShouldTerminateX()) chSemWait(&sem1); } @@ -355,13 +356,12 @@ static void bmk7_setup(void) { static void bmk7_execute(void) { uint32_t n; - bool terminate = false; - threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+5, thread3, &terminate); - threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriorityX()+4, thread3, &terminate); - threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriorityX()+3, thread3, &terminate); - threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriorityX()+2, thread3, &terminate); - threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriorityX()+1, thread3, &terminate); + threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()+5, thread3, NULL); + threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriorityX()+4, thread3, NULL); + threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriorityX()+3, thread3, NULL); + threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriorityX()+2, thread3, NULL); + threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriorityX()+1, thread3, NULL); n = 0; test_wait_tick(); @@ -373,7 +373,7 @@ static void bmk7_execute(void) { _sim_check_for_interrupts(); #endif } while (!test_timer_done); - terminate = true; + test_terminate_threads(); chSemReset(&sem1, 0); test_wait_threads(); @@ -401,44 +401,39 @@ ROMCONST struct testcase testbmk7 = { * The performance is calculated by measuring the number of iterations after * a second of continuous operations. */ -typedef struct { - bool terminate; - uint32_t n; -} params_t; static THD_FUNCTION(thread8, p) { - params_t *pp = (params_t *)p; do { chThdYield(); chThdYield(); chThdYield(); chThdYield(); - pp->n += 4; + (*(uint32_t *)p) += 4; #if defined(SIMULATOR) _sim_check_for_interrupts(); #endif - } while (!pp->terminate); + } while(!chThdShouldTerminateX()); } static void bmk8_execute(void) { - params_t params = {false, 0}; + uint32_t n; - params.n = 0; + n = 0; test_wait_tick(); - threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)¶ms); - threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)¶ms); - threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)¶ms); - threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)¶ms); - threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)¶ms); + threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)&n); + threads[1] = chThdCreateStatic(wa[1], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)&n); + threads[2] = chThdCreateStatic(wa[2], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)&n); + threads[3] = chThdCreateStatic(wa[3], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)&n); + threads[4] = chThdCreateStatic(wa[4], WA_SIZE, chThdGetPriorityX()-1, thread8, (void *)&n); chThdSleepSeconds(1); - params.terminate = true; + test_terminate_threads(); test_wait_threads(); test_print("--- Score : "); - test_printn(params.n); + test_printn(n); test_println(" ctxswc/S"); } diff --git a/test/rt/testdyn.c b/test/rt/testdyn.c index 9e8932c10..25304a376 100644 --- a/test/rt/testdyn.c +++ b/test/rt/testdyn.c @@ -87,13 +87,16 @@ static void dyn1_execute(void) { /* Starting threads from the heap. */ threads[0] = chThdCreateFromHeap(&heap1, THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE), + "dyn1", prio-1, thread, "A"); threads[1] = chThdCreateFromHeap(&heap1, THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE), + "dyn2", prio-2, thread, "B"); /* Large working area in order to make the thread creation fail.*/ threads[2] = chThdCreateFromHeap(&heap1, THD_WORKING_AREA_SIZE(THREADS_STACK_SIZE * 16), + "dyn3", prio-3, thread, "C"); test_assert(1, (threads[0] != NULL) && @@ -145,11 +148,11 @@ static void dyn2_execute(void) { chPoolFree(&mp1, wa[i]); /* Starting threads from the memory pool. */ - threads[0] = chThdCreateFromMemoryPool(&mp1, prio-1, thread, "A"); - threads[1] = chThdCreateFromMemoryPool(&mp1, prio-2, thread, "B"); - threads[2] = chThdCreateFromMemoryPool(&mp1, prio-3, thread, "C"); - threads[3] = chThdCreateFromMemoryPool(&mp1, prio-4, thread, "D"); - threads[4] = chThdCreateFromMemoryPool(&mp1, prio-5, thread, "E"); + threads[0] = chThdCreateFromMemoryPool(&mp1, "dyn1", prio-1, thread, "A"); + threads[1] = chThdCreateFromMemoryPool(&mp1, "dyn2", prio-2, thread, "B"); + threads[2] = chThdCreateFromMemoryPool(&mp1, "dyn3", prio-3, thread, "C"); + threads[3] = chThdCreateFromMemoryPool(&mp1, "dyn4", prio-4, thread, "D"); + threads[4] = chThdCreateFromMemoryPool(&mp1, "dyn5", prio-5, thread, "E"); test_assert(1, (threads[0] != NULL) && (threads[1] != NULL) && @@ -207,7 +210,7 @@ static void dyn3_execute(void) { tprio_t prio = chThdGetPriorityX(); /* Testing references increase/decrease and final detach.*/ - tp = chThdCreateFromHeap(&heap1, WA_SIZE, prio-1, thread, "A"); + tp = chThdCreateFromHeap(&heap1, WA_SIZE, "dyn1", prio-1, thread, "A"); test_assert(1, tp->refs == 1, "wrong initial reference counter"); chThdAddRef(tp); test_assert(2, tp->refs == 2, "references increase failure"); diff --git a/testhal/STM32/STM32F7xx/USB_CDC/main.c b/testhal/STM32/STM32F7xx/USB_CDC/main.c index 940bde5a1..244385b11 100644 --- a/testhal/STM32/STM32F7xx/USB_CDC/main.c +++ b/testhal/STM32/STM32F7xx/USB_CDC/main.c @@ -160,8 +160,7 @@ int main(void) { thread_t *shelltp = chThdCreateFromHeap(NULL, SHELL_WA_SIZE, "shell", NORMALPRIO + 1, shellThread, (void *)&shell_cfg1); - chThdWait(shelltp); /* Waiting termination. */ - chThdFreeToHeap(shelltp); /* Returning memory to heap. */ + chThdWait(shelltp); } #if 0 if (palReadPad(GPIOI, GPIOI_BUTTON_USER)) { -- cgit v1.2.3