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 1147c0eb2bSKamil Rytarowski 125a83710eSEric Fiselier // <mutex> 135a83710eSEric Fiselier 145a83710eSEric Fiselier // class recursive_timed_mutex; 155a83710eSEric Fiselier 165a83710eSEric Fiselier // void lock(); 175a83710eSEric Fiselier 185a83710eSEric Fiselier #include <mutex> 195a83710eSEric Fiselier #include <thread> 205a83710eSEric Fiselier #include <cstdlib> 215a83710eSEric Fiselier #include <cassert> 225a83710eSEric Fiselier 2356462801SLouis Dionne #include "make_test_thread.h" 247fc6a556SMarshall Clow #include "test_macros.h" 257fc6a556SMarshall Clow 265a83710eSEric Fiselier std::recursive_timed_mutex m; 275a83710eSEric Fiselier 285a83710eSEric Fiselier typedef std::chrono::system_clock Clock; 295a83710eSEric Fiselier typedef Clock::time_point time_point; 305a83710eSEric Fiselier typedef Clock::duration duration; 315a83710eSEric Fiselier typedef std::chrono::milliseconds ms; 325a83710eSEric Fiselier typedef std::chrono::nanoseconds ns; 335a83710eSEric Fiselier f()345a83710eSEric Fiseliervoid f() 355a83710eSEric Fiselier { 365a83710eSEric Fiselier time_point t0 = Clock::now(); 375a83710eSEric Fiselier m.lock(); 385a83710eSEric Fiselier time_point t1 = Clock::now(); 395a83710eSEric Fiselier m.lock(); 405a83710eSEric Fiselier m.unlock(); 415a83710eSEric Fiselier m.unlock(); 425a83710eSEric Fiselier ns d = t1 - t0 - ms(250); 435a83710eSEric Fiselier assert(d < ms(50)); // within 50ms 445a83710eSEric Fiselier } 455a83710eSEric Fiselier main(int,char **)462df59c50SJF Bastienint main(int, char**) 475a83710eSEric Fiselier { 485a83710eSEric Fiselier m.lock(); 4956462801SLouis Dionne std::thread t = support::make_test_thread(f); 505a83710eSEric Fiselier std::this_thread::sleep_for(ms(250)); 515a83710eSEric Fiselier m.unlock(); 525a83710eSEric Fiselier t.join(); 532df59c50SJF Bastien 542df59c50SJF Bastien return 0; 555a83710eSEric Fiselier } 56