[08/11] libstdc++ testsuite: Also test shared_timed_mutex with steady_clock

Message ID 0f07257e35dc18ba8dffc4ae4a80ea123c929c8a.1569660153.git-series.mac@mcrowe.com
State Superseded
Headers show
Series
  • timed_mutex, shared_timed_mutex: Add full steady clock support
Related show

Commit Message

Mike Crowe Sept. 28, 2019, 8:44 a.m.
* testsuite/30_threads/shared_timed_mutex/try_lock/3.cc: Convert
          existing test to templated function so that it can be called with
          both system_clock and steady_clock.
---
 libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock/3.cc | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

-- 
git-series 0.9.1

Patch

diff --git a/libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock/3.cc b/libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock/3.cc
index fd21033..1cf191c 100644
--- a/libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock/3.cc
+++ b/libstdc++-v3/testsuite/30_threads/shared_timed_mutex/try_lock/3.cc
@@ -27,7 +27,8 @@ 
 #include <system_error>
 #include <testsuite_hooks.h>
 
-int main()
+template <typename clock_type>
+void test()
 {
   typedef std::shared_timed_mutex mutex_type;
 
@@ -42,15 +43,15 @@  int main()
           {
             using namespace std::chrono;
             auto timeout = 100ms;
-            auto start = system_clock::now();
+            auto start = clock_type::now();
             b = m.try_lock_for(timeout);
-            auto t = system_clock::now() - start;
+            auto t = clock_type::now() - start;
             VERIFY( !b );
             VERIFY( t >= timeout );
 
-            start = system_clock::now();
+            start = clock_type::now();
             b = m.try_lock_until(start + timeout);
-            t = system_clock::now() - start;
+            t = clock_type::now() - start;
             VERIFY( !b );
             VERIFY( t >= timeout );
           }
@@ -71,3 +72,9 @@  int main()
       VERIFY( false );
     }
 }
+
+int main()
+{
+  test<std::chrono::system_clock>();
+  test<std::chrono::steady_clock>();
+}