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]

PATCH: Configure libstdc++-v3 against gthr.h


To this point, libstdc++-v3 has used its own thread configuration
files instead of picking up the mutex abstraction provided by
gcc/gthr.h.  It only supported POSIX or nothing.  This patch
configures libstdc++-v3 against gthr.h, thus --enable-threads should
now work for more non-POSIX platforms and it should work better and
more consistently for all POSIX platforms (in particular, weak symbol
support now works for those platforms that supported it for libgcc;
and it is now harder to accidentally build some accesses to an STL
container with mutex locking on and other accesses, in other parts of
your code base, with mutex locking off).

In a related issue, libstdc++-v3/libsupc++ was once setup to use
gthr.h properly (it actually uses the thread-specific memory and
initialization abstractions, in addition to the mutex abstractions),
but over time it broke (mainly due to being moved from libgcc?).  The
next patch, and final in this set of patches, addresses that issue by
using this work.

I have been away for a while since I last posted other parts of this
patch set (all of which have now been approved and applied).  We have
cleaned-up the implementation while retaining the technique proposed
about a week ago.  Also, I was still mulling over how to address
long-standing concerns related to support for --enable-threads verses
the STL.  It does not seem correct to allow users to provide options
and/or command-line macro defines at compiler run-time that may change
the internal configuration of the STL (unless the option is an
official multilib option for the port and the user understands what
they are doing and follows all the related rules).  My approach is to
unconditionally use the gthr.h configuration as cast at libstdc++-v3
configuration-time (a sophisticate user could still override the
configuration but now they will be defining macro symbols clearly in
our library implementor-space).

Before people complain about unconditional mutex-locking overhead in
the --enable-threads configuration, let me remind you that any
platform that supports weak symbols will only pay mutex locking
overhead when the threading routines are actually linked into the
final executable.  Platforms that don't support weak symbols have
other techniques to avoid the overhead (these are the same tradeoffs
already made while designing libgcc since we now use the same
portability layer).  In the ultimate case, configurations that
--disable-threads get the dummy gthr-single.h implementation, which
provides empty inline functions for the abstraction layer.

I propose to apply this patch to the mainline ASAP (although please
note that, unfortunately, it conflicts with the massive configuration
patch just posted by Benjamin).  If, after additional testing on a
wider selection of platforms, we see no problems, then this patch in
conjunction with the related follow-on patch should go onto the 3.0
branch since we have a regression from 2.95 otherwise.  The issue is
that C++ EH is broken in light of multi-threading; whereas it worked
for 2.95.  As a bonus with this approach, we address the ad hoc nature
of getting an STL container which plays with multi-thread code
properly (as defined by SGI).

Various versions of the patch (almost always tested in conjunction
with the next and final patch, which requires this one to really fix
multithreading C++ EH) have been bootstrapped on (--enable-threads
in all cases plus --disable-threads on selected platforms):

i386-unknown-freebsd4.2 (many earlier versions on mainline)
i386-unknown-freebsd4.2 (this version on 3.0 branch)
alpha-unknown-freebsd4.2 (this version on 3.0 branch)
i386-*-linux* (very close to this version on 3.0 branch)
hppa-*-hpux10* (very close to this version on 3.0 branch)
hppa-*-hpux11* (very close to this version on 3.0 branch)
sparc-sun-solaris2.7 (this version on 3.0 branch however
 I don't usually build this target and every C++ test fails with:
 ld.so.1: [...]: fatal: relocation error: R_SPARC_32: file [...]/libstdc++.so.3:
 symbol __gxx_personality_v0:  offset 0xff31cbe2 is non-aligned ---
 This could be because I have an old/bad binutils; I used
 --with-gnu-as and --with-gnu-ld or whatever.  I have checked at the
 source level that things are being setup properly for threads on this
 port and I think the failure is independent of this patch but I have
 not verified that yet.)

Once it is on mainline without breaking other ports (I expect some
follow-on patches will be required to support some hosts but most
effort will be spent fixing those hosts where --enable-threads already
worked with libstdc++-v3), it shall be moved to the 3.0 branch.

(Regenerated configure file was not included due to its massive diff size.)

(A little, seemingly bogus, change creeped into the setting of
 DIST_COMMON in libstdc++-v3/Makefile.in.  It will not be committed.)

2001-06-07  Loren J. Rittle  <ljrittle@acm.org>
	    John David Anglin  <dave@hiauly1.hia.nrc.ca>

	* config/threads-no.h: Remove file.
	* config/threads-posix.h: Remove file.

	* acconfig.h (_GLIBCPP_USE_THREADS): Remove.
	(_GLIBCPP_SUPPORTS_WEAK): Add (required by namespace-clean gthr*.h).
	(_GLIBCPP_HAVE_GTHR_DEFAULT): Likewise.
	* config.h.in: Regenerate.

	* acinclude.m4 (GLIBCPP_ENABLE_THREADS): Completely rework to
	setup and use gthr*.h files.  In particular, make gthr.h files
	namespace-clean in the staging area (they don't have to be for
	libgcc.a).
	* aclocal.m4: Regenerate.
	* configure: Regenerate.

	* src/Makefile.am (build_headers): Remove bits/c++threads.h
	and add bits/gthr.h bits/gthr-single.h bits/gthr-default.h.
	* src/Makefile.in: Regenerate.

	* include/bits/c++config: Cleanup threading configuration macros.
	In particular, define __STL_GTHREADS macro which controls...
	* include/bits/stl_threads.h: ...a brand new gthr.h-based
        configuration here.

	* config/c_io_stdio.h: Include staged gthr.h instead of local
	thread configuration file.  Always use __gthread_mutex_t
	instead of __mutext_type (or int).
	* include/bits/std_fstream.h: Likewise.

	* docs/html/17_intro/howto.html: Remove placeholder comment in
	case this configuration patch didn't make it.  Add advice that
	section only applies if configured with --enable-threads.
	* docs/html/23_containers/howto.html: Reword to make clear
	that _PTHREADS is no longer required for any port to be
	correctly using STL with threads.  Add advice that section
	only applies if configured with --enable-threads.

Index: acconfig.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/acconfig.h,v
retrieving revision 1.15.4.2
diff -c -r1.15.4.2 acconfig.h
*** acconfig.h	2001/05/31 12:40:38	1.15.4.2
--- acconfig.h	2001/06/07 10:06:47
***************
*** 1,7 ****
  // acconfig.h symbols and macros for libstdc++ v3 -*- C++ -*-
  
! // Include support for multiple threads, e.g., in the I/O package.
! #undef _GLIBCPP_USE_THREADS
  
  // Include support for 'long long' and 'unsigned long long'.
  #undef _GLIBCPP_USE_LONG_LONG
--- 1,10 ----
  // acconfig.h symbols and macros for libstdc++ v3 -*- C++ -*-
  
! // Define if GCC supports weak symbols
! #undef _GLIBCPP_SUPPORTS_WEAK
! 
! // Define if gthr-default.h exists (meaning that threading support is enabled)
! #undef HAVE_GTHR_DEFAULT
  
  // Include support for 'long long' and 'unsigned long long'.
  #undef _GLIBCPP_USE_LONG_LONG
Index: config.h.in
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config.h.in,v
retrieving revision 1.26.2.3
diff -c -r1.26.2.3 config.h.in
*** config.h.in	2001/05/31 12:40:39	1.26.2.3
--- config.h.in	2001/06/07 10:06:47
***************
*** 3,10 ****
  /* Define if you have a working `mmap' system call.  */
  #undef HAVE_MMAP
  
! // Include support for multiple threads, e.g., in the I/O package.
! #undef _GLIBCPP_USE_THREADS
  
  // Include support for 'long long' and 'unsigned long long'.
  #undef _GLIBCPP_USE_LONG_LONG
--- 3,13 ----
  /* Define if you have a working `mmap' system call.  */
  #undef HAVE_MMAP
  
! // Define if GCC supports weak symbols
! #undef _GLIBCPP_SUPPORTS_WEAK
! 
! // Define if gthr-default.h exists (meaning that threading support is enabled)
! #undef HAVE_GTHR_DEFAULT
  
  // Include support for 'long long' and 'unsigned long long'.
  #undef _GLIBCPP_USE_LONG_LONG
Index: acinclude.m4
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/acinclude.m4,v
retrieving revision 1.129.2.12
diff -c -r1.129.2.12 acinclude.m4
*** acinclude.m4	2001/05/31 12:40:39	1.129.2.12
--- acinclude.m4	2001/06/07 10:06:47
***************
*** 1118,1158 ****
  
  
  dnl
! dnl Check for which threading library to use.
  dnl
- dnl GLIBCPP_ENABLE_THREADS
- dnl --enable-threads=posix sets config/threads-posix.h et. al.
- dnl 
- dnl Default is no threads, which also disables _IO_MTSAFE_IO in
- dnl libio.  Any actual thread package will enable it.
- dnl
  AC_DEFUN(GLIBCPP_ENABLE_THREADS, [
    AC_MSG_CHECKING([for thread model used by GCC])
    target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
    AC_MSG_RESULT([$target_thread_file])
- 
-   dnl Check for thread package actually supported in libstdc++ 
-   THREADH=
-   case "$target_thread_file" in
-     no | none | single)
-       THREADH=threads-no.h
-       ;;
-     posix | pthreads)
-       THREADH=threads-posix.h
-       ;;
-     decosf1 | irix | mach | os2 | solaris | win32 | dce | vxworks)
-       AC_MSG_WARN(disabling unsupported thread package $target_thread_file)
-       THREADH=threads-no.h
-       ;;
-     *)
-       AC_MSG_ERROR($target_thread_file: unsupported/unknown thread package)
-       ;;
-   esac
  
!   AC_LINK_FILES(config/$THREADH, include/bits/c++threads.h)
!   if test $THREADH != threads-no.h; then
!     AC_DEFINE(_GLIBCPP_USE_THREADS)
    fi
  ])
  
  
--- 1118,1154 ----
  
  
  dnl
! dnl Setup to use the gcc gthr.h thread-specific memory and mutex model.
! dnl We must stage the required headers so that they will be installed
! dnl with the library (unlike libgcc, the STL implementation is provided
! dnl solely within headers).  Since we must not inject random user-space
! dnl macro names into user-provided C++ code, we first stage into <file>-in
! dnl and process to <file> with an output command.  The reason for a two-
! dnl stage process here is to correctly handle $srcdir!=$objdir without
! dnl having to write complex code (the sed commands to clean the macro
! dnl namespace are complex and fragile enough as it is).
  dnl
  AC_DEFUN(GLIBCPP_ENABLE_THREADS, [
    AC_MSG_CHECKING([for thread model used by GCC])
    target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
    AC_MSG_RESULT([$target_thread_file])
  
!   AC_LINK_FILES(../gcc/gthr.h, include/bits/gthr.h-in)
!   AC_LINK_FILES(../gcc/gthr-single.h, include/bits/gthr-single.h-in)
!   AC_LINK_FILES(../gcc/gthr-$target_thread_file.h,
! 		include/bits/gthr-default.h-in)
!   if test $target_thread_file != single; then
!     AC_DEFINE(HAVE_GTHR_DEFAULT)
!     AC_DEFINE(_GLIBCPP_SUPPORTS_WEAK, __GXX_WEAK__)
    fi
+   AC_OUTPUT_COMMANDS([d=include/bits
+     rm -f $d/gthr.h $d/gthr-single.h $d/gthr-default.h
+     sed '/^#/s/\([A-Z_][A-Z_]*\)/_GLIBCPP_\1/g' <$d/gthr.h-in >$d/gthr.h
+     sed 's/\(UNUSED\)/_GLIBCPP_\1/g' <$d/gthr-single.h-in \
+       | sed 's/\(GCC[A-Z_]*_H\)/_GLIBCPP_\1/g' >$d/gthr-single.h
+     sed 's/\(UNUSED\)/_GLIBCPP_\1/g' <$d/gthr-default.h-in \
+       | sed 's/\(GCC[A-Z_]*_H\)/_GLIBCPP_\1/g' \
+       | sed 's/\([A-Z_]*WEAK\)/_GLIBCPP_\1/g' >$d/gthr-default.h])
  ])
  
  
Index: aclocal.m4
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/aclocal.m4,v
retrieving revision 1.132.2.12
diff -c -r1.132.2.12 aclocal.m4
*** aclocal.m4	2001/05/31 12:40:39	1.132.2.12
--- aclocal.m4	2001/06/07 10:06:47
***************
*** 1130,1170 ****
  
  
  dnl
! dnl Check for which threading library to use.
  dnl
- dnl GLIBCPP_ENABLE_THREADS
- dnl --enable-threads=posix sets config/threads-posix.h et. al.
- dnl 
- dnl Default is no threads, which also disables _IO_MTSAFE_IO in
- dnl libio.  Any actual thread package will enable it.
- dnl
  AC_DEFUN(GLIBCPP_ENABLE_THREADS, [
    AC_MSG_CHECKING([for thread model used by GCC])
    target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
    AC_MSG_RESULT([$target_thread_file])
- 
-   dnl Check for thread package actually supported in libstdc++ 
-   THREADH=
-   case "$target_thread_file" in
-     no | none | single)
-       THREADH=threads-no.h
-       ;;
-     posix | pthreads)
-       THREADH=threads-posix.h
-       ;;
-     decosf1 | irix | mach | os2 | solaris | win32 | dce | vxworks)
-       AC_MSG_WARN(disabling unsupported thread package $target_thread_file)
-       THREADH=threads-no.h
-       ;;
-     *)
-       AC_MSG_ERROR($target_thread_file: unsupported/unknown thread package)
-       ;;
-   esac
  
!   AC_LINK_FILES(config/$THREADH, include/bits/c++threads.h)
!   if test $THREADH != threads-no.h; then
!     AC_DEFINE(_GLIBCPP_USE_THREADS)
    fi
  ])
  
  
--- 1130,1166 ----
  
  
  dnl
! dnl Setup to use the gcc gthr.h thread-specific memory and mutex model.
! dnl We must stage the required headers so that they will be installed
! dnl with the library (unlike libgcc, the STL implementation is provided
! dnl solely within headers).  Since we must not inject random user-space
! dnl macro names into user-provided C++ code, we first stage into <file>-in
! dnl and process to <file> with an output command.  The reason for a two-
! dnl stage process here is to correctly handle $srcdir!=$objdir without
! dnl having to write complex code (the sed commands to clean the macro
! dnl namespace are complex and fragile enough as it is).
  dnl
  AC_DEFUN(GLIBCPP_ENABLE_THREADS, [
    AC_MSG_CHECKING([for thread model used by GCC])
    target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
    AC_MSG_RESULT([$target_thread_file])
  
!   AC_LINK_FILES(../gcc/gthr.h, include/bits/gthr.h-in)
!   AC_LINK_FILES(../gcc/gthr-single.h, include/bits/gthr-single.h-in)
!   AC_LINK_FILES(../gcc/gthr-$target_thread_file.h,
! 		include/bits/gthr-default.h-in)
!   if test $target_thread_file != single; then
!     AC_DEFINE(HAVE_GTHR_DEFAULT)
!     AC_DEFINE(_GLIBCPP_SUPPORTS_WEAK, __GXX_WEAK__)
    fi
+   AC_OUTPUT_COMMANDS([d=include/bits
+     rm -f $d/gthr.h $d/gthr-single.h $d/gthr-default.h
+     sed '/^#/s/\([A-Z_][A-Z_]*\)/_GLIBCPP_\1/g' <$d/gthr.h-in >$d/gthr.h
+     sed 's/\(UNUSED\)/_GLIBCPP_\1/g' <$d/gthr-single.h-in \
+       | sed 's/\(GCC[A-Z_]*_H\)/_GLIBCPP_\1/g' >$d/gthr-single.h
+     sed 's/\(UNUSED\)/_GLIBCPP_\1/g' <$d/gthr-default.h-in \
+       | sed 's/\(GCC[A-Z_]*_H\)/_GLIBCPP_\1/g' \
+       | sed 's/\([A-Z_]*WEAK\)/_GLIBCPP_\1/g' >$d/gthr-default.h])
  ])
  
  
Index: src/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/Makefile.am,v
retrieving revision 1.71.2.7
diff -c -r1.71.2.7 Makefile.am
*** Makefile.am	2001/05/30 07:14:43	1.71.2.7
--- Makefile.am	2001/06/07 10:06:47
***************
*** 158,164 ****
  
  build_headers = \
  	bits/std_limits.h \
! 	bits/c++config.h bits/c++io.h bits/c++locale.h bits/c++threads.h \
  	bits/basic_file_model.h \
  	bits/atomicity.h bits/os_defines.h \
  	bits/ctype_base.h bits/ctype_noninline.h bits/ctype_inline.h 
--- 158,165 ----
  
  build_headers = \
  	bits/std_limits.h \
! 	bits/c++config.h bits/c++io.h bits/c++locale.h \
! 	bits/gthr.h bits/gthr-single.h bits/gthr-default.h \
  	bits/basic_file_model.h \
  	bits/atomicity.h bits/os_defines.h \
  	bits/ctype_base.h bits/ctype_noninline.h bits/ctype_inline.h 
Index: src/Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/Makefile.in,v
retrieving revision 1.95.2.9
diff -c -r1.95.2.9 Makefile.in
*** Makefile.in	2001/05/31 12:41:47	1.95.2.9
--- Makefile.in	2001/06/07 10:06:47
***************
*** 164,170 ****
  @GLIBCPP_NEED_LIBIO_TRUE@libio_headers = 	$(top_srcdir)/libio/_G_config.h $(top_srcdir)/libio/libio.h
  @GLIBCPP_NEED_LIBIO_FALSE@libio_headers = 
  
! build_headers =  	bits/std_limits.h 	bits/c++config.h bits/c++io.h bits/c++locale.h bits/c++threads.h 	bits/basic_file_model.h 	bits/atomicity.h bits/os_defines.h 	bits/ctype_base.h bits/ctype_noninline.h bits/ctype_inline.h 
  
  
  sources =  	limitsMEMBERS.cc 	stdexcept.cc functexcept.cc bitset.cc 	globals.cc 	basic_file.cc ios.cc complex_io.cc strstream.cc 	c++locale.cc locale.cc localename.cc codecvt.cc 	locale-inst.cc stl-inst.cc misc-inst.cc valarray-inst.cc 	string-inst.cc wstring-inst.cc 
--- 164,170 ----
  @GLIBCPP_NEED_LIBIO_TRUE@libio_headers = 	$(top_srcdir)/libio/_G_config.h $(top_srcdir)/libio/libio.h
  @GLIBCPP_NEED_LIBIO_FALSE@libio_headers = 
  
! build_headers =  	bits/std_limits.h 	bits/c++config.h bits/c++io.h bits/c++locale.h 	bits/gthr.h bits/gthr-single.h bits/gthr-default.h 	bits/basic_file_model.h 	bits/atomicity.h bits/os_defines.h 	bits/ctype_base.h bits/ctype_noninline.h bits/ctype_inline.h 
  
  
  sources =  	limitsMEMBERS.cc 	stdexcept.cc functexcept.cc bitset.cc 	globals.cc 	basic_file.cc ios.cc complex_io.cc strstream.cc 	c++locale.cc locale.cc localename.cc codecvt.cc 	locale-inst.cc stl-inst.cc misc-inst.cc valarray-inst.cc 	string-inst.cc wstring-inst.cc 
Index: include/bits/c++config
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/c++config,v
retrieving revision 1.8.6.6
diff -c -r1.8.6.6 c++config
*** c++config	2001/05/31 02:48:49	1.8.6.6
--- c++config	2001/06/07 10:06:47
***************
*** 62,87 ****
  // Enable concept checking code from the boost libraries.
  //#define _GLIBCPP_CONCEPT_CHECKS 1
  
! // From SGI's stl_config.h; generic settings and user hooks (_NOTHREADS).
! #ifdef _REENTRANT
! # define __STL_THREADS
! #endif
! 
! #if defined(_PTHREADS) && !defined(_NOTHREADS)
! # define __STL_PTHREADS
! #endif
! 
! #if defined(_UITHREADS) && !defined(_PTHREADS) && !defined(_NOTHREADS)
! # define __STL_UITHREADS
! #endif
! 
! #if defined(__STL_WIN32THREADS) || defined(__STL_SGI_THREADS) \
!     || defined(__STL_PTHREADS)  || defined(__STL_UITHREADS)
! # define __STL_THREADS
! # define __STL_VOLATILE volatile
! #else
! # define __STL_VOLATILE
! #endif
  
  // This is also a user hook, but via -f[no-]exceptions, not direct #defines.
  #ifdef __EXCEPTIONS
--- 62,78 ----
  // Enable concept checking code from the boost libraries.
  //#define _GLIBCPP_CONCEPT_CHECKS 1
  
! // Map gthr.h abstraction to that required for STL.  Do not key off of
! // __GTHREADS at this point since we haven't seen the correct symbol
! // yet, instead setup so that include/bits/stl_threads.h will know to
! // include gthr.h instead of any other type of thread support.  Note:
! // that gthr.h may well map to gthr-single.h which is a correct way to
! // express no threads support in gcc.  As a user, do not define
! // _NOTHREADS without consideration of the consequences (e.g. it is an
! // internal ABI change).
! #define __STL_GTHREADS
! #define __STL_THREADS
! #define __STL_VOLATILE volatile
  
  // This is also a user hook, but via -f[no-]exceptions, not direct #defines.
  #ifdef __EXCEPTIONS
Index: include/bits/stl_threads.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_threads.h,v
retrieving revision 1.2.2.1
diff -c -r1.2.2.1 stl_threads.h
*** stl_threads.h	2001/05/14 19:49:05	1.2.2.1
--- stl_threads.h	2001/06/07 10:06:47
***************
*** 24,29 ****
--- 24,38 ----
  // threads standard), and Win32 threads.  Uithread support by Jochen
  // Schlick, 1999.
  
+ // GCC extension begin
+ // In order to present a stable threading configuration, in all cases,
+ // gcc looks for it's own abstraction layer before all others.  All
+ // modifications to this file are marked to allow easier importation of
+ // STL upgrades.
+ #if defined(__STL_GTHREADS)
+ #include "bits/gthr.h"
+ #else
+ // GCC extension end
  #if defined(__STL_SGI_THREADS)
  #include <mutex.h>
  #include <time.h>
***************
*** 35,40 ****
--- 44,52 ----
  #elif defined(__STL_WIN32THREADS)
  #include <windows.h>
  #endif
+ // GCC extension begin
+ #endif
+ // GCC extension end
  
  namespace std
  {
***************
*** 64,69 ****
--- 76,98 ----
     volatile _RC_t _M_ref_count;
  
    // Constructor
+ // GCC extension begin
+ #ifdef __STL_GTHREADS
+   __gthread_mutex_t _M_ref_count_lock;
+   _Refcount_Base(_RC_t __n) : _M_ref_count(__n)
+     {
+ #ifdef __GTHREAD_MUTEX_INIT
+       __gthread_mutex_t __tmp = __GTHREAD_MUTEX_INIT;
+       _M_ref_count_lock = __tmp;
+ #elif defined(__GTHREAD_MUTEX_INIT_FUNCTION)
+       __GTHREAD_MUTEX_INIT_FUNCTION (&_M_ref_count_lock);
+ #else
+ #error __GTHREAD_MUTEX_INIT or __GTHREAD_MUTEX_INIT_FUNCTION should be defined
+ #error by gthr.h abstraction layer, report problem to libstdc++@gcc.gnu.org.
+ #endif
+     }
+ #else
+ // GCC extension end
  # ifdef __STL_PTHREADS
    pthread_mutex_t _M_ref_count_lock;
    _Refcount_Base(_RC_t __n) : _M_ref_count(__n)
***************
*** 75,81 ****
--- 104,128 ----
  # else
    _Refcount_Base(_RC_t __n) : _M_ref_count(__n) {}
  # endif
+ // GCC extension begin
+ #endif
+ // GCC extension end
  
+ // GCC extension begin
+ #ifdef __STL_GTHREADS
+   void _M_incr() {
+     __gthread_mutex_lock(&_M_ref_count_lock);
+     ++_M_ref_count;
+     __gthread_mutex_unlock(&_M_ref_count_lock);
+   }
+   _RC_t _M_decr() {
+     __gthread_mutex_lock(&_M_ref_count_lock);
+     volatile _RC_t __tmp = --_M_ref_count;
+     __gthread_mutex_unlock(&_M_ref_count_lock);
+     return __tmp;
+   }
+ #else
+ // GCC extension end
    // _M_incr and _M_decr
  # ifdef __STL_SGI_THREADS
    void _M_incr() {  __add_and_fetch(&_M_ref_count, 1); }
***************
*** 111,122 ****
--- 158,181 ----
    void _M_incr() { ++_M_ref_count; }
    _RC_t _M_decr() { return --_M_ref_count; }
  # endif
+ // GCC extension begin
+ #endif
+ // GCC extension end
  };
  
  // Atomic swap on unsigned long
  // 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.
+ // GCC extension begin
+ #ifdef __STL_GTHREADS
+ // We don't provide an _Atomic_swap in this configuration.  This only
+ // affects the use of ext/rope with threads.  Someone could add this
+ // later, if required.  You can start by cloning the __STL_PTHREADS
+ // path while making the obvious changes.  Later it could be optimized
+ // to use the atomicity.h abstraction layer from libstdc++-v3.
+ #else
+ // GCC extension end
  # ifdef __STL_SGI_THREADS
      inline unsigned long _Atomic_swap(unsigned long * __p, unsigned long __q) {
  #       if __mips < 3 || !(defined (_ABIN32) || defined(_ABI64))
***************
*** 205,210 ****
--- 264,272 ----
          return __result;
      }
  # endif
+ // GCC extension begin
+ #endif
+ // GCC extension end
  
  // Locking class.  Note that this class *does not have a constructor*.
  // It must be initialized either statically, with __STL_MUTEX_INITIALIZER,
***************
*** 237,242 ****
--- 299,319 ----
  
  struct _STL_mutex_lock
  {
+ // GCC extension begin
+ #if defined(__STL_GTHREADS)
+   __gthread_mutex_t _M_lock;
+   void _M_initialize()
+   {
+ #ifdef __GTHREAD_MUTEX_INIT
+   // There should be no code in this path given the usage rules above.
+ #elif defined(__GTHREAD_MUTEX_INIT_FUNCTION)
+     __GTHREAD_MUTEX_INIT_FUNCTION (&_M_lock);
+ #endif
+   }
+   void _M_acquire_lock() { __gthread_mutex_lock(&_M_lock); }
+   void _M_release_lock() { __gthread_mutex_unlock(&_M_lock); }
+ #else
+ // GCC extension end
  #if defined(__STL_SGI_THREADS) || defined(__STL_WIN32THREADS)
    // It should be relatively easy to get this to work on any modern Unix.
    volatile unsigned long _M_lock;
***************
*** 330,337 ****
--- 407,428 ----
    void _M_acquire_lock() {}
    void _M_release_lock() {}
  #endif
+ // GCC extension begin
+ #endif
+ // GCC extension end
  };
  
+ // GCC extension begin
+ #if defined(__STL_GTHREADS)
+ #ifdef __GTHREAD_MUTEX_INIT
+ #define __STL_MUTEX_INITIALIZER = { __GTHREAD_MUTEX_INIT }
+ #else
+ #define __STL_MUTEX_INITIALIZER
+ #warning You must arrange to call _M_initialize on all _STL_mutex_lock
+ #warning objects in the linked system before any STL containers are created.
+ #endif
+ #else
+ // GCC extension end
  #ifdef __STL_PTHREADS
  // Pthreads locks must be statically initialized to something other than
  // the default value of zero.
***************
*** 345,350 ****
--- 436,444 ----
  #else
  #   define __STL_MUTEX_INITIALIZER
  #endif
+ // GCC extension begin
+ #endif
+ // GCC extension end
  
  
  // A locking class that uses _STL_mutex_lock.  The constructor takes a
Index: include/bits/std_fstream.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/std_fstream.h,v
retrieving revision 1.1.6.5
diff -c -r1.1.6.5 std_fstream.h
*** std_fstream.h	2001/05/24 23:20:33	1.1.6.5
--- std_fstream.h	2001/06/07 10:06:47
***************
*** 40,46 ****
  #include <bits/std_ostream.h>
  #include <bits/basic_file.h>
  #include <bits/std_locale.h>	// For codecvt
! #include <bits/c++threads.h>	// For __mutext_type
  
  namespace std 
  {
--- 40,46 ----
  #include <bits/std_ostream.h>
  #include <bits/basic_file.h>
  #include <bits/std_locale.h>	// For codecvt
! #include <bits/gthr.h>
  
  namespace std 
  {
Index: config/c_io_stdio.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/c_io_stdio.h,v
retrieving revision 1.6.4.2
diff -c -r1.6.4.2 c_io_stdio.h
*** c_io_stdio.h	2001/05/14 19:48:54	1.6.4.2
--- c_io_stdio.h	2001/06/07 10:06:47
***************
*** 34,40 ****
  
  #include <stdio.h>
  #include <stddef.h>
! #include <bits/c++threads.h>
  
  namespace std 
  {
--- 34,40 ----
  
  #include <stdio.h>
  #include <stddef.h>
! #include <bits/gthr.h>
  
  namespace std 
  {
***************
*** 46,57 ****
  #endif
    typedef fpos_t  	__c_streampos;
  
! #ifdef _GLIBCPP_USE_THREADS
!   typedef __mutext_type __c_lock;
! #else
!   typedef int          	__c_lock;
! 
! #endif
  
  // from basic_file.h
  #define _GLIBCPP_BASIC_FILE_ENCAPSULATION 1
--- 46,52 ----
  #endif
    typedef fpos_t  	__c_streampos;
  
!   typedef __gthread_mutex_t __c_lock;
  
  // from basic_file.h
  #define _GLIBCPP_BASIC_FILE_ENCAPSULATION 1
Index: docs/html/17_intro/howto.html
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/docs/html/17_intro/howto.html,v
retrieving revision 1.1.4.3
diff -c -r1.1.4.3 howto.html
*** howto.html	2001/05/31 02:48:49	1.1.4.3
--- howto.html	2001/06/07 10:06:47
***************
*** 57,63 ****
        This entry will mention a very little bit about the general MT
        issues with libstdc++.  The latest status and quick notes will be
        in FAQ 5.6.  Some discussion about thread-safe containers will be
!       in section 6.8 (the HOWTOs on containers).
     </P>
     <P>The libstdc++ code (all of it, not just the containers) has been
        designed so that thread-safety will be easily possible.  The first
--- 57,64 ----
        This entry will mention a very little bit about the general MT
        issues with libstdc++.  The latest status and quick notes will be
        in FAQ 5.6.  Some discussion about thread-safe containers will be
!       in section 6.8 (the HOWTOs on containers).  This section only applies
!       when gcc and libstdc++-v3 were configured with --enable-threads.
     </P>
     <P>The libstdc++ code (all of it, not just the containers) has been
        designed so that thread-safety will be easily possible.  The first
***************
*** 79,97 ****
        in include/bits/c++config and the HOWTOs on containers.  Be
        fully aware that you may change the external or internal ABI of
        libstdc++-v3 when you provide -D__USE_MALLOC on the command line
!       or make a change to that configuration file. [Placeholder in
!       case other patches don't make it before the 3.0 release: That
!       memory allocator can appear buggy in multithreaded C++ programs
!       (and has been reported to leak memory), if STL is misconfigured
!       for your platform.  You may need to provide -D_PTHREADS on the
!       command line in this case to ensure the memory allocator for
!       containers is really protected by a mutex.  Also, be aware that
!       you just changed the ABI of libstdc++-v3 when you did that thus
!       your entire application and all libraries must be compiled with
!       compatible flags.  The STL implementation doesn't currently
!       protect you from changing the mutex locking implementation to
!       one that doesn't really play together with the implementation
!       you may have compiled other application code with.]
     </P>
     <P>
        If you don't like caches of objects being retained inside the
--- 80,86 ----
        in include/bits/c++config and the HOWTOs on containers.  Be
        fully aware that you may change the external or internal ABI of
        libstdc++-v3 when you provide -D__USE_MALLOC on the command line
!       or make a change to that configuration file.
     </P>
     <P>
        If you don't like caches of objects being retained inside the
Index: docs/html/23_containers/howto.html
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/docs/html/23_containers/howto.html,v
retrieving revision 1.1.4.3
diff -c -r1.1.4.3 howto.html
*** howto.html	2001/05/31 02:48:49	1.1.4.3
--- howto.html	2001/06/07 10:06:47
***************
*** 185,191 ****
     <P>This section will mention some of the problems in designing MT
        programs that use Standard containers.  For information on other
        aspects of multithreading (e.g., the library as a whole), see
!       the Received Wisdom on Chapter 17.
     </P>
     <P>Two excellent pages to read when working with templatized containers
        and threads are
--- 185,192 ----
     <P>This section will mention some of the problems in designing MT
        programs that use Standard containers.  For information on other
        aspects of multithreading (e.g., the library as a whole), see
!       the Received Wisdom on Chapter 17.  This section only applies
!       when gcc and libstdc++-v3 were configured with --enable-threads.
     </P>
     <P>Two excellent pages to read when working with templatized containers
        and threads are
***************
*** 207,213 ****
        the mutex lock as is best for your platform.  In particular,
        past advice was for people using g++ to explicitly define
        _PTHREADS on the command line to get a thread-safe STL.  This
!       may or may not be required for your port.  It may or may not be
        a good idea for your port.  Extremely big caution: if you
        compile some of your application code against the STL with one
        set of threading flags and macros and another portion of the
--- 208,214 ----
        the mutex lock as is best for your platform.  In particular,
        past advice was for people using g++ to explicitly define
        _PTHREADS on the command line to get a thread-safe STL.  This
!       is no longer required for your port.  It may or may not be
        a good idea for your port.  Extremely big caution: if you
        compile some of your application code against the STL with one
        set of threading flags and macros and another portion of the


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