Commit 17325050 by Andrew Pollard Committed by Loren J. Rittle

ios_base.h: Use _Atomic_word for reference counts.

	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.

From-SVN: r49195
parent a4f76ef9
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.
2002-01-24 Benjamin Kosnik <bkoz@redhat.com> 2002-01-24 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/22_locale/num_put_members_wchar_t.cc (test03): Use * testsuite/22_locale/num_put_members_wchar_t.cc (test03): Use
......
// Iostreams base classes -*- C++ -*- // Iostreams base classes -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. // 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 // 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 // software; you can redistribute it and/or modify it under the
...@@ -41,6 +42,8 @@ ...@@ -41,6 +42,8 @@
#pragma GCC system_header #pragma GCC system_header
#include <bits/atomicity.h>
namespace std namespace std
{ {
// The following definitions of bitmask types are enums, not ints, // The following definitions of bitmask types are enums, not ints,
...@@ -244,17 +247,18 @@ namespace std ...@@ -244,17 +247,18 @@ namespace std
_Callback_list* _M_next; _Callback_list* _M_next;
ios_base::event_callback _M_fn; ios_base::event_callback _M_fn;
int _M_index; int _M_index;
int _M_refcount; // 0 means one reference. _Atomic_word _M_refcount; // 0 means one reference.
_Callback_list(ios_base::event_callback __fn, int __index, _Callback_list(ios_base::event_callback __fn, int __index,
_Callback_list* __cb) _Callback_list* __cb)
: _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { } : _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { }
void void
_M_add_reference() { ++_M_refcount; } // XXX MT _M_add_reference() { __atomic_add(&_M_refcount, 1); }
int int
_M_remove_reference() { return _M_refcount--; } // 0 => OK to delete _M_remove_reference() { return __exchange_and_add(&_M_refcount, -1); }
// 0 => OK to delete
}; };
_Callback_list* _M_callbacks; _Callback_list* _M_callbacks;
......
...@@ -49,6 +49,8 @@ ...@@ -49,6 +49,8 @@
#include <string> // For string #include <string> // For string
#include <bits/functexcept.h> #include <bits/functexcept.h>
#include <bits/atomicity.h>
namespace std namespace std
{ {
// NB: Don't instantiate required wchar_t facets if no wchar_t support. // NB: Don't instantiate required wchar_t facets if no wchar_t support.
...@@ -317,7 +319,7 @@ namespace std ...@@ -317,7 +319,7 @@ namespace std
private: private:
// Data Members. // Data Members.
size_t _M_references; _Atomic_word _M_references;
__vec_facet* _M_facets; __vec_facet* _M_facets;
string _M_names[_S_num_categories]; string _M_names[_S_num_categories];
static const locale::id* const _S_id_ctype[]; static const locale::id* const _S_id_ctype[];
...@@ -330,12 +332,12 @@ namespace std ...@@ -330,12 +332,12 @@ namespace std
inline void inline void
_M_add_reference() throw() _M_add_reference() throw()
{ ++_M_references; } // XXX MT { __atomic_add(&_M_references, 1); }
inline void inline void
_M_remove_reference() throw() _M_remove_reference() throw()
{ {
if (--_M_references == 0) // XXX MT if (__exchange_and_add(&_M_references, -1) == 1)
{ {
try try
{ delete this; } { delete this; }
...@@ -392,7 +394,7 @@ namespace std ...@@ -392,7 +394,7 @@ namespace std
friend class __enc_traits; friend class __enc_traits;
private: private:
size_t _M_references; _Atomic_word _M_references;
protected: protected:
// Contains data from the underlying "C" library for default "C" // Contains data from the underlying "C" library for default "C"
...@@ -447,7 +449,7 @@ namespace std ...@@ -447,7 +449,7 @@ namespace std
mutable size_t _M_index; mutable size_t _M_index;
// Last id number assigned // Last id number assigned
static size_t _S_highwater; static _Atomic_word _S_highwater;
void void
operator=(const id&); // not defined operator=(const id&); // not defined
......
// Iostreams base classes -*- C++ -*- // Iostreams base classes -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. // 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 // 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 // software; you can redistribute it and/or modify it under the
...@@ -36,6 +37,8 @@ ...@@ -36,6 +37,8 @@
#include <istream> #include <istream>
#include <fstream> #include <fstream>
#include <bits/atomicity.h>
namespace std namespace std
{ {
// Extern declarations for global objects in src/globals.cc. // Extern declarations for global objects in src/globals.cc.
...@@ -224,10 +227,11 @@ namespace std ...@@ -224,10 +227,11 @@ namespace std
int int
ios_base::xalloc() throw() ios_base::xalloc() throw()
{ {
// XXX MT
// XXX should be a symbol. (Reserve 0..3 for builtins.) // XXX should be a symbol. (Reserve 0..3 for builtins.)
static int top = 4; static _Atomic_word top = 0;
return top++; 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 // 27.4.2.5 iword/pword storage
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
# include <cwctype> // for towupper, etc. # include <cwctype> // for towupper, etc.
#endif #endif
#include <bits/atomicity.h>
namespace std namespace std
{ {
// Defined in globals.cc. // Defined in globals.cc.
...@@ -72,7 +74,7 @@ namespace std ...@@ -72,7 +74,7 @@ namespace std
#endif #endif
// Definitions for static const data members of locale::id // Definitions for static const data members of locale::id
size_t locale::id::_S_highwater; // init'd to 0 by linker _Atomic_word locale::id::_S_highwater; // init'd to 0 by linker
// Definitions for static const data members of locale::_Impl // Definitions for static const data members of locale::_Impl
const locale::id* const const locale::id* const
...@@ -187,7 +189,7 @@ namespace std ...@@ -187,7 +189,7 @@ namespace std
{ {
_S_initialize(); _S_initialize();
(_M_impl = _S_global)->_M_add_reference(); (_M_impl = _S_global)->_M_add_reference();
} // XXX MT }
locale::locale(const locale& __other) throw() locale::locale(const locale& __other) throw()
{ (_M_impl = __other._M_impl)->_M_add_reference(); } { (_M_impl = __other._M_impl)->_M_add_reference(); }
...@@ -283,7 +285,9 @@ namespace std ...@@ -283,7 +285,9 @@ namespace std
locale const& locale const&
locale::classic() locale::classic()
{ {
// XXX MT static _STL_mutex_lock __lock __STL_MUTEX_INITIALIZER;
_STL_auto_lock __auto(__lock);
if (!_S_classic) if (!_S_classic)
{ {
try try
...@@ -364,13 +368,13 @@ namespace std ...@@ -364,13 +368,13 @@ namespace std
void void
locale::facet:: locale::facet::
_M_add_reference() throw() _M_add_reference() throw()
{ ++_M_references; } // XXX MT { __atomic_add(&_M_references, 1); }
void void
locale::facet:: locale::facet::
_M_remove_reference() throw() _M_remove_reference() throw()
{ {
if (_M_references-- == 0) if (__exchange_and_add(&_M_references, -1) == 0)
{ {
try try
{ delete this; } { delete this; }
......
...@@ -178,7 +178,7 @@ namespace std ...@@ -178,7 +178,7 @@ namespace std
{ {
size_t& __index = __idp->_M_index; size_t& __index = __idp->_M_index;
if (!__index) if (!__index)
__index = ++locale::id::_S_highwater; // XXX MT __index = 1 + __exchange_and_add(&locale::id::_S_highwater, 1);
if (__index >= _M_facets->size()) if (__index >= _M_facets->size())
_M_facets->resize(__index + 1, 0); // might throw _M_facets->resize(__index + 1, 0); // might throw
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment