This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] std::_Atomic_swap for i386
- From: Danny Smith <danny_r_smith_2001 at yahoo dot co dot nz>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Sat, 3 May 2003 08:21:46 +1000 (EST)
- Subject: [Patch] std::_Atomic_swap for i386
Recent builds of libstdc++ on mingw (__GTHREAD_MUTEX_INIT not defined)
gives this.
In file included from
/develop/gcc-3.4/build/mingw32/libstdc++-v3/include/ext/stl_rope.h:2511,
from
/develop/gcc-3.4/build/mingw32/libstdc++-v3/include/ext/rope:60,
from ../../../../gcc/libstdc++-v3/src/ext-inst.cc:34:
/develop/gcc-3.4/build/mingw32/libstdc++-v3/include/ext/ropeimpl.h: In member
function `const _CharT* __gnu_cxx::rope<_CharT, _Alloc>::c_str() const':
/develop/gcc-3.4/build/mingw32/libstdc++-v3/include/ext/ropeimpl.h:1463: error:
`
_Atomic_swap' is not a member of `std'
make[2]: *** [ext-inst.lo] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all-recursive-am] Error 2
The following patch, based on the recent discussion of i386
__exchange_and_add, fixes.
2003-05-02 Danny Smith <dannysmith@users.sourceforge.net>
* config/cpu/i386/atomicity.h (_Atomic_swap): Define.
(_GLIPCPP_USE_CPU_ATOMIC_SWAP): Define.
* config/cpu/i486/atomicity.h (_Atomic_swap): Define.
(_GLIPCPP_USE_CPU_ATOMIC_SWAP): Define.
* include/bits/stl_threads.h (_Atomic_swap): Don't define
if _GLIPCPP_USE_CPU_ATOMIC_SWAP.
Index: config/cpu/i386/atomicity.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/cpu/i386/atomicity.h,v
retrieving revision 1.5
diff -c -3 -p -r1.5 atomicity.h
*** config/cpu/i386/atomicity.h 29 Apr 2003 21:57:39 -0000 1.5
--- config/cpu/i386/atomicity.h 2 May 2003 22:19:38 -0000
*************** __atomic_add (volatile _Atomic_word* __m
*** 72,75 ****
--- 72,91 ----
__exchange_and_add (__mem, __val);
}
+ #define _GLIPCPP_USE_CPU_ATOMIC_SWAP 1
+ namespace std
+ {
+ inline
+ unsigned long _Atomic_swap (volatile unsigned long * __p,
+ unsigned long __q)
+ {
+ unsigned long res;
+ __asm__ __volatile__ ("xchgl %0, %1"
+ : "=r" (res)
+ : "m" (*__p), "0" (__q)
+ : "memory");
+ return res;
+ }
+ } // namespace std
+
#endif /* atomicity.h */
Index: config/cpu/i486/atomicity.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/cpu/i486/atomicity.h,v
retrieving revision 1.2
diff -c -3 -p -r1.2 atomicity.h
*** config/cpu/i486/atomicity.h 2 Jan 2003 22:48:20 -0000 1.2
--- config/cpu/i486/atomicity.h 2 May 2003 22:19:38 -0000
*************** __atomic_add (volatile _Atomic_word* __m
*** 52,57 ****
--- 52,74 ----
: "+m" (*__mem) : "ir" (__val) : "memory");
}
+ #define _GLIPCPP_USE_CPU_ATOMIC_SWAP 1
+ namespace std
+ {
+ inline
+ unsigned long _Atomic_swap (volatile unsigned long * __p,
+ unsigned long __q)
+ {
+ unsigned long res;
+ __asm__ __volatile__ ("xchgl %0, %1"
+ : "=r" (res)
+ : "m" (*__p), "0" (__q)
+ : "memory");
+ return res;
+ }
+ } // namespace std
+
+
#endif /* atomicity.h */
Index: include/bits/stl_threads.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_threads.h,v
retrieving revision 1.14
diff -c -3 -p -r1.14 stl_threads.h
*** include/bits/stl_threads.h 13 Oct 2002 06:35:15 -0000 1.14
--- include/bits/stl_threads.h 2 May 2003 22:19:38 -0000
*************** namespace std
*** 102,108 ****
// This is guaranteed to behave as though it were atomic only if all
// possibly concurrent updates use _Atomic_swap.
// In some cases the operation is emulated with a lock.
! #if defined (__GTHREAD_MUTEX_INIT)
// This could be optimized to use the atomicity.h abstraction layer.
// vyzo: simple _Atomic_swap implementation following the guidelines above
// We use a template here only to get a unique initialized instance.
--- 102,108 ----
// This is guaranteed to behave as though it were atomic only if all
// possibly concurrent updates use _Atomic_swap.
// In some cases the operation is emulated with a lock.
! #if !defined (_GLIPCPP_USE_CPU_ATOMIC_SWAP) && defined (__GTHREAD_MUTEX_INIT)
// This could be optimized to use the atomicity.h abstraction layer.
// vyzo: simple _Atomic_swap implementation following the guidelines above
// We use a template here only to get a unique initialized instance.
http://mobile.yahoo.com.au - Yahoo! Mobile
- Check & compose your email via SMS on your Telstra or Vodafone mobile.