[PATCH][RFC] Remove volatile from data members in libstdc++

Richard Guenther rguenther@suse.de
Mon Jul 10 10:58:00 GMT 2006


This patch removes volatile qualifiers from data members in allocator
classes of libstdc++ and rope.  As mentioned in previous discussion,
their use is wrong.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Ok for mainline?

Thanks,
Richard.

:ADDPATCH libstdc++:

2006-07-08  Richard Guenther  <rguenther@suse.de>

	* include/ext/pool_allocator.h: Remove volatile qualifiers
	from data members and corresponding locals and function
	signatures.
	* include/ext/rope: Likewise.
	* include/ext/mt_allocator.h: Likewise.
	* src/pool_allocator.cc: Likewise.

Index: include/ext/pool_allocator.h
===================================================================
*** include/ext/pool_allocator.h	(revision 115286)
--- include/ext/pool_allocator.h	(working copy)
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 92,98 ****
  	char        _M_client_data[1];    // The client sees this.
        };
        
!       static _Obj* volatile         _S_free_list[_S_free_list_size];
  
        // Chunk allocation state.
        static char*                  _S_start_free;
--- 92,98 ----
  	char        _M_client_data[1];    // The client sees this.
        };
        
!       static _Obj*		    _S_free_list[_S_free_list_size];
  
        // Chunk allocation state.
        static char*                  _S_start_free;
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 103,109 ****
        _M_round_up(size_t __bytes)
        { return ((__bytes + (size_t)_S_align - 1) & ~((size_t)_S_align - 1)); }
        
!       _Obj* volatile*
        _M_get_free_list(size_t __bytes);
      
        mutex_type&
--- 103,109 ----
        _M_round_up(size_t __bytes)
        { return ((__bytes + (size_t)_S_align - 1) & ~((size_t)_S_align - 1)); }
        
!       _Obj**
        _M_get_free_list(size_t __bytes);
      
        mutex_type&
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 216,222 ****
  	    __ret = static_cast<_Tp*>(::operator new(__bytes));
  	  else
  	    {
! 	      _Obj* volatile* __free_list = _M_get_free_list(__bytes);
  	      
  	      lock sentry(_M_get_mutex());
  	      _Obj* __restrict__ __result = *__free_list;
--- 216,222 ----
  	    __ret = static_cast<_Tp*>(::operator new(__bytes));
  	  else
  	    {
! 	      _Obj** __free_list = _M_get_free_list(__bytes);
  	      
  	      lock sentry(_M_get_mutex());
  	      _Obj* __restrict__ __result = *__free_list;
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 245,251 ****
  	    ::operator delete(__p);
  	  else
  	    {
! 	      _Obj* volatile* __free_list = _M_get_free_list(__bytes);
  	      _Obj* __q = reinterpret_cast<_Obj*>(__p);
  
  	      lock sentry(_M_get_mutex());
--- 245,251 ----
  	    ::operator delete(__p);
  	  else
  	    {
! 	      _Obj** __free_list = _M_get_free_list(__bytes);
  	      _Obj* __q = reinterpret_cast<_Obj*>(__p);
  
  	      lock sentry(_M_get_mutex());
Index: include/ext/rope
===================================================================
*** include/ext/rope	(revision 115286)
--- include/ext/rope	(working copy)
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 437,443 ****
      typedef size_t _RC_t;
      
      // The data member _M_ref_count
!     volatile _RC_t _M_ref_count;
  
      // Constructor
      __gthread_mutex_t _M_ref_count_lock;
--- 437,443 ----
      typedef size_t _RC_t;
      
      // The data member _M_ref_count
!     _RC_t _M_ref_count;
  
      // Constructor
      __gthread_mutex_t _M_ref_count_lock;
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 466,472 ****
      _M_decr()
      {
        __gthread_mutex_lock(&_M_ref_count_lock);
!       volatile _RC_t __tmp = --_M_ref_count;
        __gthread_mutex_unlock(&_M_ref_count_lock);
        return __tmp;
      }
--- 466,472 ----
      _M_decr()
      {
        __gthread_mutex_lock(&_M_ref_count_lock);
!       _RC_t __tmp = --_M_ref_count;
        __gthread_mutex_unlock(&_M_ref_count_lock);
        return __tmp;
      }
Index: include/ext/mt_allocator.h
===================================================================
*** include/ext/mt_allocator.h	(revision 115286)
--- include/ext/mt_allocator.h	(working copy)
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 195,207 ****
        union _Block_record
        {
  	// Points to the block_record of the next free block.
! 	_Block_record* volatile         _M_next;
        };
  
        struct _Bin_record
        {
  	// An "array" of pointers to the first free block.
! 	_Block_record** volatile        _M_first;
  
  	// A list of the initial addresses of all allocated blocks.
  	_Block_address*		     	_M_address;
--- 195,207 ----
        union _Block_record
        {
  	// Points to the block_record of the next free block.
! 	_Block_record* 			_M_next;
        };
  
        struct _Bin_record
        {
  	// An "array" of pointers to the first free block.
! 	_Block_record**			_M_first;
  
  	// A list of the initial addresses of all allocated blocks.
  	_Block_address*		     	_M_address;
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 244,250 ****
        // An "array" of bin_records each of which represents a specific
        // power of 2 size. Memory to this "array" is allocated in
        // _M_initialize().
!       _Bin_record* volatile	_M_bin;
        
        // Actual value calculated in _M_initialize().
        size_t 	       	     	_M_bin_size;     
--- 244,250 ----
        // An "array" of bin_records each of which represents a specific
        // power of 2 size. Memory to this "array" is allocated in
        // _M_initialize().
!       _Bin_record*		 _M_bin;
        
        // Actual value calculated in _M_initialize().
        size_t 	       	     	_M_bin_size;     
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 271,277 ****
        struct _Thread_record
        {
  	// Points to next free thread id record. NULL if last record in list.
! 	_Thread_record* volatile        _M_next;
  	
  	// Thread id ranging from 1 to _S_max_threads.
  	size_t                          _M_id;
--- 271,277 ----
        struct _Thread_record
        {
  	// Points to next free thread id record. NULL if last record in list.
! 	_Thread_record*			_M_next;
  	
  	// Thread id ranging from 1 to _S_max_threads.
  	size_t                          _M_id;
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 280,286 ****
        union _Block_record
        {
  	// Points to the block_record of the next free block.
! 	_Block_record* volatile         _M_next;
  	
  	// The thread id of the thread which has requested this block.
  	size_t                          _M_thread_id;
--- 280,286 ----
        union _Block_record
        {
  	// Points to the block_record of the next free block.
! 	_Block_record*			_M_next;
  	
  	// The thread id of the thread which has requested this block.
  	size_t                          _M_thread_id;
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 291,297 ****
  	// An "array" of pointers to the first free block for each
  	// thread id. Memory to this "array" is allocated in
  	// _S_initialize() for _S_max_threads + global pool 0.
! 	_Block_record** volatile        _M_first;
  	
  	// A list of the initial addresses of all allocated blocks.
  	_Block_address*		     	_M_address;
--- 291,297 ----
  	// An "array" of pointers to the first free block for each
  	// thread id. Memory to this "array" is allocated in
  	// _S_initialize() for _S_max_threads + global pool 0.
! 	_Block_record**			_M_first;
  	
  	// A list of the initial addresses of all allocated blocks.
  	_Block_address*		     	_M_address;
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 300,307 ****
  	// blocks that are on the freelist/used for each thread id.
  	// Memory to these "arrays" is allocated in _S_initialize() for
  	// _S_max_threads + global pool 0.
! 	size_t* volatile                _M_free;
! 	size_t* volatile                _M_used;
  	
  	// Each bin has its own mutex which is used to ensure data
  	// integrity while changing "ownership" on a block.  The mutex
--- 300,307 ----
  	// blocks that are on the freelist/used for each thread id.
  	// Memory to these "arrays" is allocated in _S_initialize() for
  	// _S_max_threads + global pool 0.
! 	size_t*				_M_free;
! 	size_t*				_M_used;
  	
  	// Each bin has its own mutex which is used to ensure data
  	// integrity while changing "ownership" on a block.  The mutex
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 365,371 ****
        // An "array" of bin_records each of which represents a specific
        // power of 2 size. Memory to this "array" is allocated in
        // _M_initialize().
!       _Bin_record* volatile	_M_bin;
  
        // Actual value calculated in _M_initialize().
        size_t 	       	     	_M_bin_size;
--- 365,371 ----
        // An "array" of bin_records each of which represents a specific
        // power of 2 size. Memory to this "array" is allocated in
        // _M_initialize().
!       _Bin_record*		_M_bin;
  
        // Actual value calculated in _M_initialize().
        size_t 	       	     	_M_bin_size;
Index: src/pool_allocator.cc
===================================================================
*** src/pool_allocator.cc	(revision 115286)
--- src/pool_allocator.cc	(working copy)
*************** namespace __gnu_internal
*** 43,49 ****
  _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
  
    // Definitions for __pool_alloc_base.
!   __pool_alloc_base::_Obj* volatile*
    __pool_alloc_base::_M_get_free_list(size_t __bytes)
    { 
      size_t __i = ((__bytes + (size_t)_S_align - 1) / (size_t)_S_align - 1);
--- 43,49 ----
  _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
  
    // Definitions for __pool_alloc_base.
!   __pool_alloc_base::_Obj**
    __pool_alloc_base::_M_get_free_list(size_t __bytes)
    { 
      size_t __i = ((__bytes + (size_t)_S_align - 1) / (size_t)_S_align - 1);
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 83,89 ****
  	// Try to make use of the left-over piece.
  	if (__bytes_left > 0)
  	  {
! 	    _Obj* volatile* __free_list = _M_get_free_list(__bytes_left);
  	    ((_Obj*)(void*)_S_start_free)->_M_free_list_link = *__free_list;
  	    *__free_list = (_Obj*)(void*)_S_start_free;
  	  }
--- 83,89 ----
  	// Try to make use of the left-over piece.
  	if (__bytes_left > 0)
  	  {
! 	    _Obj** __free_list = _M_get_free_list(__bytes_left);
  	    ((_Obj*)(void*)_S_start_free)->_M_free_list_link = *__free_list;
  	    *__free_list = (_Obj*)(void*)_S_start_free;
  	  }
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 102,108 ****
  	    size_t __i = __n;
  	    for (; __i <= (size_t) _S_max_bytes; __i += (size_t) _S_align)
  	      {
! 		_Obj* volatile* __free_list = _M_get_free_list(__i);
  		_Obj* __p = *__free_list;
  		if (__p != 0)
  		  {
--- 102,108 ----
  	    size_t __i = __n;
  	    for (; __i <= (size_t) _S_max_bytes; __i += (size_t) _S_align)
  	      {
! 		_Obj** __free_list = _M_get_free_list(__i);
  		_Obj* __p = *__free_list;
  		if (__p != 0)
  		  {
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 132,138 ****
    {
      int __nobjs = 20;
      char* __chunk = _M_allocate_chunk(__n, __nobjs);
!     _Obj* volatile* __free_list;
      _Obj* __result;
      _Obj* __current_obj;
      _Obj* __next_obj;
--- 132,138 ----
    {
      int __nobjs = 20;
      char* __chunk = _M_allocate_chunk(__n, __nobjs);
!     _Obj** __free_list;
      _Obj* __result;
      _Obj* __current_obj;
      _Obj* __next_obj;
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 159,165 ****
      return __result;
    }
  
!   __pool_alloc_base::_Obj* volatile __pool_alloc_base::_S_free_list[_S_free_list_size];
    
    char* __pool_alloc_base::_S_start_free = 0;
    
--- 159,165 ----
      return __result;
    }
  
!   __pool_alloc_base::_Obj* __pool_alloc_base::_S_free_list[_S_free_list_size];
    
    char* __pool_alloc_base::_S_start_free = 0;
    



More information about the Gcc-patches mailing list