]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
all.h (compare_type_to_native_type_sizes): To...
authorBenjamin Kosnik <bkoz@redhat.com>
Fri, 13 Feb 2009 00:14:42 +0000 (00:14 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Fri, 13 Feb 2009 00:14:42 +0000 (00:14 +0000)
2009-02-12  Benjamin Kosnik  <bkoz@redhat.com>

* testsuite/util/thread/all.h (compare_type_to_native_type_sizes): To...
(compare_type_to_native_type): ...this, add alignment check.
* testsuite/30_threads/condition_variable_any/native_handle/
typesizes.cc: Modify as above.
* testsuite/30_threads/mutex/native_handle/typesizes.cc: Same.
* testsuite/30_threads/timed_mutex/native_handle/typesizes.cc: Same.
* testsuite/30_threads/thread/native_handle/typesizes.cc: Same.
* testsuite/30_threads/recursive_mutex/native_handle/typesizes.cc: Same.
* testsuite/30_threads/condition_variable/native_handle/
typesizes.cc: Same.
* testsuite/30_threads/recursive_timed_mutex/native_handle/
typesizes.cc: Same.

* testsuite/30_threads/thread/cons/1.cc: Add comments.
* testsuite/30_threads/thread/cons/2.cc: Same.
* testsuite/30_threads/thread/cons/3.cc: Same.
* testsuite/30_threads/thread/cons/4.cc: Same.
* testsuite/30_threads/thread/cons/5.cc: Same.
* testsuite/30_threads/thread/cons/6.cc: Same.
* testsuite/30_threads/thread/cons/7.cc: Same.
* testsuite/30_threads/thread/cons/8.cc: Same.

* testsuite/30_threads/thread/cons/9.cc: New.
* testsuite/30_threads/thread/cons/moveable.cc: New.

* src/condition_variable.cc: Clean up whitespace.
* include/std/condition_variable: Same.

From-SVN: r144142

19 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/include/std/condition_variable
libstdc++-v3/src/condition_variable.cc
libstdc++-v3/testsuite/30_threads/condition_variable/native_handle/typesizes.cc
libstdc++-v3/testsuite/30_threads/condition_variable_any/native_handle/typesizes.cc
libstdc++-v3/testsuite/30_threads/mutex/native_handle/typesizes.cc
libstdc++-v3/testsuite/30_threads/recursive_mutex/native_handle/typesizes.cc
libstdc++-v3/testsuite/30_threads/recursive_timed_mutex/native_handle/typesizes.cc
libstdc++-v3/testsuite/30_threads/thread/cons/1.cc
libstdc++-v3/testsuite/30_threads/thread/cons/2.cc
libstdc++-v3/testsuite/30_threads/thread/cons/3.cc
libstdc++-v3/testsuite/30_threads/thread/cons/4.cc
libstdc++-v3/testsuite/30_threads/thread/cons/5.cc
libstdc++-v3/testsuite/30_threads/thread/cons/6.cc
libstdc++-v3/testsuite/30_threads/thread/cons/7.cc
libstdc++-v3/testsuite/30_threads/thread/cons/8.cc
libstdc++-v3/testsuite/30_threads/thread/native_handle/typesizes.cc
libstdc++-v3/testsuite/30_threads/timed_mutex/native_handle/typesizes.cc
libstdc++-v3/testsuite/util/thread/all.h

index b04ae7d8878a7489c92dd2221d3cc9d9f2c8be78..c60b452f7246a377e4d4ba65672699883a553307 100644 (file)
@@ -1,3 +1,33 @@
+2009-02-12  Benjamin Kosnik  <bkoz@redhat.com>
+
+       * testsuite/util/thread/all.h (compare_type_to_native_type_sizes): To...
+       (compare_type_to_native_type): ...this, add alignment check.
+       * testsuite/30_threads/condition_variable_any/native_handle/
+       typesizes.cc: Modify as above.
+       * testsuite/30_threads/mutex/native_handle/typesizes.cc: Same.
+       * testsuite/30_threads/timed_mutex/native_handle/typesizes.cc: Same.
+       * testsuite/30_threads/thread/native_handle/typesizes.cc: Same.
+       * testsuite/30_threads/recursive_mutex/native_handle/typesizes.cc: Same.
+       * testsuite/30_threads/condition_variable/native_handle/
+       typesizes.cc: Same.
+       * testsuite/30_threads/recursive_timed_mutex/native_handle/
+       typesizes.cc: Same.
+
+       * testsuite/30_threads/thread/cons/1.cc: Add comments.
+       * testsuite/30_threads/thread/cons/2.cc: Same.
+       * testsuite/30_threads/thread/cons/3.cc: Same.
+       * testsuite/30_threads/thread/cons/4.cc: Same.
+       * testsuite/30_threads/thread/cons/5.cc: Same.
+       * testsuite/30_threads/thread/cons/6.cc: Same.
+       * testsuite/30_threads/thread/cons/7.cc: Same.
+       * testsuite/30_threads/thread/cons/8.cc: Same.
+
+       * testsuite/30_threads/thread/cons/9.cc: New.
+       * testsuite/30_threads/thread/cons/moveable.cc: New.
+
+       * src/condition_variable.cc: Clean up whitespace.
+       * include/std/condition_variable: Same.
+
 2009-02-09  Benjamin Kosnik  <bkoz@redhat.com>
 
        * include/std/condition_variable (condition_variable): Remove
index 0c28b18fb6dcb3a75077e877a37a327f8f63b53a..c26c213e6188d08ec5686104f9da93b6dad84aa8 100644 (file)
@@ -45,7 +45,7 @@
 
 #if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
 
-namespace std 
+namespace std
 {
   /// condition_variable
   class condition_variable
@@ -63,25 +63,25 @@ namespace std
     condition_variable(const condition_variable&) = delete;
     condition_variable& operator=(const condition_variable&) = delete;
 
-    void 
+    void
     notify_one();
 
-    void 
+    void
     notify_all();
 
-    void 
+    void
     wait(unique_lock<mutex>& __lock);
 
     template<typename _Predicate>
-      void 
+      void
       wait(unique_lock<mutex>& __lock, _Predicate __p)
       {
        while (!__p())
          wait(__lock);
       }
-  
+
     template<typename _Duration>
-      bool 
+      bool
       wait_until(unique_lock<mutex>& __lock,
                 const chrono::time_point<__clock_t, _Duration>& __atime)
       { return __wait_until_impl(__lock, __atime); }
@@ -94,7 +94,7 @@ namespace std
        // DR 887 - Sync unknown clock to known clock.
        typename _Clock::time_point __c_entry = _Clock::now();
        __clock_t::time_point __s_entry = __clock_t::now();
-       chrono::nanoseconds __delta = __atime - __c_entry;      
+       chrono::nanoseconds __delta = __atime - __c_entry;
        __clock_t::time_point __s_atime = __s_entry + __delta;
 
        return __wait_until_impl(__lock, __s_atime);
@@ -109,7 +109,7 @@ namespace std
        while (!__p())
          if (!wait_until(__lock, __atime))
            return __p();
-       
+
        return true;
       }
 
@@ -126,8 +126,8 @@ namespace std
               _Predicate __p)
       { return wait_until(__lock, __clock_t::now() + __rtime, std::move(__p)); }
 
-    native_handle_type 
-    native_handle() 
+    native_handle_type
+    native_handle()
     { return &_M_cond; }
 
   private:
@@ -137,21 +137,21 @@ namespace std
                        const chrono::time_point<_Clock, _Duration>& __atime)
       {
        chrono::time_point<__clock_t, chrono::seconds> __s =
-          chrono::time_point_cast<chrono::seconds>(__atime);
-       
+         chrono::time_point_cast<chrono::seconds>(__atime);
+
        chrono::nanoseconds __ns =
-          chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
-       
-        __gthread_time_t __ts =
-          {
-            static_cast<std::time_t>(__s.time_since_epoch().count()),
-            static_cast<long>(__ns.count())
-          };
-       
-        __gthread_cond_timedwait(&_M_cond, __lock.mutex()->native_handle(),
-                                 &__ts);
-       
-        return _Clock::now() < __atime;
+         chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
+
+       __gthread_time_t __ts =
+         {
+           static_cast<std::time_t>(__s.time_since_epoch().count()),
+           static_cast<long>(__ns.count())
+         };
+
+       __gthread_cond_timedwait(&_M_cond, __lock.mutex()->native_handle(),
+                                &__ts);
+
+       return _Clock::now() < __atime;
       }
   };
 
@@ -167,36 +167,36 @@ namespace std
 
     condition_variable_any();
     ~condition_variable_any();
-    
+
     condition_variable_any(const condition_variable_any&) = delete;
     condition_variable_any& operator=(const condition_variable_any&) = delete;
 
-    void 
+    void
     notify_one();
 
-    void 
+    void
     notify_all();
 
     template<typename _Lock>
-      void 
+      void
       wait(_Lock& __lock);
 
     template<typename _Lock, typename _Predicate>
-      void 
+      void
       wait(_Lock& __lock, _Predicate __p);
 
     template<typename _Lock, typename _Clock, typename _Duration>
-      bool 
+      bool
       wait_until(_Lock& __lock,
                 const chrono::time_point<_Clock, _Duration>& __atime);
 
-    template<typename _Lock, typename _Clock, 
+    template<typename _Lock, typename _Clock,
             typename _Duration, typename _Predicate>
-      bool 
+      bool
       wait_until(_Lock& __lock,
                 const chrono::time_point<_Clock, _Duration>& __atime,
                 _Predicate __p);
-    
+
     template<typename _Lock, typename _Rep, typename _Period>
       bool
       wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __rtime);
@@ -204,10 +204,10 @@ namespace std
     template<typename _Lock, typename _Rep,
             typename _Period, typename _Predicate>
       bool
-      wait_for(_Lock& __lock, 
+      wait_for(_Lock& __lock,
               const chrono::duration<_Rep, _Period>& __rtime, _Predicate __p);
 
-    native_handle_type 
+    native_handle_type
     native_handle()
     { return &_M_cond; }
   };
index c916bf0c2052e08ba3af5da45cba7624a4039b28..c36881bc827509e974d832cf14b38f5331fa38c5 100644 (file)
@@ -59,12 +59,12 @@ namespace std
     int __e = __gthread_cond_wait(&_M_cond, __lock.mutex()->native_handle());
 
     if (__e)
-      __throw_system_error(__e);    
+      __throw_system_error(__e);
   }
-  
-  void 
+
+  void
   condition_variable::notify_one()
-  { 
+  {
     int __e = __gthread_cond_signal(&_M_cond);
 
     // XXX not in spec
@@ -73,9 +73,9 @@ namespace std
       __throw_system_error(__e);
   }
 
-  void 
+  void
   condition_variable::notify_all()
-  { 
+  {
     int __e = __gthread_cond_broadcast(&_M_cond);
 
     // XXX not in spec
@@ -96,11 +96,11 @@ namespace std
       __throw_system_error(__e);
 #endif
   }
-  
+
   condition_variable_any::~condition_variable_any()
   {
     __gthread_cond_destroy(&_M_cond);
-  } 
+  }
 }
 
 #endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
index 2dbaccc3c4595668b419bf3aad2b43ec9397962c..93968798b67341cd5dfe0a510e70e569c3b8808e 100644 (file)
@@ -29,6 +29,6 @@
 int main()
 {
   typedef std::condition_variable test_type;
-  __gnu_test::compare_type_to_native_type_sizes<test_type>();
+  __gnu_test::compare_type_to_native_type<test_type>();
   return 0;
 }
index 9d388963b9bf02c74da305c2b30b2359004b279c..2544291ab13c33aec17ee48030b1eb0a11f19310 100644 (file)
@@ -29,6 +29,6 @@
 int main()
 {
   typedef std::condition_variable_any test_type;
-  __gnu_test::compare_type_to_native_type_sizes<test_type>();
+  __gnu_test::compare_type_to_native_type<test_type>();
   return 0;
 }
index b293008b97520b60fe06a367eea5807cfa2bfaa2..cda0816cfbebe399fbb5f50206ca5e1cf0ec1e8a 100644 (file)
@@ -29,6 +29,6 @@
 int main()
 {
   typedef std::mutex test_type;
-  __gnu_test::compare_type_to_native_type_sizes<test_type>();
+  __gnu_test::compare_type_to_native_type<test_type>();
   return 0;
 }
index 6d58c1ef90ef8ff1c8a4567d3c8e41b66bde9740..8ee1f3895c1387466d5bde46b29b5d4a142366f1 100644 (file)
@@ -29,6 +29,6 @@
 int main()
 {
   typedef std::recursive_mutex test_type;
-  __gnu_test::compare_type_to_native_type_sizes<test_type>();
+  __gnu_test::compare_type_to_native_type<test_type>();
   return 0;
 }
index b51bdf27a1bb553dda2ea4235f8adbb760f7a67c..be9dc53e83f7fd233fd0ae3cfaad90331de4a71d 100644 (file)
@@ -29,6 +29,6 @@
 int main()
 {
   typedef std::recursive_timed_mutex test_type;
-  __gnu_test::compare_type_to_native_type_sizes<test_type>();
+  __gnu_test::compare_type_to_native_type<test_type>();
   return 0;
 }
index a631e7eabf8ea2fd4a7b28bc23da318e03a6f39a..9f5d83fb2c712d2aec1aaa1284119150882659d0 100644 (file)
@@ -36,6 +36,9 @@
 #include <system_error>
 #include <testsuite_hooks.h>
 
+// thread default cons works
+// thread default cons no throw
+// thread default cons not joinable
 int main()
 {
   bool test __attribute__((unused)) = true;
index e53b088449a10dee64cf2fa683344350ab9d20d1..aeccf79cdb67545c0d9f23bb2085a55d3199ffd3 100644 (file)
@@ -32,7 +32,7 @@
 // invalidate any other reasons why the executable file might be covered by
 // the GNU General Public License.
 
-#include <utility> // std::ref
+#include <functional> // std::ref
 #include <thread>
 #include <system_error>
 #include <testsuite_hooks.h>
@@ -43,19 +43,27 @@ free_function(std::thread::id& id)
   id = std::this_thread::get_id();
 }
 
+// thread::id default cons
+// thread::id copy ctor
+// thread variadic cons, c++ function
+// thread variadic cons joinable
+// thread join
+// thread join postcondition not joinable
+// thread join postcondition function called correctly
+// this_thread::get_id
 void test02()
 {
   bool test __attribute__((unused)) = true;
 
   try
     {
-      std::thread::id t1_id1;
-      std::thread t1(free_function, std::ref(t1_id1));
-      std::thread::id t1_id2 = t1.get_id();
-      VERIFY( t1.joinable() );
-      t1.join();      
-      VERIFY( !t1.joinable() );
-      VERIFY( t1_id1 == t1_id2 );
+      std::thread::id id1;
+      std::thread t(free_function, std::ref(id1));
+      std::thread::id id2 = t.get_id();
+      VERIFY( t.joinable() );
+      t.join();      
+      VERIFY( !t.joinable() );
+      VERIFY( id1 == id2 );
     }
   catch (const std::system_error&)
     {
index 3df7ad050b97548da7ac8c8d9b74d951ea245d1e..54526c603468f1c2f4b6a65af563593caa094f47 100644 (file)
@@ -5,7 +5,7 @@
 // { dg-require-cstdint "" }
 // { dg-require-gthreads "" }
 
-// Copyright (C) 2008 Free Software Foundation, Inc.
+// Copyright (C) 2008, 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
@@ -32,8 +32,7 @@
 // invalidate any other reasons why the executable file might be covered by
 // the GNU General Public License.
 
-#include <functional> // std::unary_function
-#include <utility> // std::ref
+#include <functional> // std::unary_function, std::ref
 #include <thread>
 #include <system_error>
 #include <testsuite_hooks.h>
@@ -55,6 +54,10 @@ struct copyable : public std::unary_function<std::thread::id&, void>
 
 int copyable::copy_count = 0;
 
+// same as 2, but function is copyable function object
+// thread variadic cons not copied when std::ref
+// thread variadic cons copied when not std::ref
+// no errors
 void test03()
 {
   bool test __attribute__((unused)) = true;
index 76fc9ec3e452c08c2a8ea8faa089505ab70cd155..5fdc8c01598012adca9e695c8e34ccb4ebdd26c1 100644 (file)
@@ -5,7 +5,7 @@
 // { dg-require-cstdint "" }
 // { dg-require-gthreads "" }
 
-// Copyright (C) 2008 Free Software Foundation, Inc.
+// Copyright (C) 2008, 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
@@ -32,8 +32,7 @@
 // invalidate any other reasons why the executable file might be covered by
 // the GNU General Public License.
 
-#include <functional> // std::unary_function
-#include <utility> // std::ref, std::cref
+#include <functional> // std::unary_function, std::ref, std::cref
 #include <thread>
 #include <system_error>
 #include <testsuite_hooks.h>
@@ -50,6 +49,12 @@ struct noncopyable : std::unary_function<std::thread::id&, void>
   }
 };
 
+// same as 3, but function is noncopyable function object
+// thread variadic cons not copied when std::ref
+// thread variadic cons copied when not std::ref
+// thread variadic cons not copied when std::cref
+// thread variadic cons copied when not std::cref
+// no errors
 void test03()
 {
   bool test __attribute__((unused)) = true;
index 35ea25abeb1025ffcca0142973718c6900157f63..6250c197f5f05cf428050421ff37e2268e05ae1f 100644 (file)
@@ -32,8 +32,7 @@
 // invalidate any other reasons why the executable file might be covered by
 // the GNU General Public License.
 
-#include <functional> // std::unary_function
-#include <utility> // std::ref
+#include <functional> // std::unary_function, std::ref
 #include <thread>
 #include <system_error>
 #include <testsuite_hooks.h>
index 0a6d7470fa966de9cad5065dbf40cf467bd6ab3d..367d0f603f174b37267e41e6446708cd0b04518d 100644 (file)
@@ -43,6 +43,10 @@ void f()
   f_was_called = true;
 }
 
+// thread non-variadic cons, c++ function
+// thread join
+// thread join postcondition function called correctly
+// no errors
 void test06()
 {
   bool test __attribute__((unused)) = true;
index fafa72ac2779d6a0a56f91fe97d0e0e203f2076a..62690de60b28af14336192bc8d141b9243149dee 100644 (file)
@@ -51,6 +51,7 @@ struct copyable
   }
 };
 
+// same as 6, but function is copyable function object passed by reference
 void test07()
 {
   bool test __attribute__((unused)) = true;
@@ -59,8 +60,8 @@ void test07()
     {
       copyable c;
       copyable& rc = c;
-      std::thread t1(rc);
-      t1.join();
+      std::thread t(rc);
+      t.join();
       VERIFY( functor_was_called );
     }
   catch (const std::system_error&)
index 8c6b2e1f92132fdbc1627a692eab04a2a347f7f9..de8fb873d6c3d3797c1fcd07c8c1278d5cd8e234 100644 (file)
@@ -52,6 +52,7 @@ struct moveable
   }
 };
 
+// same as 6, but function object is movable
 void test08()
 {
   bool test __attribute__((unused)) = true;
@@ -59,8 +60,8 @@ void test08()
   try
     {
       moveable m;
-      std::thread t1(std::move(m));
-      t1.join();
+      std::thread t(std::move(m));
+      t.join();
       VERIFY( functor_was_called );
     }
   catch (const std::system_error&)
index b1103d95f22bc56a575a62511050fcb8a78e3d0b..2af81fb47cf95a58ce23df5301eb29b6ab77ab6a 100644 (file)
@@ -29,7 +29,7 @@
 int main()
 {
   typedef std::thread test_type;
-  // XXX disable at the moment
-  //__gnu_test::compare_type_to_native_type_sizes<test_type>();
+  // XX disable for now
+  //__gnu_test::compare_type_to_native_type<test_type>();
   return 0;
 }
index 7a59d7da30f171365454e72136d5fd052482b0e5..e9debe55e00d1f878aa4861eb551e94152c3a99b 100644 (file)
@@ -29,6 +29,6 @@
 int main()
 {
   typedef std::timed_mutex test_type;
-  __gnu_test::compare_type_to_native_type_sizes<test_type>();
+  __gnu_test::compare_type_to_native_type<test_type>();
   return 0;
 }
index 39dea5ff6069ddd79505db7a10a9a31dfc9d37c5..40002725a9f701890f67e70650158019c042cbfb 100644 (file)
 namespace __gnu_test
 {  
   // Assume _Tp::native_handle_type.
+  // Check C++ to native_handle_type characteristics: size and alignment.
   template<typename _Tp>
     void
-    compare_type_to_native_type_sizes()
+    compare_type_to_native_type()
     {
       typedef _Tp test_type;
-      typedef typename test_type::native_handle_type native_handle_type;
-
-      int st = sizeof(test_type);
 
       // Remove possible pointer type.
-      int snt = sizeof(typename std::remove_pointer<native_handle_type>::type);
-      
-      if (st != snt)
+      typedef typename test_type::native_handle_type native_handle;
+      typedef typename std::remove_pointer<native_handle>::type native_type;
+
+      int st = sizeof(test_type);
+      int snt = sizeof(native_type);      
+      int at = __alignof__(test_type);
+      int ant = __alignof__(native_type);
+      if (st != snt || at != ant)
        {
          std::ostringstream s;
          s << std::endl;
          s << "size of _Tp: " << st << std::endl;
+         s << "alignment of _Tp: " << st << std::endl;
          s << "size of *(_Tp::native_handle_type): " << snt << std::endl;
+         s << "alignment of *(_Tp::native_handle_type): " << snt << std::endl;
          throw std::runtime_error(s.str());
        }
     }