summaryrefslogtreecommitdiff
path: root/nuttx/sched/sched_garbage.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/sched/sched_garbage.c')
-rwxr-xr-xnuttx/sched/sched_garbage.c44
1 files changed, 18 insertions, 26 deletions
diff --git a/nuttx/sched/sched_garbage.c b/nuttx/sched/sched_garbage.c
index 6dc1a5c88..66c7bafae 100755
--- a/nuttx/sched/sched_garbage.c
+++ b/nuttx/sched/sched_garbage.c
@@ -42,8 +42,6 @@
#include <stdlib.h>
-#include <nuttx/mm.h>
-
#include "os_internal.h"
/****************************************************************************
@@ -93,35 +91,29 @@
void sched_garbagecollection(void)
{
- /* Check if there is anything in the delayed deallocation list. If there
- * is deallocate it now. We must have exclusive access to the memory manager
- * to do this BUT the idle task cannot wait on a semaphore. So we only do
- * the cleanup now if we can get the semaphore -- and this should be possible
- * because if the IDLE thread is running, no other task is!
- */
-
-#ifdef CONFIG_SCHED_WORKQUEUE
- mm_takesemaphore();
-#else
- if (mm_trysemaphore() == 0)
-#endif
+ irqstate_t flags;
+ void *address;
+
+ /* Test if the delayed deallocation queue is empty. No special protection
+ * is needed because this is an atomic test.
+ */
+
+ while (g_delayeddeallocations.head)
{
- while (g_delayeddeallocations.head)
- {
- /* Remove the first delayed deallocation. */
+ /* Remove the first delayed deallocation. This is not atomic and so
+ * we must disable interrupts around the queue operation.
+ */
- irqstate_t saved_state = irqsave();
- void *address = (void*)sq_remfirst((FAR sq_queue_t*)&g_delayeddeallocations);
- irqrestore(saved_state);
+ flags = irqsave();
+ address = (void*)sq_remfirst((FAR sq_queue_t*)&g_delayeddeallocations);
+ irqrestore(flags);
- /* Then deallocate it */
+ /* Then deallocate it. */
- if (address)
- {
- free(address);
- }
+ if (address)
+ {
+ free(address);
}
- mm_givesemaphore();
}
}