15a83710eSEric Fiselier //===----------------------------------------------------------------------===// 25a83710eSEric Fiselier // 357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65a83710eSEric Fiselier // 75a83710eSEric Fiselier //===----------------------------------------------------------------------===// 85a83710eSEric Fiselier // 9*a7f9895cSLouis Dionne // UNSUPPORTED: no-threads 10f03ac381SLouis Dionne // ALLOW_RETRIES: 2 11389da901SEric Fiselier 125a83710eSEric Fiselier // <mutex> 135a83710eSEric Fiselier 145a83710eSEric Fiselier // template <class Mutex> class unique_lock; 155a83710eSEric Fiselier 165a83710eSEric Fiselier // explicit unique_lock(mutex_type& m); 175a83710eSEric Fiselier 186015dd11SMarshall Clow // template<class _Mutex> unique_lock(unique_lock<_Mutex>) 196015dd11SMarshall Clow // -> unique_lock<_Mutex>; // C++17 206015dd11SMarshall Clow 215a83710eSEric Fiselier #include <mutex> 225a83710eSEric Fiselier #include <thread> 235a83710eSEric Fiselier #include <cstdlib> 245a83710eSEric Fiselier #include <cassert> 255a83710eSEric Fiselier 2656462801SLouis Dionne #include "make_test_thread.h" 276015dd11SMarshall Clow #include "test_macros.h" 286015dd11SMarshall Clow 295a83710eSEric Fiselier std::mutex m; 305a83710eSEric Fiselier 315a83710eSEric Fiselier typedef std::chrono::system_clock Clock; 325a83710eSEric Fiselier typedef Clock::time_point time_point; 335a83710eSEric Fiselier typedef Clock::duration duration; 345a83710eSEric Fiselier typedef std::chrono::milliseconds ms; 355a83710eSEric Fiselier typedef std::chrono::nanoseconds ns; 365a83710eSEric Fiselier f()375a83710eSEric Fiseliervoid f() 385a83710eSEric Fiselier { 395a83710eSEric Fiselier time_point t0 = Clock::now(); 405a83710eSEric Fiselier time_point t1; 415a83710eSEric Fiselier { 425a83710eSEric Fiselier std::unique_lock<std::mutex> ul(m); 435a83710eSEric Fiselier t1 = Clock::now(); 445a83710eSEric Fiselier } 455a83710eSEric Fiselier ns d = t1 - t0 - ms(250); 465a83710eSEric Fiselier assert(d < ms(50)); // within 50ms 475a83710eSEric Fiselier } 485a83710eSEric Fiselier main(int,char **)492df59c50SJF Bastienint main(int, char**) 505a83710eSEric Fiselier { 515a83710eSEric Fiselier m.lock(); 5256462801SLouis Dionne std::thread t = support::make_test_thread(f); 535a83710eSEric Fiselier std::this_thread::sleep_for(ms(250)); 545a83710eSEric Fiselier m.unlock(); 555a83710eSEric Fiselier t.join(); 566015dd11SMarshall Clow 5701666904SLouis Dionne #if TEST_STD_VER >= 17 586015dd11SMarshall Clow std::unique_lock ul(m); 596015dd11SMarshall Clow static_assert((std::is_same<decltype(ul), std::unique_lock<decltype(m)>>::value), "" ); 606015dd11SMarshall Clow #endif 612df59c50SJF Bastien 622df59c50SJF Bastien return 0; 635a83710eSEric Fiselier } 64