diff options
| author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-08-12 22:56:59 +0000 |
|---|---|---|
| committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-08-12 22:56:59 +0000 |
| commit | d8155f717c2ac0ba8a6251bdfa0e50fc90c9a181 (patch) | |
| tree | 0e6c156d49fe7f64d815154ccc4cbd3c33f02455 /libstdc++-v3/include | |
| parent | 99b66d21e0d1073bc594d7bfaa0422c77db449cc (diff) | |
| download | ppe42-gcc-d8155f717c2ac0ba8a6251bdfa0e50fc90c9a181.tar.gz ppe42-gcc-d8155f717c2ac0ba8a6251bdfa0e50fc90c9a181.zip | |
2010-08-12 Kostya Serebryany <kcc@google.com>
Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/c++config (_GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE,
_GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER): Add.
* src/ios_init.cc (ios_base::Init::~Init): Decorate with the
latter.
* include/tr1_impl/boost_sp_counted_base.h: Likewise.
* 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.
* testsuite/27_io/ios_base/cons/assign_neg.cc: Adjust dg-error
line number.
* testsuite/27_io/ios_base/cons/copy_neg.cc: Likewise.
* testsuite/ext/profile/mutex_extensions.cc: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@163210 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include')
| -rw-r--r-- | libstdc++-v3/include/bits/basic_string.h | 13 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/c++config | 29 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/ios_base.h | 12 | ||||
| -rw-r--r-- | libstdc++-v3/include/bits/locale_classes.h | 6 | ||||
| -rw-r--r-- | libstdc++-v3/include/ext/rc_string_base.h | 9 | ||||
| -rw-r--r-- | libstdc++-v3/include/tr1_impl/boost_sp_counted_base.h | 15 |
6 files changed, 76 insertions, 8 deletions
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index fe9e1a3519c..74820eb348e 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -232,9 +232,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std) #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING if (__builtin_expect(this != &_S_empty_rep(), false)) #endif - if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount, - -1) <= 0) - _M_destroy(__a); + { + // Be race-detector-friendly. For more info see bits/c++config. + _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount) + if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount, + -1) <= 0) + { + _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount) + _M_destroy(__a); + } + } } // XXX MT void diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config index 9dc9ac24cd8..fef6933a3b5 100644 --- a/libstdc++-v3/include/bits/c++config +++ b/libstdc++-v3/include/bits/c++config @@ -60,6 +60,35 @@ # define _GLIBCXX_DEPRECATED_ATTR #endif +// Macros for race detectors. +// _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(A) and +// _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(A) should be used to explain +// atomic (lock-free) synchronization to race detectors: +// the race detector will infer a happens-before arc from the former to the +// latter when they share the same argument pointer. +// +// The most frequent use case for these macros (and the only case in the +// current implementation of the library) is atomic reference counting: +// void _M_remove_reference() +// { +// _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount) +// if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount, -1) <= 0) +// { +// _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount) +// _M_destroy(__a); +// } +// } +// The annotations in this example tell the race detector that all memory +// accesses occurred when the refcount was positive do not race with +// memory accesses which occurred after the refcount became zero. + +#ifndef _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE +# define _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(A) +#endif +#ifndef _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER +# define _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(A) +#endif + // Macros for activating various namespace association modes. // _GLIBCXX_NAMESPACE_ASSOCIATION_DEBUG // _GLIBCXX_NAMESPACE_ASSOCIATION_PARALLEL diff --git a/libstdc++-v3/include/bits/ios_base.h b/libstdc++-v3/include/bits/ios_base.h index 6515dd40e8e..6cca99166ca 100644 --- a/libstdc++-v3/include/bits/ios_base.h +++ b/libstdc++-v3/include/bits/ios_base.h @@ -474,7 +474,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // 0 => OK to delete. int _M_remove_reference() - { return __gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1); } + { + // Be race-detector-friendly. For more info see bits/c++config. + _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_refcount) + int __res = __gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1); + if (__res == 0) + { + _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_refcount) + } + return __res; + } }; _Callback_list* _M_callbacks; @@ -962,4 +971,3 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_END_NAMESPACE #endif /* _IOS_BASE_H */ - diff --git a/libstdc++-v3/include/bits/locale_classes.h b/libstdc++-v3/include/bits/locale_classes.h index 347e7612486..c519f358476 100644 --- a/libstdc++-v3/include/bits/locale_classes.h +++ b/libstdc++-v3/include/bits/locale_classes.h @@ -402,8 +402,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) void _M_remove_reference() const throw() { + // Be race-detector-friendly. For more info see bits/c++config. + _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_refcount) if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1) { + _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_refcount) __try { delete this; } __catch(...) @@ -508,8 +511,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) void _M_remove_reference() throw() { + // Be race-detector-friendly. For more info see bits/c++config. + _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_refcount) if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1) { + _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_refcount) __try { delete this; } __catch(...) diff --git a/libstdc++-v3/include/ext/rc_string_base.h b/libstdc++-v3/include/ext/rc_string_base.h index dd18738dc57..32c9d3865ae 100644 --- a/libstdc++-v3/include/ext/rc_string_base.h +++ b/libstdc++-v3/include/ext/rc_string_base.h @@ -199,9 +199,16 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) void _M_dispose() { + // Be race-detector-friendly. For more info see bits/c++config. + _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_rep()->_M_info. + _M_refcount) if (__exchange_and_add_dispatch(&_M_rep()->_M_info._M_refcount, -1) <= 0) - _M_rep()->_M_destroy(_M_get_allocator()); + { + _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_rep()->_M_info. + _M_refcount) + _M_rep()->_M_destroy(_M_get_allocator()); + } } // XXX MT bool diff --git a/libstdc++-v3/include/tr1_impl/boost_sp_counted_base.h b/libstdc++-v3/include/tr1_impl/boost_sp_counted_base.h index 56030856dca..a995df5bb76 100644 --- a/libstdc++-v3/include/tr1_impl/boost_sp_counted_base.h +++ b/libstdc++-v3/include/tr1_impl/boost_sp_counted_base.h @@ -1,6 +1,6 @@ // <tr1_impl/boost_sp_counted_base.h> -*- C++ -*- -// Copyright (C) 2007, 2009 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. // // 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 @@ -139,8 +139,11 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 void _M_release() // nothrow { + // Be race-detector-friendly. For more info see bits/c++config. + _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_use_count) if (__gnu_cxx::__exchange_and_add_dispatch(&_M_use_count, -1) == 1) { + _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_use_count) _M_dispose(); // There must be a memory barrier between dispose() and destroy() // to ensure that the effects of dispose() are observed in the @@ -152,9 +155,14 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 _GLIBCXX_WRITE_MEM_BARRIER; } + // Be race-detector-friendly. For more info see bits/c++config. + _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_weak_count) if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count, -1) == 1) - _M_destroy(); + { + _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_weak_count) + _M_destroy(); + } } } @@ -165,8 +173,11 @@ _GLIBCXX_BEGIN_NAMESPACE_TR1 void _M_weak_release() // nothrow { + // Be race-detector-friendly. For more info see bits/c++config. + _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_weak_count) if (__gnu_cxx::__exchange_and_add_dispatch(&_M_weak_count, -1) == 1) { + _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_weak_count) if (_Mutex_base<_Lp>::_S_need_barriers) { // See _M_release(), |

