2003-11-26 Joel Sherrill <joel@OARcorp.com>

PR 523/filesystem
	* src/malloc.c: Make malloc family safer for use from ISRs and
	dispatching critical sections. If in a critical section while doing
	a free(), then the free is deferred until the next malloc() attempt.
This commit is contained in:
Joel Sherrill
2003-11-26 17:50:53 +00:00
parent dfd3132e1d
commit 690861c3c6
2 changed files with 24 additions and 11 deletions

View File

@@ -1,3 +1,10 @@
2003-11-26 Joel Sherrill <joel@OARcorp.com>
PR 523/filesystem
* src/malloc.c: Make malloc family safer for use from ISRs and
dispatching critical sections. If in a critical section while doing
a free(), then the free is deferred until the next malloc() attempt.
2003-11-25 Jennifer Averett <jennifer@OARcorp.com> 2003-11-25 Jennifer Averett <jennifer@OARcorp.com>
PR 519/filesystem PR 519/filesystem

View File

@@ -170,11 +170,13 @@ void *malloc(
* Do not attempt to allocate memory if in a critical section or ISR. * Do not attempt to allocate memory if in a critical section or ISR.
*/ */
if (_System_state_Is_up(_System_state_Get())) {
if (_Thread_Dispatch_disable_level > 0) if (_Thread_Dispatch_disable_level > 0)
return (void *) 0; return (void *) 0;
if (_ISR_Nest_level > 0) if (_ISR_Nest_level > 0)
return (void *) 0; return (void *) 0;
}
/* /*
* If some free's have been deferred, then do them now. * If some free's have been deferred, then do them now.
@@ -297,11 +299,13 @@ void *realloc(
* Do not attempt to allocate memory if in a critical section or ISR. * Do not attempt to allocate memory if in a critical section or ISR.
*/ */
if (_System_state_Is_up(_System_state_Get())) {
if (_Thread_Dispatch_disable_level > 0) if (_Thread_Dispatch_disable_level > 0)
return (void *) 0; return (void *) 0;
if (_ISR_Nest_level > 0) if (_ISR_Nest_level > 0)
return (void *) 0; return (void *) 0;
}
/* /*
* Continue with calloc(). * Continue with calloc().
@@ -356,10 +360,12 @@ void free(
* Do not attempt to free memory if in a critical section or ISR. * Do not attempt to free memory if in a critical section or ISR.
*/ */
if (_System_state_Is_up(_System_state_Get())) {
if ((_Thread_Dispatch_disable_level > 0) || (_ISR_Nest_level > 0)) { if ((_Thread_Dispatch_disable_level > 0) || (_ISR_Nest_level > 0)) {
Chain_Append(&RTEMS_Malloc_GC_list, (Chain_Node *)ptr); Chain_Append(&RTEMS_Malloc_GC_list, (Chain_Node *)ptr);
return; return;
} }
}
#ifdef MALLOC_STATS #ifdef MALLOC_STATS
{ {