diff options
author | Jason Merrill <jason@redhat.com> | 2004-12-27 23:36:54 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2004-12-27 23:36:54 -0500 |
commit | 445cf5eb0d91d2aa401ff3907fcf993a44e4c8b4 (patch) | |
tree | d723d1a31c0c3358f41a176191bde7ef4add806e /gcc/cp | |
parent | 1f7edb8b3d65da166df57999ae6053bfdbf939de (diff) | |
download | gcc-445cf5eb0d91d2aa401ff3907fcf993a44e4c8b4.zip gcc-445cf5eb0d91d2aa401ff3907fcf993a44e4c8b4.tar.gz gcc-445cf5eb0d91d2aa401ff3907fcf993a44e4c8b4.tar.bz2 |
Add memory barriers to the double-checked locking used for static initialization.
libstdc++:
Add memory barriers to the double-checked locking used for static
initialization.
* libsupc++/guard.cc (__test_and_acquire): Define default.
(_GLIBCXX_GUARD_TEST_AND_ACQUIRE, __set_and_release)
(_GLIBCXX_GUARD_SET_AND_RELEASE): Likewise.
(recursion_push, recursion_pop): New abstraction functions.
(__cxa_guard_acquire): Use _GLIBCXX_GUARD_TEST_AND_ACQUIRE.
(__cxa_guard_release): Use _GLIBCXX_GUARD_SET_AND_RELEASE.
* config/cpu/generic/cxxabi_tweaks.h (_GLIBCXX_GUARD_TEST): Rename
from _GLIBCXX_GUARD_ACQUIRE and reverse sense.
(_GLIBCXX_GUARD_SET): Rename from _GLIBCXX_GUARD_RELEASE.
* config/cpu/arm/cxxabi_tweaks.h: Likewise.
* config/cpu/alpha/atomic_word.h (_GLIBCXX_READ_MEM_BARRIER)
(_GLIBCXX_WRITE_MEM_BARRIER): Define.
* config/cpu/powerpc/atomic_word.h: Likewise.
* config/cpu/sparc/atomic_word.h: Likewise.
* config/cpu/generic/atomic_word.h: Define them, commented out.
* include/bits/atomicity.h: Define defaults.
* config/cpu/ia64/atomic_word.h (__test_and_acquire)
(__set_and_release): New inlines.
(_GLIBCXX_GUARD_TEST_AND_ACQUIRE): Define.
(_GLIBCXX_GUARD_SET_AND_RELEASE): Define.
* libsupc++/guard.cc (acquire_1): Use __builtin_trap instead of
abort();
gcc:
* doc/tm.texi (TARGET_RELAXED_ORDERING): Document.
* target.h (struct gcc_target): Add relaxed_ordering field.
* target-def.h (TARGET_RELAXED_ORDERING): Define default.
(TARGET_INITIALIZER): Add it.
* config/alpha/alpha.c (TARGET_RELAXED_ORDERING): Define.
* config/ia64/ia64.c (TARGET_RELAXED_ORDERING): Define.
* config/rs6000/rs6000.c (TARGET_RELAXED_ORDERING): Define.
* config/sparc/sparc.c (TARGET_RELAXED_ORDERING): Define.
* cp/decl.c (expand_static_init): Don't use shortcut if
targetm.relaxed_ordering.
From-SVN: r92659
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/decl.c | 27 |
2 files changed, 23 insertions, 9 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a62a61e..622a001 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2004-12-27 Jason Merrill <jason@redhat.com> + + * decl.c (expand_static_init): Don't use shortcut if + targetm.relaxed_ordering. + 2004-12-27 Mark Mitchell <mark@codesourcery.com> PR c++/19149 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 991996b..7a839d7 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5313,8 +5313,8 @@ expand_static_init (tree decl, tree init) if (DECL_FUNCTION_SCOPE_P (decl)) { /* Emit code to perform this initialization but once. */ - tree if_stmt, inner_if_stmt = NULL_TREE; - tree then_clause, inner_then_clause = NULL_TREE; + tree if_stmt = NULL_TREE, inner_if_stmt = NULL_TREE; + tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE; tree guard, guard_addr, guard_addr_list; tree acquire_fn, release_fn, abort_fn; tree flag, begin; @@ -5353,10 +5353,16 @@ expand_static_init (tree decl, tree init) /* Create the guard variable. */ guard = get_guard (decl); - /* Begin the conditional initialization. */ - if_stmt = begin_if_stmt (); - finish_if_stmt_cond (get_guard_cond (guard), if_stmt); - then_clause = begin_compound_stmt (BCS_NO_SCOPE); + /* This optimization isn't safe on targets with relaxed memory + consistency. On such targets we force synchronization in + __cxa_guard_acquire. */ + if (!targetm.relaxed_ordering || !flag_threadsafe_statics) + { + /* Begin the conditional initialization. */ + if_stmt = begin_if_stmt (); + finish_if_stmt_cond (get_guard_cond (guard), if_stmt); + then_clause = begin_compound_stmt (BCS_NO_SCOPE); + } if (flag_threadsafe_statics) { @@ -5419,9 +5425,12 @@ expand_static_init (tree decl, tree init) finish_if_stmt (inner_if_stmt); } - finish_compound_stmt (then_clause); - finish_then_clause (if_stmt); - finish_if_stmt (if_stmt); + if (!targetm.relaxed_ordering || !flag_threadsafe_statics) + { + finish_compound_stmt (then_clause); + finish_then_clause (if_stmt); + finish_if_stmt (if_stmt); + } } else static_aggregates = tree_cons (init, decl, static_aggregates); |