aboutsummaryrefslogtreecommitdiff
path: root/gcc/gthr-dce.h
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2004-08-27 22:33:54 -0400
committerJason Merrill <jason@gcc.gnu.org>2004-08-27 22:33:54 -0400
commit40aac94801f86355bd86cf5b340481ee2f501d3c (patch)
tree1f0fd6ce16170d90ee5ebfcb5972ed7af5874607 /gcc/gthr-dce.h
parented3479983db246f3126c12c441659ef6b8ed027e (diff)
downloadgcc-40aac94801f86355bd86cf5b340481ee2f501d3c.zip
gcc-40aac94801f86355bd86cf5b340481ee2f501d3c.tar.gz
gcc-40aac94801f86355bd86cf5b340481ee2f501d3c.tar.bz2
re PR c++/13684 (local static object variable constructed once but ctors and dtors called multiple times on same memory when called in multiple threads)
PR c++/13684 * cp/decl.c (expand_static_init): Use thread-safety API. (register_dtor_fn): Return the call, don't expand it. * cp/tree.c (add_stmt_to_compound): New fn. (stabilize_call): Use it. * gimplify.c (gimplify_cleanup_point_expr): Handle CLEANUP_EH_ONLY. (gimple_push_cleanup): Add eh_only parm. (gimplify_target_expr): Pass it. * c.opt (-fno-threadsafe-statics): New option. * c-opts.c (c_common_handle_option): Handle it. * c-common.h (flag_threadsafe_statics): Declare it. * c-common.c (flag_threadsafe_statics): Record it. * doc/invoke.texi: Document it. * tsystem.h (_GNU_SOURCE): Define. * gthr-posix.h (__gthread_recursive_mutex_t): New typedef. (__GTHREAD_RECURSIVE_MUTEX_INIT): New macro. (__GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION): New macro. (__gthread_recursive_mutex_init_function): New fn. (__gthread_recursive_mutex_lock): New fn. (__gthread_recursive_mutex_trylock): New fn. (__gthread_recursive_mutex_unlock): New fn. * gthr-solaris.h, gthr-single.h, gthr-dce.h: Likewise. * gthr-win32.h, gthr-vxworks.h: Likewise. * gthr.h: Document. * libsupc++/guard.cc (static_mutex): Internal class implementing a recursive mutex which controls initialization of local statics. (__gnu_cxx::recursive_init): New exception class. (__cxa_guard_acquire): Deal with locking and recursion detection. (acquire_1, __cxa_guard_abort, __cxa_guard_release): Likewise. From-SVN: r86687
Diffstat (limited to 'gcc/gthr-dce.h')
-rw-r--r--gcc/gthr-dce.h41
1 files changed, 40 insertions, 1 deletions
diff --git a/gcc/gthr-dce.h b/gcc/gthr-dce.h
index 563754e..ccdf82d 100644
--- a/gcc/gthr-dce.h
+++ b/gcc/gthr-dce.h
@@ -1,4 +1,4 @@
-
+/* Threads compatibility routines for libgcc2 and libobjc. */
/* Compile this one with gcc. */
/* Copyright (C) 1997, 1999, 2000, 2001 Free Software Foundation, Inc.
@@ -52,10 +52,12 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
typedef pthread_key_t __gthread_key_t;
typedef pthread_once_t __gthread_once_t;
typedef pthread_mutex_t __gthread_mutex_t;
+typedef pthread_mutex_t __gthread_recursive_mutex_t;
#define __GTHREAD_ONCE_INIT pthread_once_init
#define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
+#define __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION __gthread_recursive_mutex_init_function
#define __GTHREAD_MUTEX_INIT_DEFAULT pthread_once_init
@@ -481,6 +483,43 @@ __gthread_mutex_unlock (__gthread_mutex_t *mutex)
return 0;
}
+static inline int
+__gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *mutex)
+{
+ if (__gthread_active_p ())
+ {
+ pthread_mutexattr_t attr;
+ int r;
+
+ r = pthread_mutexattr_create (&attr);
+ if (!r)
+ r = pthread_mutexattr_setkind_np (&attr, MUTEX_RECURSIVE_NP);
+ if (!r)
+ r = pthread_mutex_init (mutex, attr);
+ if (!r)
+ r = pthread_mutexattr_delete (&attr);
+ return r;
+ }
+}
+
+static inline int
+__gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *mutex)
+{
+ return __gthread_mutex_lock (mutex);
+}
+
+static inline int
+__gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *mutex)
+{
+ return __gthread_mutex_trylock (mutex);
+}
+
+static inline int
+__gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex)
+{
+ return __gthread_mutex_unlock (mutex);
+}
+
#endif /* _LIBOBJC */
#undef UNUSED