1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // UNSUPPORTED: libcpp-has-no-threads 10 // UNSUPPORTED: c++03, c++11 11 12 // shared_timed_mutex was introduced in macosx10.12 13 // UNSUPPORTED: use_system_cxx_lib && x86_64-apple-macosx10.11 14 // UNSUPPORTED: use_system_cxx_lib && x86_64-apple-macosx10.10 15 // UNSUPPORTED: use_system_cxx_lib && x86_64-apple-macosx10.9 16 17 // <shared_mutex> 18 19 // class shared_timed_mutex; 20 21 // void lock(); 22 23 #include <shared_mutex> 24 #include <thread> 25 #include <cstdlib> 26 #include <cassert> 27 28 #include "make_test_thread.h" 29 #include "test_macros.h" 30 31 std::shared_timed_mutex m; 32 33 typedef std::chrono::system_clock Clock; 34 typedef Clock::time_point time_point; 35 typedef Clock::duration duration; 36 typedef std::chrono::milliseconds ms; 37 typedef std::chrono::nanoseconds ns; 38 39 std::atomic<bool> ready(false); 40 time_point start; 41 42 ms WaitTime = ms(250); 43 44 void f() 45 { 46 ready.store(true); 47 m.lock(); 48 time_point t0 = start; 49 time_point t1 = Clock::now(); 50 m.unlock(); 51 assert(t0.time_since_epoch() > ms(0)); 52 assert(t1 - t0 >= WaitTime); 53 } 54 55 int main(int, char**) 56 { 57 m.lock(); 58 std::thread t = support::make_test_thread(f); 59 while (!ready) 60 std::this_thread::yield(); 61 start = Clock::now(); 62 std::this_thread::sleep_for(WaitTime); 63 m.unlock(); 64 t.join(); 65 66 return 0; 67 } 68