Changeset 839d0a74 in rtems


Ignore:
Timestamp:
Feb 25, 2016, 7:03:21 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
9d1f3943
Parents:
287a70f
git-author:
Sebastian Huber <sebastian.huber@…> (02/25/16 07:03:21)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/25/16 08:10:53)
Message:

malloc: Use dedicated lock for deferred frees

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/src/malloc_deferred.c

    r287a70f r839d0a74  
    3131#include <rtems/score/threaddispatch.h>
    3232
    33 RTEMS_CHAIN_DEFINE_EMPTY(RTEMS_Malloc_GC_list);
     33static RTEMS_CHAIN_DEFINE_EMPTY( _Malloc_GC_list );
     34
     35RTEMS_INTERRUPT_LOCK_DEFINE( static, _Malloc_GC_lock, "Malloc GC" )
    3436
    3537bool malloc_is_system_state_OK(void)
     
    3941}
    4042
    41 void malloc_deferred_frees_process(void)
     43static void *_Malloc_Get_deferred_free( void )
    4244{
    43   rtems_chain_node  *to_be_freed;
     45  rtems_interrupt_lock_context lock_context;
     46  void *p;
     47
     48  rtems_interrupt_lock_acquire( &_Malloc_GC_lock, &lock_context );
     49  p = rtems_chain_get_unprotected( &_Malloc_GC_list );
     50  rtems_interrupt_lock_release( &_Malloc_GC_lock, &lock_context );
     51
     52  return p;
     53}
     54
     55void malloc_deferred_frees_process( void )
     56{
     57  rtems_chain_node *to_be_freed;
    4458
    4559  /*
    4660   *  If some free's have been deferred, then do them now.
    4761   */
    48   while ((to_be_freed = rtems_chain_get(&RTEMS_Malloc_GC_list)) != NULL)
    49     free(to_be_freed);
     62  while ( ( to_be_freed = _Malloc_Get_deferred_free() ) != NULL ) {
     63    free( to_be_freed );
     64  }
    5065}
    5166
    52 void malloc_deferred_free(
    53   void *pointer
    54 )
     67void malloc_deferred_free( void *p )
    5568{
    56   rtems_chain_append(&RTEMS_Malloc_GC_list, (rtems_chain_node *)pointer);
     69  rtems_interrupt_lock_context lock_context;
     70
     71  rtems_interrupt_lock_acquire( &_Malloc_GC_lock, &lock_context );
     72  rtems_chain_append_unprotected( &_Malloc_GC_list, (rtems_chain_node *) p );
     73  rtems_interrupt_lock_release( &_Malloc_GC_lock, &lock_context );
    5774}
    5875#endif
Note: See TracChangeset for help on using the changeset viewer.