This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: *ping* generic atomicity.h


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.


> Another query:
> cpu_include_dir defaults to the cpu part of the target triplet.
> But doesn't that correspond to the -mcpu or -mtune default rather than
> to the -march default. In the case of generic vs i486 atomicity.h, the
> selection should be based on the default instruction set -- which is
>  __i386__ -- not the default tuning?? 

*shrug*


> static function declaration, but missing definition when included by
> any file _except_ src/misc-inst.cc.   Should this function be inlined here
> rather than definition in src/misc-inst.cc.

I'd rather not end up with copies everywhere.  We'd need an out-of-line
definition anyhow.


> Should be  __GTHREAD_MUTEX_INIT_FUNCTION (&_Atomic_add_mutex), as per
> description in gthr.h and implementation in, eg., gthr-win32.h.

Good catch, thanks.


Index: config/cpu/generic/atomicity.h
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/libstdc++-v3/config/cpu/generic/atomicity.h,v
retrieving revision 1.4
diff -u -3 -r1.4 atomicity.h
--- config/cpu/generic/atomicity.h	8 Nov 2002 19:24:41 -0000	1.4
+++ config/cpu/generic/atomicity.h	20 Jan 2003 16:06: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,35 @@
 
 namespace __gnu_cxx
 {
-  __gthread_mutex_t _Atomic_add_mutex __attribute__ ((__weak__))
-                                                      = __GTHREAD_MUTEX_INIT;
+  extern __gthread_mutex_t _Atomic_add_mutex
+#ifdef __GTHREAD_MUTEX_INIT
+                                                      = __GTHREAD_MUTEX_INIT
+#endif
+                                                      ;
+
+#ifndef __GTHREAD_MUTEX_INIT
+  #define __GTHREAD_NEED_MUTEX_ONCE_FUNCTION
+  extern __gthread_once_t _Atomic_add_mutex_once
+                                                      = __GTHREAD_ONCE_INIT;
+  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;
+#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);
+  _Atomic_word __result;
 
-   __result = *__mem;
-   *__mem += __val;
+  __gthread_mutex_lock (&__gnu_cxx::_Atomic_add_mutex);
+
+  __result = *__mem;
+  *__mem += __val;
 
   __gthread_mutex_unlock (&__gnu_cxx::_Atomic_add_mutex);
   return __result;
Index: src/misc-inst.cc
===================================================================
RCS file: /home/pme/Repositories/GCC/gcc/libstdc++-v3/src/misc-inst.cc,v
retrieving revision 1.20
diff -u -3 -r1.20 misc-inst.cc
--- src/misc-inst.cc	5 Nov 2002 19:17:37 -0000	1.20
+++ src/misc-inst.cc	20 Jan 2003 16:06:27 -0000
@@ -87,3 +88,21 @@
      string*, __false_type);
 #endif
 } // namespace std
+
+namespace __gnu_cxx
+{
+  #ifdef __GTHREAD_NEED_MUTEX_ONCE_FUNCTION
+  // generic atomicity.h without static initialization
+  void __gthread_atomic_add_mutex_once()
+  {
+    __GTHREAD_MUTEX_INIT_FUNCTION (&_Atomic_add_mutex);
+  }
+  #endif
+} // namespace __gnu_cxx


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]