re PR libstdc++/24704 (__gnu_cxx::__exchange_and_add is called even for single threaded applications)
2006-05-24 Paolo Carlini <pcarlini@suse.de> PR libstdc++/24704 * include/bits/atomicity.h (__exchange_and_add_single, __atomic_add_single): New, single thread versions of the atomic functions. (__exchange_and_add_dispatch, __atomic_add_dispatch): New, depending on __GTHREADS and __gthread_active_p() dispatch either to the above or to the existing atomic functions. * include/ext/pool_allocator.h: Update callers. * include/ext/rc_string_base.h: Likewise. * include/bits/locale_classes.h: Likewise. * include/bits/basic_string.h: Likewise. * include/bits/ios_base.h: Likewise. * include/tr1/boost_shared_ptr.h: Likewise. * src/ios.cc: Likewise. * src/locale.cc: Likewise. * src/ios_init.cc: Likewise. From-SVN: r114044
This commit is contained in:
parent
cc07b2dbeb
commit
b7ee72de2d
|
@ -1,3 +1,22 @@
|
||||||
|
2006-05-24 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
|
||||||
|
PR libstdc++/24704
|
||||||
|
* include/bits/atomicity.h (__exchange_and_add_single,
|
||||||
|
__atomic_add_single): New, single thread versions of the atomic
|
||||||
|
functions.
|
||||||
|
(__exchange_and_add_dispatch, __atomic_add_dispatch): New,
|
||||||
|
depending on __GTHREADS and __gthread_active_p() dispatch either
|
||||||
|
to the above or to the existing atomic functions.
|
||||||
|
* include/ext/pool_allocator.h: Update callers.
|
||||||
|
* include/ext/rc_string_base.h: Likewise.
|
||||||
|
* include/bits/locale_classes.h: Likewise.
|
||||||
|
* include/bits/basic_string.h: Likewise.
|
||||||
|
* include/bits/ios_base.h: Likewise.
|
||||||
|
* include/tr1/boost_shared_ptr.h: Likewise.
|
||||||
|
* src/ios.cc: Likewise.
|
||||||
|
* src/locale.cc: Likewise.
|
||||||
|
* src/ios_init.cc: Likewise.
|
||||||
|
|
||||||
2006-05-23 Paolo Carlini <pcarlini@suse.de>
|
2006-05-23 Paolo Carlini <pcarlini@suse.de>
|
||||||
|
|
||||||
* testsuite/testsuite_shared.cc: Fix --enable-threads=single build.
|
* testsuite/testsuite_shared.cc: Fix --enable-threads=single build.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Low-level functions for atomic operations -*- C++ -*-
|
// Low-level functions for atomic operations -*- C++ -*-
|
||||||
|
|
||||||
// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
|
// Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
|
||||||
//
|
//
|
||||||
// This file is part of the GNU ISO C++ Library. This library is free
|
// This file is part of the GNU ISO C++ Library. This library is free
|
||||||
// software; you can redistribute it and/or modify it under the
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
@ -36,11 +36,12 @@
|
||||||
#define _GLIBCXX_ATOMICITY_H 1
|
#define _GLIBCXX_ATOMICITY_H 1
|
||||||
|
|
||||||
#include <bits/c++config.h>
|
#include <bits/c++config.h>
|
||||||
|
#include <bits/gthr.h>
|
||||||
#include <bits/atomic_word.h>
|
#include <bits/atomic_word.h>
|
||||||
|
|
||||||
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
|
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
|
||||||
|
|
||||||
_Atomic_word
|
_Atomic_word
|
||||||
__attribute__ ((__unused__))
|
__attribute__ ((__unused__))
|
||||||
__exchange_and_add(volatile _Atomic_word* __mem, int __val);
|
__exchange_and_add(volatile _Atomic_word* __mem, int __val);
|
||||||
|
|
||||||
|
@ -48,6 +49,54 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
|
||||||
__attribute__ ((__unused__))
|
__attribute__ ((__unused__))
|
||||||
__atomic_add(volatile _Atomic_word* __mem, int __val);
|
__atomic_add(volatile _Atomic_word* __mem, int __val);
|
||||||
|
|
||||||
|
static inline _Atomic_word
|
||||||
|
__exchange_and_add_single(volatile _Atomic_word* __mem, int __val)
|
||||||
|
{
|
||||||
|
_Atomic_word __result = *__mem;
|
||||||
|
*__mem += __val;
|
||||||
|
return __result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
__atomic_add_single(volatile _Atomic_word* __mem, int __val)
|
||||||
|
{ *__mem += __val; }
|
||||||
|
|
||||||
|
static inline _Atomic_word
|
||||||
|
__attribute__ ((__unused__))
|
||||||
|
__exchange_and_add_dispatch(volatile _Atomic_word* __mem, int __val)
|
||||||
|
{
|
||||||
|
#ifdef __GTHREADS
|
||||||
|
|
||||||
|
if (__gthread_active_p())
|
||||||
|
return __exchange_and_add(__mem, __val);
|
||||||
|
else
|
||||||
|
return __exchange_and_add_single(__mem, __val);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
return __exchange_and_add_single(__mem, __val);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
__attribute__ ((__unused__))
|
||||||
|
__atomic_add_dispatch(volatile _Atomic_word* __mem, int __val)
|
||||||
|
{
|
||||||
|
#ifdef __GTHREADS
|
||||||
|
|
||||||
|
if (__gthread_active_p())
|
||||||
|
__atomic_add(__mem, __val);
|
||||||
|
else
|
||||||
|
__atomic_add_single(__mem, __val);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
__atomic_add_single(__mem, __val);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
_GLIBCXX_END_NAMESPACE
|
_GLIBCXX_END_NAMESPACE
|
||||||
|
|
||||||
/* Even if the CPU doesn't need a memory barrier, we need to ensure that
|
/* Even if the CPU doesn't need a memory barrier, we need to ensure that
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Components for manipulating sequences of characters -*- C++ -*-
|
// Components for manipulating sequences of characters -*- C++ -*-
|
||||||
|
|
||||||
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
|
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
|
||||||
// Free Software Foundation, Inc.
|
// Free Software Foundation, Inc.
|
||||||
//
|
//
|
||||||
// This file is part of the GNU ISO C++ Library. This library is free
|
// This file is part of the GNU ISO C++ Library. This library is free
|
||||||
|
@ -232,7 +232,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
|
#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
|
||||||
if (__builtin_expect(this != &_S_empty_rep(), false))
|
if (__builtin_expect(this != &_S_empty_rep(), false))
|
||||||
#endif
|
#endif
|
||||||
if (__gnu_cxx::__exchange_and_add(&this->_M_refcount, -1) <= 0)
|
if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
|
||||||
|
-1) <= 0)
|
||||||
_M_destroy(__a);
|
_M_destroy(__a);
|
||||||
} // XXX MT
|
} // XXX MT
|
||||||
|
|
||||||
|
@ -245,7 +246,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
|
#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING
|
||||||
if (__builtin_expect(this != &_S_empty_rep(), false))
|
if (__builtin_expect(this != &_S_empty_rep(), false))
|
||||||
#endif
|
#endif
|
||||||
__gnu_cxx::__atomic_add(&this->_M_refcount, 1);
|
__gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
|
||||||
return _M_refdata();
|
return _M_refdata();
|
||||||
} // XXX MT
|
} // XXX MT
|
||||||
|
|
||||||
|
|
|
@ -476,12 +476,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
: _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { }
|
: _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { }
|
||||||
|
|
||||||
void
|
void
|
||||||
_M_add_reference() { __gnu_cxx::__atomic_add(&_M_refcount, 1); }
|
_M_add_reference() { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
|
||||||
|
|
||||||
// 0 => OK to delete.
|
// 0 => OK to delete.
|
||||||
int
|
int
|
||||||
_M_remove_reference()
|
_M_remove_reference()
|
||||||
{ return __gnu_cxx::__exchange_and_add(&_M_refcount, -1); }
|
{ return __gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1); }
|
||||||
};
|
};
|
||||||
|
|
||||||
_Callback_list* _M_callbacks;
|
_Callback_list* _M_callbacks;
|
||||||
|
|
|
@ -400,12 +400,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
private:
|
private:
|
||||||
inline void
|
inline void
|
||||||
_M_add_reference() const throw()
|
_M_add_reference() const throw()
|
||||||
{ __gnu_cxx::__atomic_add(&_M_refcount, 1); }
|
{ __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
_M_remove_reference() const throw()
|
_M_remove_reference() const throw()
|
||||||
{
|
{
|
||||||
if (__gnu_cxx::__exchange_and_add(&_M_refcount, -1) == 1)
|
if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{ delete this; }
|
{ delete this; }
|
||||||
|
@ -505,12 +505,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
_M_add_reference() throw()
|
_M_add_reference() throw()
|
||||||
{ __gnu_cxx::__atomic_add(&_M_refcount, 1); }
|
{ __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
_M_remove_reference() throw()
|
_M_remove_reference() throw()
|
||||||
{
|
{
|
||||||
if (__gnu_cxx::__exchange_and_add(&_M_refcount, -1) == 1)
|
if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{ delete this; }
|
{ delete this; }
|
||||||
|
|
|
@ -206,9 +206,9 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
|
||||||
if (_S_force_new == 0)
|
if (_S_force_new == 0)
|
||||||
{
|
{
|
||||||
if (std::getenv("GLIBCXX_FORCE_NEW"))
|
if (std::getenv("GLIBCXX_FORCE_NEW"))
|
||||||
__atomic_add(&_S_force_new, 1);
|
__atomic_add_dispatch(&_S_force_new, 1);
|
||||||
else
|
else
|
||||||
__atomic_add(&_S_force_new, -1);
|
__atomic_add_dispatch(&_S_force_new, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t __bytes = __n * sizeof(_Tp);
|
const size_t __bytes = __n * sizeof(_Tp);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Reference-counted versatile string base -*- C++ -*-
|
// Reference-counted versatile string base -*- C++ -*-
|
||||||
|
|
||||||
// Copyright (C) 2005 Free Software Foundation, Inc.
|
// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
|
||||||
//
|
//
|
||||||
// This file is part of the GNU ISO C++ Library. This library is free
|
// This file is part of the GNU ISO C++ Library. This library is free
|
||||||
// software; you can redistribute it and/or modify it under the
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
@ -134,7 +134,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
|
||||||
_CharT*
|
_CharT*
|
||||||
_M_refcopy() throw()
|
_M_refcopy() throw()
|
||||||
{
|
{
|
||||||
__atomic_add(&_M_info._M_refcount, 1);
|
__atomic_add_dispatch(&_M_info._M_refcount, 1);
|
||||||
return _M_refdata();
|
return _M_refdata();
|
||||||
} // XXX MT
|
} // XXX MT
|
||||||
|
|
||||||
|
@ -202,7 +202,8 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
|
||||||
void
|
void
|
||||||
_M_dispose()
|
_M_dispose()
|
||||||
{
|
{
|
||||||
if (__exchange_and_add(&_M_rep()->_M_info._M_refcount, -1) <= 0)
|
if (__exchange_and_add_dispatch(&_M_rep()->_M_info._M_refcount,
|
||||||
|
-1) <= 0)
|
||||||
_M_rep()->_M_destroy(_M_get_allocator());
|
_M_rep()->_M_destroy(_M_get_allocator());
|
||||||
} // XXX MT
|
} // XXX MT
|
||||||
|
|
||||||
|
|
|
@ -130,14 +130,14 @@ public:
|
||||||
void
|
void
|
||||||
add_ref_copy()
|
add_ref_copy()
|
||||||
{
|
{
|
||||||
__gnu_cxx::__atomic_add(&_M_use_count, 1);
|
__gnu_cxx::__atomic_add_dispatch(&_M_use_count, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
add_ref_lock()
|
add_ref_lock()
|
||||||
{
|
{
|
||||||
__gnu_cxx::lock lock(_M_mutex);
|
__gnu_cxx::lock lock(_M_mutex);
|
||||||
if (__gnu_cxx::__exchange_and_add(&_M_use_count, 1) == 0)
|
if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, 1) == 0)
|
||||||
{
|
{
|
||||||
_M_use_count = 0;
|
_M_use_count = 0;
|
||||||
__throw_bad_weak_ptr();
|
__throw_bad_weak_ptr();
|
||||||
|
@ -147,14 +147,14 @@ public:
|
||||||
void
|
void
|
||||||
release() // nothrow
|
release() // nothrow
|
||||||
{
|
{
|
||||||
if (__gnu_cxx::__exchange_and_add(&_M_use_count, -1) == 1)
|
if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, -1) == 1)
|
||||||
{
|
{
|
||||||
dispose();
|
dispose();
|
||||||
#ifdef __GTHREADS
|
#ifdef __GTHREADS
|
||||||
_GLIBCXX_READ_MEM_BARRIER;
|
_GLIBCXX_READ_MEM_BARRIER;
|
||||||
_GLIBCXX_WRITE_MEM_BARRIER;
|
_GLIBCXX_WRITE_MEM_BARRIER;
|
||||||
#endif
|
#endif
|
||||||
if (__gnu_cxx::__exchange_and_add(&_M_weak_count, -1) == 1)
|
if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count, -1) == 1)
|
||||||
destroy();
|
destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,13 +162,13 @@ public:
|
||||||
void
|
void
|
||||||
weak_add_ref() // nothrow
|
weak_add_ref() // nothrow
|
||||||
{
|
{
|
||||||
__gnu_cxx::__atomic_add(&_M_weak_count, 1);
|
__gnu_cxx::__atomic_add_dispatch(&_M_weak_count, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
weak_release() // nothrow
|
weak_release() // nothrow
|
||||||
{
|
{
|
||||||
if (__gnu_cxx::__exchange_and_add(&_M_weak_count, -1) == 1)
|
if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count, -1) == 1)
|
||||||
{
|
{
|
||||||
#ifdef __GTHREADS
|
#ifdef __GTHREADS
|
||||||
_GLIBCXX_READ_MEM_BARRIER;
|
_GLIBCXX_READ_MEM_BARRIER;
|
||||||
|
|
|
@ -107,7 +107,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
// Implementation note: Initialize top to zero to ensure that
|
// Implementation note: Initialize top to zero to ensure that
|
||||||
// initialization occurs before main() is started.
|
// initialization occurs before main() is started.
|
||||||
static _Atomic_word _S_top = 0;
|
static _Atomic_word _S_top = 0;
|
||||||
return __gnu_cxx::__exchange_and_add(&_S_top, 1) + 4;
|
return __gnu_cxx::__exchange_and_add_dispatch(&_S_top, 1) + 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -82,7 +82,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
|
|
||||||
ios_base::Init::Init()
|
ios_base::Init::Init()
|
||||||
{
|
{
|
||||||
if (__gnu_cxx::__exchange_and_add(&_S_refcount, 1) == 0)
|
if (__gnu_cxx::__exchange_and_add_dispatch(&_S_refcount, 1) == 0)
|
||||||
{
|
{
|
||||||
// Standard streams default to synced with "C" operations.
|
// Standard streams default to synced with "C" operations.
|
||||||
_S_synced_with_stdio = true;
|
_S_synced_with_stdio = true;
|
||||||
|
@ -121,13 +121,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
// streams are not re-initialized with uses of ios_base::Init
|
// streams are not re-initialized with uses of ios_base::Init
|
||||||
// besides <iostream> static object, ie just using <ios> with
|
// besides <iostream> static object, ie just using <ios> with
|
||||||
// ios_base::Init objects.
|
// ios_base::Init objects.
|
||||||
__gnu_cxx::__atomic_add(&_S_refcount, 1);
|
__gnu_cxx::__atomic_add_dispatch(&_S_refcount, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ios_base::Init::~Init()
|
ios_base::Init::~Init()
|
||||||
{
|
{
|
||||||
if (__gnu_cxx::__exchange_and_add(&_S_refcount, -1) == 2)
|
if (__gnu_cxx::__exchange_and_add_dispatch(&_S_refcount, -1) == 2)
|
||||||
{
|
{
|
||||||
// Catch any exceptions thrown by basic_ostream::flush()
|
// Catch any exceptions thrown by basic_ostream::flush()
|
||||||
try
|
try
|
||||||
|
|
|
@ -433,7 +433,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
|
||||||
_M_index = 1 + f->_M_id();
|
_M_index = 1 + f->_M_id();
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
_M_index = 1 + __gnu_cxx::__exchange_and_add(&_S_refcount, 1);
|
_M_index = 1 + __gnu_cxx::__exchange_and_add_dispatch(&_S_refcount,
|
||||||
|
1);
|
||||||
}
|
}
|
||||||
return _M_index - 1;
|
return _M_index - 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue