From cb2f84e288cd92e807d2fa96427ffe37ba0421be Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 7 Sep 2015 15:28:58 -0600 Subject: [PATCH] Loosen up restriction a little in sched_ufree() --- sched/sched/sched_free.c | 74 ++++++++++++++++++++----------------- sched/sched/sched_garbage.c | 2 +- 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/sched/sched/sched_free.c b/sched/sched/sched_free.c index a762e09a6a..1ef1579159 100644 --- a/sched/sched/sched_free.c +++ b/sched/sched/sched_free.c @@ -1,7 +1,7 @@ -/************************************************************************ +/**************************************************************************** * sched/sched/sched_free.c * - * Copyright (C) 2007, 2009, 2012-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2012-2013, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -31,11 +31,13 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ + +/**************************************************************************** * Included Files - ************************************************************************/ + ****************************************************************************/ + #include @@ -48,31 +50,37 @@ #include "sched/sched.h" -/************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ + +/**************************************************************************** * Private Type Declarations - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ + +/**************************************************************************** * Global Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ + +/**************************************************************************** * Private Variables - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ + +/**************************************************************************** * Private Function Prototypes - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ + +/**************************************************************************** * Public Functions - ************************************************************************/ + ****************************************************************************/ -/************************************************************************ + +/**************************************************************************** * Name: sched_ufree and sched_kfree * * Description: @@ -81,10 +89,23 @@ * corner cases where the operating system may have to perform * deallocations from within an interrupt handler. * - ************************************************************************/ + ****************************************************************************/ void sched_ufree(FAR void *address) { +#ifdef CONFIG_BUILD_KERNEL + /* REVISIT: It is not safe to defer user allocation in the kernel mode + * build. Why? Because the correct user context is in place now but + * will not be in place when the deferred de-allocation is performed. In + * order to make this work, we would need to do something like: (1) move + * g_delayed_kufree into the group structure, then traverse the groups to + * collect garbage on a group-by-group basis. + */ + + ASSERT(!up_interrupt_context()); + kumm_free(address); + +#else /* Check if this is an attempt to deallocate memory from an exception * handler. If this function is called from the IDLE task, then we * must have exclusive access to the memory manager to do this. @@ -92,19 +113,6 @@ void sched_ufree(FAR void *address) if (up_interrupt_context() || kumm_trysemaphore() != 0) { -#ifdef CONFIG_BUILD_KERNEL - /* REVISIT: It is not safe to defer user allocation in the kernel - * mode build. Why? Because the correct user context is in place - * now but will not be in place when the deferred de-allocation is - * performed. In order to make this work, we would need to do - * something like: (1) move g_delayed_kufree into the group - * structure, then traverse the groups to collect garbage on a - * group-by-group basis. - */ - - PANIC(); - -#else irqstate_t flags; /* Yes.. Make sure that this is not a attempt to free kernel memory @@ -127,7 +135,6 @@ void sched_ufree(FAR void *address) work_signal(LPWORK); #endif irqrestore(flags); -#endif } else { @@ -136,6 +143,7 @@ void sched_ufree(FAR void *address) kumm_free(address); kumm_givesemaphore(); } +#endif } #ifdef CONFIG_MM_KERNEL_HEAP diff --git a/sched/sched/sched_garbage.c b/sched/sched/sched_garbage.c index ce394641cf..5ebfe6eaed 100644 --- a/sched/sched/sched_garbage.c +++ b/sched/sched/sched_garbage.c @@ -201,7 +201,7 @@ void sched_garbagecollection(void) sched_kcleanup(); - /* Handle deferred dealloctions for the user heap */ + /* Handle deferred deallocations for the user heap */ sched_kucleanup(); }