summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2005-04-05 11:08:55 +0000
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2005-04-05 11:08:55 +0000
commit49a17d00eb70141b68497495803b62146fd3d7b9 (patch)
treecd11923f6c07d5cfe3ca28c23d7985b110a02994 /libstdc++-v3
parentf25e793234195571de33aa4963cbf1a7495a76b4 (diff)
downloadgcc-49a17d00eb70141b68497495803b62146fd3d7b9.tar.gz
* include/tr1/memory, include/tr1/boost_shared_ptr.h: Use mutex
to make _Sp_counted_base::add_ref_lock() thread-safe. Check whether to destroy resources by testing for equality, not inequality. Add empty critical sections to solve memory visibility issues. * testsuite/tr1/2_general_utilities/memory/ shared_ptr/cons/auto_ptr_neg.cc: Use dg-excess-errors instead of explicitly listing line numbers which need to be kept in sync. * testsuite/tr1/2_general_utilities/memory/ shared_ptr/assign/auto_ptr_neg.cc: Same. * testsuite/tr1/2_general_utilities/memory/ shared_ptr/assign/auto_ptr_rvalue_neg.cc: Same. * testsuite/tr1/2_general_utilities/memory/ shared_ptr/cons/weak_ptr_expired.cc: Make XFAIL for consistency when -fno-exceptions. * testsuite/tr1/2_general_utilities/memory/ enable_shared_from_this/not_shared.cc: Add explanatory comments. * testsuite/tr1/2_general_utilities/memory/ enable_shared_from_this/not_shared2.cc: Same. * testsuite/tr1/2_general_utilities/memory/ enable_shared_from_this/not_shared3.cc: Same. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@97620 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog23
-rw-r--r--libstdc++-v3/include/tr1/boost_shared_ptr.h14
-rw-r--r--libstdc++-v3/include/tr1/memory1
-rw-r--r--libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/not_shared.cc2
-rw-r--r--libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/not_shared2.cc5
-rw-r--r--libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/not_shared3.cc5
-rw-r--r--libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/assign/auto_ptr_neg.cc4
-rw-r--r--libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/assign/auto_ptr_rvalue_neg.cc3
-rw-r--r--libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/cons/auto_ptr_neg.cc4
-rw-r--r--libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/cons/weak_ptr_expired.cc5
10 files changed, 52 insertions, 14 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 110376e2c02..7461bd1e318 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,26 @@
+2005-04-05 Jonathan Wakely <redi@gcc.gnu.org>
+
+ * include/tr1/memory, include/tr1/boost_shared_ptr.h: Use mutex
+ to make _Sp_counted_base::add_ref_lock() thread-safe. Check whether
+ to destroy resources by testing for equality, not inequality. Add
+ empty critical sections to solve memory visibility issues.
+ * testsuite/tr1/2_general_utilities/memory/
+ shared_ptr/cons/auto_ptr_neg.cc: Use dg-excess-errors instead of
+ explicitly listing line numbers which need to be kept in sync.
+ * testsuite/tr1/2_general_utilities/memory/
+ shared_ptr/assign/auto_ptr_neg.cc: Same.
+ * testsuite/tr1/2_general_utilities/memory/
+ shared_ptr/assign/auto_ptr_rvalue_neg.cc: Same.
+ * testsuite/tr1/2_general_utilities/memory/
+ shared_ptr/cons/weak_ptr_expired.cc: Make XFAIL for consistency when
+ -fno-exceptions.
+ * testsuite/tr1/2_general_utilities/memory/
+ enable_shared_from_this/not_shared.cc: Add explanatory comments.
+ * testsuite/tr1/2_general_utilities/memory/
+ enable_shared_from_this/not_shared2.cc: Same.
+ * testsuite/tr1/2_general_utilities/memory/
+ enable_shared_from_this/not_shared3.cc: Same.
+
2005-04-05 Kelley Cook <kcook@gcc.gnu.org>
* acconfig.h: Delete macros already ACDEFINED.
diff --git a/libstdc++-v3/include/tr1/boost_shared_ptr.h b/libstdc++-v3/include/tr1/boost_shared_ptr.h
index f55c0537586..3426a4acebe 100644
--- a/libstdc++-v3/include/tr1/boost_shared_ptr.h
+++ b/libstdc++-v3/include/tr1/boost_shared_ptr.h
@@ -131,19 +131,22 @@ public:
void
add_ref_lock()
{
- if (_M_use_count <= 0) // TODO not yet MT safe XXX
+ __gnu_cxx::lock lock(_M_mutex);
+ if (__gnu_cxx::__exchange_and_add(&_M_use_count, 1) == 0)
{
+ _M_use_count = 0;
__throw_bad_weak_ptr();
}
- __gnu_cxx::__atomic_add(&_M_use_count, 1);
}
void
release() // nothrow
{
- if (__gnu_cxx::__exchange_and_add(&_M_use_count, -1) <= 1)
+ if (__gnu_cxx::__exchange_and_add(&_M_use_count, -1) == 1)
{
dispose();
+ __glibcxx_mutex_lock(_M_mutex);
+ __glibcxx_mutex_unlock(_M_mutex);
weak_release();
}
}
@@ -157,8 +160,10 @@ public:
void
weak_release() // nothrow
{
- if (__gnu_cxx::__exchange_and_add(&_M_weak_count, -1) <= 1)
+ if (__gnu_cxx::__exchange_and_add(&_M_weak_count, -1) == 1)
{
+ __glibcxx_mutex_lock(_M_mutex);
+ __glibcxx_mutex_unlock(_M_mutex);
destroy();
}
}
@@ -176,6 +181,7 @@ private:
_Atomic_word _M_use_count; // #shared
_Atomic_word _M_weak_count; // #weak + (#shared != 0)
+ __gnu_cxx::mutex_type _M_mutex;
};
template <typename _Ptr, typename _Deleter>
diff --git a/libstdc++-v3/include/tr1/memory b/libstdc++-v3/include/tr1/memory
index 93d206e5c29..294d4868a47 100644
--- a/libstdc++-v3/include/tr1/memory
+++ b/libstdc++-v3/include/tr1/memory
@@ -43,6 +43,7 @@
#include <bits/gthr.h>
#include <bits/atomicity.h>
#include <bits/functexcept.h>
+#include <bits/concurrence.h>
#include <debug/debug.h>
#include <tr1/boost_shared_ptr.h>
diff --git a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/not_shared.cc b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/not_shared.cc
index 493bd84a77c..2c36c7ea08a 100644
--- a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/not_shared.cc
+++ b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/not_shared.cc
@@ -39,10 +39,12 @@ test01()
}
catch (const std::tr1::bad_weak_ptr&)
{
+ // Expected.
__throw_exception_again;
}
catch (...)
{
+ // Failed.
}
return 0;
diff --git a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/not_shared2.cc b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/not_shared2.cc
index a6ca74da389..0043b33dfd4 100644
--- a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/not_shared2.cc
+++ b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/not_shared2.cc
@@ -41,8 +41,13 @@ test01()
}
catch (const std::tr1::bad_weak_ptr&)
{
+ // Expected.
__throw_exception_again;
}
+ catch (...)
+ {
+ // Failed.
+ }
return 0;
}
diff --git a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/not_shared3.cc b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/not_shared3.cc
index 3bca336bc20..c5e10d1a73c 100644
--- a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/not_shared3.cc
+++ b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/enable_shared_from_this/not_shared3.cc
@@ -42,8 +42,13 @@ test01()
}
catch (const std::tr1::bad_weak_ptr&)
{
+ // Expected.
__throw_exception_again;
}
+ catch (...)
+ {
+ // Failed.
+ }
return 0;
}
diff --git a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/assign/auto_ptr_neg.cc b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/assign/auto_ptr_neg.cc
index 433f951c139..587e8e66b86 100644
--- a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/assign/auto_ptr_neg.cc
+++ b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/assign/auto_ptr_neg.cc
@@ -47,6 +47,4 @@ main()
test01();
return 0;
}
-// { dg-error "In constructor" "" { target *-*-* } 0 }
-// { dg-error "cannot convert" "" { target *-*-* } 0 }
-// { dg-error "instantiated from" "" { target *-*-* } 0 }
+// { dg-excess-errors "In constructor" }
diff --git a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/assign/auto_ptr_rvalue_neg.cc b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/assign/auto_ptr_rvalue_neg.cc
index f119a59a939..e9678b93009 100644
--- a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/assign/auto_ptr_rvalue_neg.cc
+++ b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/assign/auto_ptr_rvalue_neg.cc
@@ -46,5 +46,4 @@ main()
test01();
return 0;
}
-// { dg-error "auto_ptr" "" { target *-*-* } 0 }
-// { dg-error "shared_ptr" "" { target *-*-* } 0 }
+// { dg-excess-errors "candidates are" }
diff --git a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/cons/auto_ptr_neg.cc b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/cons/auto_ptr_neg.cc
index ec219066aac..9eafc88deb9 100644
--- a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/cons/auto_ptr_neg.cc
+++ b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/cons/auto_ptr_neg.cc
@@ -45,6 +45,4 @@ main()
test01();
return 0;
}
-// { dg-error "shared_ptr" "candidates are" { target *-*-* } 478 }
-
-// { dg-error "shared_ptr" "" { target *-*-* } 468 }
+// { dg-excess-errors "candidates are" }
diff --git a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/cons/weak_ptr_expired.cc b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/cons/weak_ptr_expired.cc
index 8b0213ec726..63dcae49276 100644
--- a/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/cons/weak_ptr_expired.cc
+++ b/libstdc++-v3/testsuite/tr1/2_general_utilities/memory/shared_ptr/cons/weak_ptr_expired.cc
@@ -1,3 +1,4 @@
+// { dg-do run { xfail *-*-* } }
// Copyright (C) 2005 Free Software Foundation
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -34,6 +35,7 @@ test01()
std::tr1::shared_ptr<A> a1(new A);
std::tr1::weak_ptr<A> wa(a1);
a1.reset();
+ VERIFY( wa.expired() );
try
{
std::tr1::shared_ptr<A> a2(wa);
@@ -41,13 +43,12 @@ test01()
catch (const std::tr1::bad_weak_ptr&)
{
// Expected.
+ __throw_exception_again;
}
catch (...)
{
// Failed.
- __throw_exception_again;
}
- VERIFY( wa.expired() );
return 0;
}