summaryrefslogtreecommitdiff
path: root/nuttx/sched/sched_garbage.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-11-06 00:44:22 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-11-06 00:44:22 +0000
commited1cec224f54cb1045fbc436f3c28f71bcf3e646 (patch)
treed3e6b16c63256c6e28562a5b7ea3a76bb8bf3fa7 /nuttx/sched/sched_garbage.c
parent36fb3a89c18856623e1a6f99a90088593c44ac82 (diff)
downloadpx4-nuttx-ed1cec224f54cb1045fbc436f3c28f71bcf3e646.tar.gz
px4-nuttx-ed1cec224f54cb1045fbc436f3c28f71bcf3e646.tar.bz2
px4-nuttx-ed1cec224f54cb1045fbc436f3c28f71bcf3e646.zip
Integrte work thread
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2232 42af7a65-404d-4744-a932-0658087f49c3
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();
}
}