OSDN Git Service

2010-01-29 Paolo Carlini <paolo.carlini@oracle.com>
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 29 Jan 2010 16:59:55 +0000 (16:59 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 29 Jan 2010 16:59:55 +0000 (16:59 +0000)
* include/std/condition_variable (enum class cv_status): Add and
use it throughout, per N3000.
(condition_variable_any::wait<>(_Lock&), wait<>(_Lock&, _Predicate),
wait_until<>(_Lock&, const chrono::time_point<>&, _Predicate)):
Provide definitions.
* src/condition_variable.cc (condition_variable_any::notify_one,
condition_variable_any::notify_all): Likewise.
* config/abi/pre/gnu.ver: Export.
* testsuite/30_threads/condition_variable_any/requirements/
typedefs.cc: New.
* testsuite/30_threads/condition_variable_any/requirements/
standard_layout.cc: Likewise.
* testsuite/30_threads/condition_variable/members/1.cc: Adjust.
* testsuite/30_threads/condition_variable/members/2.cc: Likewise.
* testsuite/30_threads/condition_variable/cons/assign_neg.cc: Adjust
dg-error line numbers.
* testsuite/30_threads/condition_variable/cons/copy_neg.cc: Likewise.
* testsuite/30_threads/condition_variable_any/cons/assign_neg.cc:
Likewise.
* testsuite/30_threads/condition_variable_any/cons/copy_neg.cc:
Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@156358 138bc75d-0d04-0410-961f-82ee72b054a4

12 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/config/abi/pre/gnu.ver
libstdc++-v3/include/std/condition_variable
libstdc++-v3/src/condition_variable.cc
libstdc++-v3/testsuite/30_threads/condition_variable/cons/assign_neg.cc
libstdc++-v3/testsuite/30_threads/condition_variable/cons/copy_neg.cc
libstdc++-v3/testsuite/30_threads/condition_variable/members/1.cc
libstdc++-v3/testsuite/30_threads/condition_variable/members/2.cc
libstdc++-v3/testsuite/30_threads/condition_variable_any/cons/assign_neg.cc
libstdc++-v3/testsuite/30_threads/condition_variable_any/cons/copy_neg.cc
libstdc++-v3/testsuite/30_threads/condition_variable_any/requirements/standard_layout.cc [new file with mode: 0644]
libstdc++-v3/testsuite/30_threads/condition_variable_any/requirements/typedefs.cc [new file with mode: 0644]

index 6542223..33d7790 100644 (file)
@@ -1,3 +1,27 @@
+2010-01-29  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       * include/std/condition_variable (enum class cv_status): Add and
+       use it throughout, per N3000.
+       (condition_variable_any::wait<>(_Lock&), wait<>(_Lock&, _Predicate),
+       wait_until<>(_Lock&, const chrono::time_point<>&, _Predicate)):
+       Provide definitions.
+       * src/condition_variable.cc (condition_variable_any::notify_one,
+       condition_variable_any::notify_all): Likewise.
+       * config/abi/pre/gnu.ver: Export.
+       * testsuite/30_threads/condition_variable_any/requirements/
+       typedefs.cc: New.
+       * testsuite/30_threads/condition_variable_any/requirements/
+       standard_layout.cc: Likewise.
+       * testsuite/30_threads/condition_variable/members/1.cc: Adjust.
+       * testsuite/30_threads/condition_variable/members/2.cc: Likewise.
+       * testsuite/30_threads/condition_variable/cons/assign_neg.cc: Adjust
+       dg-error line numbers.
+       * testsuite/30_threads/condition_variable/cons/copy_neg.cc: Likewise.
+       * testsuite/30_threads/condition_variable_any/cons/assign_neg.cc:
+       Likewise.
+       * testsuite/30_threads/condition_variable_any/cons/copy_neg.cc:
+       Likewise.
+
 2010-01-28  Fran├žois Dumont  <francois.cppdevs@free.fr>
 
        * include/bits/stl_algobase.h (struct __iter_base): Add.
index 447b63e..4b5f6d0 100644 (file)
@@ -1113,6 +1113,10 @@ GLIBCXX_3.4.14 {
     # std::time_get::_M_extract_wday_or_month
     _ZNKSt8time_getI[cw]St19istreambuf_iteratorI[cw]St11char_traitsI[cw]EEE24_M_extract_wday_or_month*;
 
+    # condition_variable_any::notify_*
+    _ZNSt22condition_variable_any10notify_allEv;
+    _ZNSt22condition_variable_any10notify_oneEv;    
+
 } GLIBCXX_3.4.13;
 
 # Symbols in the support library (libsupc++) have their own tag.
index f87eb1b..ea4570e 100644 (file)
@@ -1,6 +1,6 @@
 // <condition_variable> -*- C++ -*-
 
-// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2008, 2009, 2010 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
@@ -50,6 +50,9 @@ namespace std
    * @{
    */
 
+  /// cv_status
+  enum class cv_status { no_timeout, timeout };
+  
   /// condition_variable
   class condition_variable
   {
@@ -84,13 +87,13 @@ namespace std
       }
 
     template<typename _Duration>
-      bool
+      cv_status
       wait_until(unique_lock<mutex>& __lock,
                 const chrono::time_point<__clock_t, _Duration>& __atime)
       { return __wait_until_impl(__lock, __atime); }
 
     template<typename _Clock, typename _Duration>
-      bool
+      cv_status
       wait_until(unique_lock<mutex>& __lock,
                 const chrono::time_point<_Clock, _Duration>& __atime)
       {
@@ -110,14 +113,13 @@ namespace std
                 _Predicate __p)
       {
        while (!__p())
-         if (!wait_until(__lock, __atime))
+         if (wait_until(__lock, __atime) == cv_status::timeout)
            return __p();
-
        return true;
       }
 
     template<typename _Rep, typename _Period>
-      bool
+      cv_status
       wait_for(unique_lock<mutex>& __lock,
               const chrono::duration<_Rep, _Period>& __rtime)
       { return wait_until(__lock, __clock_t::now() + __rtime); }
@@ -135,7 +137,7 @@ namespace std
 
   private:
     template<typename _Clock, typename _Duration>
-      bool
+      cv_status
       __wait_until_impl(unique_lock<mutex>& __lock,
                        const chrono::time_point<_Clock, _Duration>& __atime)
       {
@@ -154,7 +156,8 @@ namespace std
        __gthread_cond_timedwait(&_M_cond, __lock.mutex()->native_handle(),
                                 &__ts);
 
-       return _Clock::now() < __atime;
+       return (_Clock::now() < __atime
+               ? cv_status::no_timeout : cv_status::timeout);
       }
   };
 
@@ -182,14 +185,24 @@ namespace std
 
     template<typename _Lock>
       void
-      wait(_Lock& __lock);
+      wait(_Lock& __lock)
+      {
+       int __e = __gthread_cond_wait(&_M_cond,
+                                     __lock.mutex()->native_handle());
+       if (__e)
+         __throw_system_error(__e);
+      }
 
     template<typename _Lock, typename _Predicate>
       void
-      wait(_Lock& __lock, _Predicate __p);
+      wait(_Lock& __lock, _Predicate __p)
+      {
+       while (!__p())
+         wait(__lock);
+      }
 
     template<typename _Lock, typename _Clock, typename _Duration>
-      bool
+      cv_status
       wait_until(_Lock& __lock,
                 const chrono::time_point<_Clock, _Duration>& __atime);
 
@@ -198,10 +211,16 @@ namespace std
       bool
       wait_until(_Lock& __lock,
                 const chrono::time_point<_Clock, _Duration>& __atime,
-                _Predicate __p);
+                _Predicate __p)
+      {
+       while (!__p())
+         if (wait_until(__lock, __atime) == cv_status::timeout)
+           return __p();
+       return true;
+      }
 
     template<typename _Lock, typename _Rep, typename _Period>
-      bool
+      cv_status
       wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __rtime);
 
     template<typename _Lock, typename _Rep,
index 4fb2f17..b420379 100644 (file)
@@ -96,6 +96,28 @@ namespace std
   {
     __gthread_cond_destroy(&_M_cond);
   }
+
+  void
+  condition_variable_any::notify_one()
+  {
+    int __e = __gthread_cond_signal(&_M_cond);
+
+    // XXX not in spec
+    // EINVAL
+    if (__e)
+      __throw_system_error(__e);
+  }
+
+  void
+  condition_variable_any::notify_all()
+  {
+    int __e = __gthread_cond_broadcast(&_M_cond);
+
+    // XXX not in spec
+    // EINVAL
+    if (__e)
+      __throw_system_error(__e);
+  }
 }
 
 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
index 04e492b..9e9ad8a 100644 (file)
@@ -32,4 +32,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 31 }
-// { dg-error "deleted function" "" { target *-*-* } 67 }
+// { dg-error "deleted function" "" { target *-*-* } 70 }
index 0d06628..5765351 100644 (file)
@@ -31,4 +31,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 30 }
-// { dg-error "deleted function" "" { target *-*-* } 66 }
+// { dg-error "deleted function" "" { target *-*-* } 69 }
index 4dea137..127960a 100644 (file)
@@ -40,8 +40,8 @@ int main()
       std::unique_lock<std::mutex> l(m);
 
       auto then = std::chrono::system_clock::now();
-      bool result = c1.wait_for(l, ms);
-      VERIFY( !result );
+      std::cv_status result = c1.wait_for(l, ms);
+      VERIFY( result == std::cv_status::timeout );
       VERIFY( (std::chrono::system_clock::now() - then) >= ms );
       VERIFY( l.owns_lock() );
     }
index fe17666..ab2e877 100644 (file)
@@ -40,8 +40,8 @@ int main()
       std::unique_lock<std::mutex> l(m);
 
       auto then = std::chrono::monotonic_clock::now();
-      bool result = c1.wait_until(l, then + ms);
-      VERIFY( !result );
+      std::cv_status result = c1.wait_until(l, then + ms);
+      VERIFY( result == std::cv_status::timeout );
       VERIFY( (std::chrono::monotonic_clock::now() - then) >= ms );
       VERIFY( l.owns_lock() );
     }
index 473f326..5e3e302 100644 (file)
@@ -3,7 +3,7 @@
 // { dg-require-cstdint "" }
 // { dg-require-gthreads "" }
 
-// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2008, 2009, 2010 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
@@ -32,4 +32,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 31 }
-// { dg-error "deleted function" "" { target *-*-* } 175 }
+// { dg-error "deleted function" "" { target *-*-* } 178 }
index 1d06c2d..2b61c1b 100644 (file)
@@ -3,7 +3,7 @@
 // { dg-require-cstdint "" }
 // { dg-require-gthreads "" }
 
-// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2008, 2009, 2010 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
@@ -31,4 +31,4 @@ void test01()
 }
 
 // { dg-error "used here" "" { target *-*-* } 30 }
-// { dg-error "deleted function" "" { target *-*-* } 174 }
+// { dg-error "deleted function" "" { target *-*-* } 177 }
diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable_any/requirements/standard_layout.cc b/libstdc++-v3/testsuite/30_threads/condition_variable_any/requirements/standard_layout.cc
new file mode 100644 (file)
index 0000000..74e57ab
--- /dev/null
@@ -0,0 +1,30 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+
+// Copyright (C) 2010 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 <condition_variable>
+#include <testsuite_common_types.h>
+
+void test01()
+{
+  __gnu_test::standard_layout test;
+  test.operator()<std::condition_variable_any>();
+}
diff --git a/libstdc++-v3/testsuite/30_threads/condition_variable_any/requirements/typedefs.cc b/libstdc++-v3/testsuite/30_threads/condition_variable_any/requirements/typedefs.cc
new file mode 100644 (file)
index 0000000..8a6fd82
--- /dev/null
@@ -0,0 +1,30 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+
+// Copyright (C) 2010 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 <condition_variable>
+
+void test01()
+{
+  // Check for required typedefs
+  typedef std::condition_variable_any test_type;
+  typedef test_type::native_handle_type type;
+}