diff options
Diffstat (limited to 'os')
-rw-r--r-- | os/kernel/src/chdynamic.c | 13 | ||||
-rw-r--r-- | os/kernel/src/chthreads.c | 5 |
2 files changed, 14 insertions, 4 deletions
diff --git a/os/kernel/src/chdynamic.c b/os/kernel/src/chdynamic.c index 06e5bd00a..5f1fc3401 100644 --- a/os/kernel/src/chdynamic.c +++ b/os/kernel/src/chdynamic.c @@ -71,17 +71,24 @@ void chThdRelease(Thread *tp) { refs = --tp->p_refs;
chSysUnlock();
- /* If the references counter reaches zero then the memory can be returned
- to the proper allocator. Of course static threads are not affected.*/
- if (refs == 0) {
+ /* 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 == 0) && (tp->p_state == THD_STATE_FINAL)) {
switch (tp->p_flags & THD_MEM_MODE_MASK) {
#if CH_USE_HEAP
case THD_MEM_MODE_HEAP:
+#if CH_USE_REGISTRY
+ REG_REMOVE(tp);
+#endif
chHeapFree(tp);
break;
#endif
#if CH_USE_MEMPOOLS
case THD_MEM_MODE_MEMPOOL:
+#if CH_USE_REGISTRY
+ REG_REMOVE(tp);
+#endif
chPoolFree(tp->p_mpool, tp);
break;
#endif
diff --git a/os/kernel/src/chthreads.c b/os/kernel/src/chthreads.c index 4e8ae1c21..ced8a77e0 100644 --- a/os/kernel/src/chthreads.c +++ b/os/kernel/src/chthreads.c @@ -342,7 +342,10 @@ void chThdExit(msg_t msg) { chSchReadyI(list_remove(&tp->p_waiting));
#endif
#if CH_USE_REGISTRY
- REG_REMOVE(tp);
+ /* 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)
+ REG_REMOVE(tp);
#endif
chSchGoSleepS(THD_STATE_FINAL);
}
|