public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [v3] libstdc++/40654/40826
@ 2009-10-16  7:51 Benjamin Kosnik
  0 siblings, 0 replies; only message in thread
From: Benjamin Kosnik @ 2009-10-16  7:51 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 92 bytes --]


Some fixups now that standard_layout support is more solid.

tested x86_64/linux

-benjamin

[-- Attachment #2: 20091015-1.patch --]
[-- Type: text/x-patch, Size: 6209 bytes --]

2009-10-15  Benjamin Kosnik  <bkoz@redhat.com>

	PR libstdc++/40654
	PR libstdc++/40826
	* src/atomic.cc (atomic_flag_test_and_set_explicit): Add
	static_cast from base to derived.
	(atomic_flag_clear_explicit): Same.
	* include/bits/atomic_2.h (__atomic2::atomic_flag): Public derivation.
	Remove value type constructor.
	* include/bits/atomic_0.h (__atomic0::atomic_flag): Same.
	* include/std/future (_Future_state): Use ATOMIC_FLAG_INIT to
	initialized the atomic_flag member.

Index: src/atomic.cc
===================================================================
--- src/atomic.cc	(revision 152888)
+++ src/atomic.cc	(working copy)
@@ -80,16 +80,16 @@
     atomic_flag_test_and_set_explicit(volatile __atomic_flag_base* __a,
 				      memory_order __m) throw ()
     {
-      volatile atomic_flag d(__a->_M_i);
-      return d.test_and_set(__m);
+      volatile atomic_flag* d = static_cast<volatile atomic_flag*>(__a);
+      return d->test_and_set(__m);
     }
 
     void
     atomic_flag_clear_explicit(volatile __atomic_flag_base* __a,
 			       memory_order __m) throw ()
     {
-      volatile atomic_flag d(__a->_M_i);
-      return d.clear(__m);
+      volatile atomic_flag* d = static_cast<volatile atomic_flag*>(__a);
+      return d->clear(__m);
     }
 
     void
Index: include/std/future
===================================================================
--- include/std/future	(revision 152888)
+++ include/std/future	(working copy)
@@ -150,7 +150,7 @@
     typedef _Future_ptr<_Future_result_base>::type _Future_ptr_type;
 
   public:
-    _Future_state() : _M_result(), _M_retrieved(false) { }
+    _Future_state() : _M_result(), _M_retrieved(ATOMIC_FLAG_INIT) { }
 
     _Future_state(const _Future_state&) = delete;
     _Future_state& operator=(const _Future_state&) = delete;
Index: include/bits/atomic_0.h
===================================================================
--- include/bits/atomic_0.h	(revision 152888)
+++ include/bits/atomic_0.h	(working copy)
@@ -82,14 +82,15 @@
     __r; })
 
   /// atomic_flag
-  struct atomic_flag : private __atomic_flag_base
+  struct atomic_flag : public __atomic_flag_base
   {
     atomic_flag() = default;
     ~atomic_flag() = default;
     atomic_flag(const atomic_flag&) = delete;
     atomic_flag& operator=(const atomic_flag&) = delete;
 
-    atomic_flag(bool __i) { _M_i = __i; } // XXX deleted copy ctor != agg
+    // Conversion to ATOMIC_FLAG_INIT.
+    atomic_flag(bool __i): __atomic_flag_base({ __i }) { }
 
     bool
     test_and_set(memory_order __m = memory_order_seq_cst) volatile;
Index: include/bits/atomic_2.h
===================================================================
--- include/bits/atomic_2.h	(revision 152888)
+++ include/bits/atomic_2.h	(working copy)
@@ -44,14 +44,15 @@
 namespace __atomic2
 {
   /// atomic_flag
-  struct atomic_flag : private __atomic_flag_base
+  struct atomic_flag : public __atomic_flag_base
   {
     atomic_flag() = default;
     ~atomic_flag() = default;
     atomic_flag(const atomic_flag&) = delete;
     atomic_flag& operator=(const atomic_flag&) = delete;
 
-    atomic_flag(bool __i) { _M_i = __i; } // XXX deleted copy ctor != agg
+    // Conversion to ATOMIC_FLAG_INIT.
+    atomic_flag(bool __i): __atomic_flag_base({ __i }) { }
 
     bool
     test_and_set(memory_order __m = memory_order_seq_cst) volatile
Index: testsuite/29_atomics/atomic_flag/clear/1.c
===================================================================
--- testsuite/29_atomics/atomic_flag/clear/1.c	(revision 0)
+++ testsuite/29_atomics/atomic_flag/clear/1.c	(revision 0)
@@ -0,0 +1,34 @@
+// { dg-options "-x c -shared-libgcc -lstdc++" }
+
+// Copyright (C) 2009 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <cassert>
+#include <stdatomic.h>
+
+// libstdc++/40826
+// libstdc++/40654
+int main()
+{
+  atomic_flag f = ATOMIC_FLAG_INIT;
+
+  atomic_flag_clear(&f); // set to false
+  assert( false == atomic_flag_test_and_set(&f) ); // return previous false, set to true
+  assert( true == atomic_flag_test_and_set(&f) ); // return true
+
+  return 0;
+}
Index: testsuite/29_atomics/atomic_flag/clear/1.cc
===================================================================
--- testsuite/29_atomics/atomic_flag/clear/1.cc	(revision 0)
+++ testsuite/29_atomics/atomic_flag/clear/1.cc	(revision 0)
@@ -0,0 +1,33 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2009 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <cstdatomic>
+#include <testsuite_hooks.h>
+
+int main()
+{
+  bool test __attribute__((unused)) = true;
+  std::atomic_flag f = ATOMIC_FLAG_INIT;
+
+  f.clear(); // set to false
+  VERIFY( false == f.test_and_set() ); // return previous false, set to true
+  VERIFY( true == f.test_and_set() ); // return true
+
+  return 0;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-10-16  7:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-16  7:51 [v3] libstdc++/40654/40826 Benjamin Kosnik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).