From b5863b717bcb958c967ccb6cbf39814500721b85 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 4 Jun 2020 15:00:51 -0400 Subject: [PATCH] Fix #471, order of operations for delete all When cleaning up for shutdown, delete resources that have a task/thread first, followed by other resource types. This helps avoid possible dependencies as running threads might be using the other resources. --- src/os/shared/src/osapi-common.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/os/shared/src/osapi-common.c b/src/os/shared/src/osapi-common.c index c3b7fb0b5..62a5a433b 100644 --- a/src/os/shared/src/osapi-common.c +++ b/src/os/shared/src/osapi-common.c @@ -337,7 +337,18 @@ void OS_DeleteAllObjects(void) { ObjectCount = 0; ++TryCount; + + /* Delete timers and tasks first, as they could be actively using other object types */ + OS_ForEachObjectOfType(OS_OBJECT_TYPE_OS_TIMECB, OS_OBJECT_CREATOR_ANY, + OS_CleanUpObject, &ObjectCount); + OS_ForEachObjectOfType(OS_OBJECT_TYPE_OS_TIMEBASE, OS_OBJECT_CREATOR_ANY, + OS_CleanUpObject, &ObjectCount); + OS_ForEachObjectOfType(OS_OBJECT_TYPE_OS_TASK, OS_OBJECT_CREATOR_ANY, + OS_CleanUpObject, &ObjectCount); + + /* Then try to delete all other remaining objects of any type */ OS_ForEachObject(OS_OBJECT_CREATOR_ANY, OS_CleanUpObject, &ObjectCount); + if (ObjectCount == 0 || TryCount > 4) { break;