1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Copyright (C) 2011 Vicente J. Botet Escriba
12 // Distributed under the Boost Software License, Version 1.0. (See accompanying
13 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
15 // <boost/thread/locks.hpp>
17 // template <class Mutex> class unique_lock;
19 // template <class Clock, class Duration>
20 // bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
22 #include <boost/thread/lock_types.hpp>
23 #include <boost/thread/mutex.hpp>
24 #include <boost/detail/lightweight_test.hpp>
26 #if defined BOOST_THREAD_USES_CHRONO
29 bool try_lock_until_called = false;
33 template <class Clock, class Duration>
34 bool try_lock_until(const boost::chrono::time_point<Clock, Duration>& abs_time)
36 typedef boost::chrono::milliseconds ms;
37 BOOST_TEST(Clock::now() - abs_time < ms(5));
38 try_lock_until_called = !try_lock_until_called;
39 return try_lock_until_called;
50 typedef boost::chrono::steady_clock Clock;
51 boost::unique_lock<mutex> lk(m, boost::defer_lock);
52 BOOST_TEST(lk.try_lock_until(Clock::now()) == true);
53 BOOST_TEST(try_lock_until_called == true);
54 BOOST_TEST(lk.owns_lock() == true);
57 lk.try_lock_until(Clock::now());
60 catch (boost::system::system_error& e)
62 BOOST_TEST(e.code().value() == boost::system::errc::resource_deadlock_would_occur);
65 BOOST_TEST(lk.try_lock_until(Clock::now()) == false);
66 BOOST_TEST(try_lock_until_called == false);
67 BOOST_TEST(lk.owns_lock() == false);
71 lk.try_lock_until(Clock::now());
74 catch (boost::system::system_error& e)
76 BOOST_TEST(e.code().value() == boost::system::errc::operation_not_permitted);
78 return boost::report_errors();
82 #error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"