summaryrefslogtreecommitdiff
path: root/libstdc++-v3/src
diff options
context:
space:
mode:
authorAndrew Pollard <andrew@andypo.net>2002-01-24 21:14:41 +0000
committerLoren J. Rittle <ljrittle@gcc.gnu.org>2002-01-24 21:14:41 +0000
commit17325050c2b41359e31f251d9a445c32f046031b (patch)
treecba821500b80780c5d81a3c969b81dc1eccbf9bf /libstdc++-v3/src
parenta4f76ef9f331f1b052226d40ff6fd9d79c5606f3 (diff)
downloadgcc-17325050c2b41359e31f251d9a445c32f046031b.tar.gz
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
Diffstat (limited to 'libstdc++-v3/src')
-rw-r--r--libstdc++-v3/src/ios.cc12
-rw-r--r--libstdc++-v3/src/locale.cc14
-rw-r--r--libstdc++-v3/src/localename.cc2
3 files changed, 18 insertions, 10 deletions
diff --git a/libstdc++-v3/src/ios.cc b/libstdc++-v3/src/ios.cc
index 6ca59572fba..e8122bb2b77 100644
--- a/libstdc++-v3/src/ios.cc
+++ b/libstdc++-v3/src/ios.cc
@@ -1,6 +1,7 @@
// 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
// software; you can redistribute it and/or modify it under the
@@ -36,6 +37,8 @@
#include <istream>
#include <fstream>
+#include <bits/atomicity.h>
+
namespace std
{
// Extern declarations for global objects in src/globals.cc.
@@ -224,10 +227,11 @@ namespace std
int
ios_base::xalloc() throw()
{
- // XXX MT
// XXX should be a symbol. (Reserve 0..3 for builtins.)
- static int top = 4;
- return top++;
+ 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
diff --git a/libstdc++-v3/src/locale.cc b/libstdc++-v3/src/locale.cc
index 630805ee0fa..52091827259 100644
--- a/libstdc++-v3/src/locale.cc
+++ b/libstdc++-v3/src/locale.cc
@@ -41,6 +41,8 @@
# include <cwctype> // for towupper, etc.
#endif
+#include <bits/atomicity.h>
+
namespace std
{
// Defined in globals.cc.
@@ -72,7 +74,7 @@ namespace std
#endif
// 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
const locale::id* const
@@ -187,7 +189,7 @@ namespace std
{
_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(); }
@@ -283,7 +285,9 @@ namespace std
locale const&
locale::classic()
{
- // XXX MT
+ static _STL_mutex_lock __lock __STL_MUTEX_INITIALIZER;
+ _STL_auto_lock __auto(__lock);
+
if (!_S_classic)
{
try
@@ -364,13 +368,13 @@ namespace std
void
locale::facet::
_M_add_reference() throw()
- { ++_M_references; } // XXX MT
+ { __atomic_add(&_M_references, 1); }
void
locale::facet::
_M_remove_reference() throw()
{
- if (_M_references-- == 0)
+ if (__exchange_and_add(&_M_references, -1) == 0)
{
try
{ delete this; }
diff --git a/libstdc++-v3/src/localename.cc b/libstdc++-v3/src/localename.cc
index 45c4732d007..816f7581c12 100644
--- a/libstdc++-v3/src/localename.cc
+++ b/libstdc++-v3/src/localename.cc
@@ -178,7 +178,7 @@ namespace std
{
size_t& __index = __idp->_M_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())
_M_facets->resize(__index + 1, 0); // might throw