This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: *ping* generic atomicity.h
- From: Danny Smith <danny_r_smith_2001 at yahoo dot co dot nz>
- To: phil at jaj dot com
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Sat, 25 Jan 2003 11:05:05 +1100 (EST)
- Subject: Re: *ping* generic atomicity.h
Phil Edwards <phil at jaj dot com> wrote:
> On Wed, Jan 01, 2003 at 08:32:44PM +1100, Danny Smith wrote:
>> The patch presented here:
>>
>> http://gcc.gnu.org/ml/libstdc++/2002-12/msg00015.html
>>
>> does not work on i386-pc-mingw32 which does need
>> __GTHREAD_MUTEX_INIT_FUNCTION.
>>
>> The main problem is with lack of support for __attribute__((weak)) but
>> there are other problmes as well. See annotated patch below,
>
> Okay, I've appended an updated patch.
Almost, but definition of globals in headers cause multiple definition
problems.
Patch with following modification works okay on mingw32.
* Move definition/initialisation of _Atomic_add_mutex_once
and _Atomic_add_mutex from config/cpu/generic/atomicity.h
to src/inst_misc.cc.
I have only tested on 3.3. I've just returned from holiday and trunk is
throwing some unrelated problems which I have not yet worked through.
Danny
Index: ./config/cpu/generic/atomicity.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/cpu/generic/atomicity.h,v
retrieving revision 1.4
diff -u -3 -p -r1.4 atomicity.h
--- ./config/cpu/generic/atomicity.h 8 Nov 2002 19:24:41 -0000 1.4
+++ ./config/cpu/generic/atomicity.h 24 Jan 2003 23:49:23 -0000
@@ -1,6 +1,6 @@
// Low-level functions for atomic operations: Generic version -*- C++ -*-
-// Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
+// Copyright (C) 1999, 2001, 2002, 2003 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
@@ -36,20 +36,30 @@ typedef int _Atomic_word;
namespace __gnu_cxx
{
- __gthread_mutex_t _Atomic_add_mutex __attribute__ ((__weak__))
- = __GTHREAD_MUTEX_INIT;
+ extern __gthread_mutex_t _Atomic_add_mutex;
+
+#ifndef __GTHREAD_MUTEX_INIT
+# define __GTHREAD_NEED_MUTEX_ONCE_FUNCTION
+ extern __gthread_once_t _Atomic_add_mutex_once;
+ extern void __gthread_atomic_add_mutex_once();
+#endif
}
static inline _Atomic_word
__attribute__ ((__unused__))
__exchange_and_add (volatile _Atomic_word* __mem, int __val)
{
- _Atomic_word __result;
+ _Atomic_word __result;
+
+#ifndef __GTHREAD_MUTEX_INIT
+ __gthread_once (&__gnu_cxx::_Atomic_add_mutex_once,
+ __gnu_cxx::__gthread_atomic_add_mutex_once);
+#endif
- __gthread_mutex_lock (&__gnu_cxx::_Atomic_add_mutex);
+ __gthread_mutex_lock (&__gnu_cxx::_Atomic_add_mutex);
- __result = *__mem;
- *__mem += __val;
+ __result = *__mem;
+ *__mem += __val;
__gthread_mutex_unlock (&__gnu_cxx::_Atomic_add_mutex);
return __result;
Index: ./src/misc-inst.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/misc-inst.cc,v
retrieving revision 1.20
diff -u -3 -p -r1.20 misc-inst.cc
--- ./src/misc-inst.cc 5 Nov 2002 19:17:37 -0000 1.20
+++ ./src/misc-inst.cc 24 Jan 2003 23:49:23 -0000
@@ -87,3 +87,18 @@ namespace std
string*, __false_type);
#endif
} // namespace std
+
+namespace __gnu_cxx
+{
+#ifdef __GTHREAD_MUTEX_INIT
+ __gthread_mutex_t _Atomic_add_mutex = __GTHREAD_MUTEX_INIT;
+#else
+ // generic atomicity.h without static initialization
+ __gthread_mutex_t _Atomic_add_mutex;
+ __gthread_once_t _Atomic_add_mutex_once = __GTHREAD_ONCE_INIT;
+ void __gthread_atomic_add_mutex_once()
+ {
+ __GTHREAD_MUTEX_INIT_FUNCTION (&_Atomic_add_mutex);
+ }
+#endif
+} // namespace __gnu_cxx
http://movies.yahoo.com.au - Yahoo! Movies
- What's on at your local cinema?