PATCH: libstdc++/5432
Loren James Rittle
rittle@latour.rsch.comm.mot.com
Thu Jan 24 13:25:00 GMT 2002
Patch from libstdc++/5432 as committed (minor tweaks, see PR history).
Tested on both i386-unknown-freebsd4.4 and MP sparc-sun-solaris2.7
with no regressions. Fixes thread/pthread3.cc on later platform. As
Andrew, although I did review the patch closely to ensure it didn't
worsen anything related to MP, other MP issues might remain here.
Thanks to Craig and Nathan for reviewing the PR submission
and Andrew for the initial source patch.
2002-01-24 andrew@andypo.net
(tweaks, test and commit by Loren J. Rittle <ljrittle@acm.org>)
libstdc++/5432
* include/bits/ios_base.h: Use _Atomic_word for reference counts.
* include/bits/localefwd.h: Likewise.
Also use for std::locale::id::_S_highwater.
* src/ios.cc (ios_base::xalloc): Use _Atomic_word.
* src/locale.cc: Support new usage of _Atomic_word.
(std::locale::classic): Guard entire function against reentry.
* src/localename.cc: Support new usage of _Atomic_word.
Index: include/bits/ios_base.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/ios_base.h,v
retrieving revision 1.14
diff -c -r1.14 ios_base.h
*** ios_base.h 2001/11/02 17:38:10 1.14
--- ios_base.h 2002/01/24 20:27:15
***************
*** 1,6 ****
// Iostreams base classes -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001 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
--- 1,7 ----
// Iostreams base classes -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
! // 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
***************
*** 41,46 ****
--- 42,49 ----
#pragma GCC system_header
+ #include <bits/atomicity.h>
+
namespace std
{
// The following definitions of bitmask types are enums, not ints,
***************
*** 244,260 ****
_Callback_list* _M_next;
ios_base::event_callback _M_fn;
int _M_index;
! int _M_refcount; // 0 means one reference.
_Callback_list(ios_base::event_callback __fn, int __index,
_Callback_list* __cb)
: _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { }
void
! _M_add_reference() { ++_M_refcount; } // XXX MT
!
int
! _M_remove_reference() { return _M_refcount--; } // 0 => OK to delete
};
_Callback_list* _M_callbacks;
--- 247,264 ----
_Callback_list* _M_next;
ios_base::event_callback _M_fn;
int _M_index;
! _Atomic_word _M_refcount; // 0 means one reference.
_Callback_list(ios_base::event_callback __fn, int __index,
_Callback_list* __cb)
: _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { }
void
! _M_add_reference() { __atomic_add(&_M_refcount, 1); }
!
int
! _M_remove_reference() { return __exchange_and_add(&_M_refcount, -1); }
! // 0 => OK to delete
};
_Callback_list* _M_callbacks;
Index: include/bits/localefwd.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/localefwd.h,v
retrieving revision 1.24
diff -c -r1.24 localefwd.h
*** localefwd.h 2002/01/22 23:08:58 1.24
--- localefwd.h 2002/01/24 20:27:15
***************
*** 49,54 ****
--- 49,56 ----
#include <string> // For string
#include <bits/functexcept.h>
+ #include <bits/atomicity.h>
+
namespace std
{
// NB: Don't instantiate required wchar_t facets if no wchar_t support.
***************
*** 317,323 ****
private:
// Data Members.
! size_t _M_references;
__vec_facet* _M_facets;
string _M_names[_S_num_categories];
static const locale::id* const _S_id_ctype[];
--- 319,325 ----
private:
// Data Members.
! _Atomic_word _M_references;
__vec_facet* _M_facets;
string _M_names[_S_num_categories];
static const locale::id* const _S_id_ctype[];
***************
*** 330,341 ****
inline void
_M_add_reference() throw()
! { ++_M_references; } // XXX MT
inline void
_M_remove_reference() throw()
{
! if (--_M_references == 0) // XXX MT
{
try
{ delete this; }
--- 332,343 ----
inline void
_M_add_reference() throw()
! { __atomic_add(&_M_references, 1); }
inline void
_M_remove_reference() throw()
{
! if (__exchange_and_add(&_M_references, -1) == 1)
{
try
{ delete this; }
***************
*** 392,398 ****
friend class __enc_traits;
private:
! size_t _M_references;
protected:
// Contains data from the underlying "C" library for default "C"
--- 394,400 ----
friend class __enc_traits;
private:
! _Atomic_word _M_references;
protected:
// Contains data from the underlying "C" library for default "C"
***************
*** 447,453 ****
mutable size_t _M_index;
// Last id number assigned
! static size_t _S_highwater;
void
operator=(const id&); // not defined
--- 449,455 ----
mutable size_t _M_index;
// Last id number assigned
! static _Atomic_word _S_highwater;
void
operator=(const id&); // not defined
Index: src/ios.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/ios.cc,v
retrieving revision 1.23
diff -c -r1.23 ios.cc
*** ios.cc 2002/01/04 21:27:35 1.23
--- ios.cc 2002/01/24 20:27:15
***************
*** 1,6 ****
// Iostreams base classes -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001 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
--- 1,7 ----
// Iostreams base classes -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
! // 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,41 ****
--- 37,44 ----
#include <istream>
#include <fstream>
+ #include <bits/atomicity.h>
+
namespace std
{
// Extern declarations for global objects in src/globals.cc.
***************
*** 224,233 ****
int
ios_base::xalloc() throw()
{
- // XXX MT
// XXX should be a symbol. (Reserve 0..3 for builtins.)
! static int top = 4;
! return top++;
}
// 27.4.2.5 iword/pword storage
--- 227,237 ----
int
ios_base::xalloc() throw()
{
// XXX should be a symbol. (Reserve 0..3 for builtins.)
! static _Atomic_word top = 0;
! return __exchange_and_add(&top, 1) + 4;
! // Implementation note: Initialize top to zero to ensure that
! // initialization occurs before main() is started.
}
// 27.4.2.5 iword/pword storage
Index: src/locale.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/locale.cc,v
retrieving revision 1.51
diff -c -r1.51 locale.cc
*** locale.cc 2002/01/04 21:27:35 1.51
--- locale.cc 2002/01/24 20:27:16
***************
*** 41,46 ****
--- 41,48 ----
# include <cwctype> // for towupper, etc.
#endif
+ #include <bits/atomicity.h>
+
namespace std
{
// Defined in globals.cc.
***************
*** 72,78 ****
#endif
// Definitions for static const data members of locale::id
! size_t locale::id::_S_highwater; // init'd to 0 by linker
// Definitions for static const data members of locale::_Impl
const locale::id* const
--- 74,80 ----
#endif
// Definitions for static const data members of locale::id
! _Atomic_word locale::id::_S_highwater; // init'd to 0 by linker
// Definitions for static const data members of locale::_Impl
const locale::id* const
***************
*** 187,193 ****
{
_S_initialize();
(_M_impl = _S_global)->_M_add_reference();
! } // XXX MT
locale::locale(const locale& __other) throw()
{ (_M_impl = __other._M_impl)->_M_add_reference(); }
--- 189,195 ----
{
_S_initialize();
(_M_impl = _S_global)->_M_add_reference();
! }
locale::locale(const locale& __other) throw()
{ (_M_impl = __other._M_impl)->_M_add_reference(); }
***************
*** 283,289 ****
locale const&
locale::classic()
{
! // XXX MT
if (!_S_classic)
{
try
--- 285,293 ----
locale const&
locale::classic()
{
! static _STL_mutex_lock __lock __STL_MUTEX_INITIALIZER;
! _STL_auto_lock __auto(__lock);
!
if (!_S_classic)
{
try
***************
*** 364,376 ****
void
locale::facet::
_M_add_reference() throw()
! { ++_M_references; } // XXX MT
void
locale::facet::
_M_remove_reference() throw()
{
! if (_M_references-- == 0)
{
try
{ delete this; }
--- 368,380 ----
void
locale::facet::
_M_add_reference() throw()
! { __atomic_add(&_M_references, 1); }
void
locale::facet::
_M_remove_reference() throw()
{
! if (__exchange_and_add(&_M_references, -1) == 0)
{
try
{ delete this; }
Index: src/localename.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/localename.cc,v
retrieving revision 1.22
diff -c -r1.22 localename.cc
*** localename.cc 2002/01/04 21:27:35 1.22
--- localename.cc 2002/01/24 20:27:16
***************
*** 178,184 ****
{
size_t& __index = __idp->_M_index;
if (!__index)
! __index = ++locale::id::_S_highwater; // XXX MT
if (__index >= _M_facets->size())
_M_facets->resize(__index + 1, 0); // might throw
--- 178,184 ----
{
size_t& __index = __idp->_M_index;
if (!__index)
! __index = 1 + __exchange_and_add(&locale::id::_S_highwater, 1);
if (__index >= _M_facets->size())
_M_facets->resize(__index + 1, 0); // might throw
More information about the Libstdc++
mailing list