From 839d0a74e54a667d97b33ecfa8a1b650a30ae661 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 25 Feb 2016 08:03:21 +0100 Subject: malloc: Use dedicated lock for deferred frees --- cpukit/libcsupport/src/malloc_deferred.c | 35 ++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/cpukit/libcsupport/src/malloc_deferred.c b/cpukit/libcsupport/src/malloc_deferred.c index e85b2646ea..395ed64d34 100644 --- a/cpukit/libcsupport/src/malloc_deferred.c +++ b/cpukit/libcsupport/src/malloc_deferred.c @@ -30,7 +30,9 @@ #include #include -RTEMS_CHAIN_DEFINE_EMPTY(RTEMS_Malloc_GC_list); +static RTEMS_CHAIN_DEFINE_EMPTY( _Malloc_GC_list ); + +RTEMS_INTERRUPT_LOCK_DEFINE( static, _Malloc_GC_lock, "Malloc GC" ) bool malloc_is_system_state_OK(void) { @@ -38,21 +40,36 @@ bool malloc_is_system_state_OK(void) || _Thread_Dispatch_is_enabled(); } -void malloc_deferred_frees_process(void) +static void *_Malloc_Get_deferred_free( void ) { - rtems_chain_node *to_be_freed; + rtems_interrupt_lock_context lock_context; + void *p; + + rtems_interrupt_lock_acquire( &_Malloc_GC_lock, &lock_context ); + p = rtems_chain_get_unprotected( &_Malloc_GC_list ); + rtems_interrupt_lock_release( &_Malloc_GC_lock, &lock_context ); + + return p; +} + +void malloc_deferred_frees_process( void ) +{ + rtems_chain_node *to_be_freed; /* * If some free's have been deferred, then do them now. */ - while ((to_be_freed = rtems_chain_get(&RTEMS_Malloc_GC_list)) != NULL) - free(to_be_freed); + while ( ( to_be_freed = _Malloc_Get_deferred_free() ) != NULL ) { + free( to_be_freed ); + } } -void malloc_deferred_free( - void *pointer -) +void malloc_deferred_free( void *p ) { - rtems_chain_append(&RTEMS_Malloc_GC_list, (rtems_chain_node *)pointer); + rtems_interrupt_lock_context lock_context; + + rtems_interrupt_lock_acquire( &_Malloc_GC_lock, &lock_context ); + rtems_chain_append_unprotected( &_Malloc_GC_list, (rtems_chain_node *) p ); + rtems_interrupt_lock_release( &_Malloc_GC_lock, &lock_context ); } #endif -- cgit v1.2.3