1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2012-2013. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_INTERPROCESS_SYNC_DETAIL_COMMON_ALGORITHMS_HPP
12 #define BOOST_INTERPROCESS_SYNC_DETAIL_COMMON_ALGORITHMS_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/interprocess/detail/config_begin.hpp>
23 #include <boost/interprocess/detail/workaround.hpp>
25 #include <boost/interprocess/sync/spin/wait.hpp>
26 #include <boost/interprocess/detail/timed_utils.hpp>
29 namespace interprocess {
32 template<class MutexType, class TimePoint>
33 bool try_based_timed_lock(MutexType &m, const TimePoint &abs_time)
36 if(is_pos_infinity(abs_time)){
40 //Always try to lock to achieve POSIX guarantees:
41 // "Under no circumstance shall the function fail with a timeout if the mutex
42 // can be locked immediately. The validity of the abs_timeout parameter need not
43 // be checked if the mutex can be locked immediately."
44 else if(m.try_lock()){
49 while(microsec_clock<TimePoint>::universal_time() < abs_time){
59 template<class MutexType>
60 void try_based_lock(MutexType &m)
76 template<class MutexType>
77 void timeout_when_locking_aware_lock(MutexType &m)
79 #ifdef BOOST_INTERPROCESS_ENABLE_TIMEOUT_WHEN_LOCKING
80 if (!m.timed_lock(microsec_clock<ustime>::universal_time()
81 + usduration_milliseconds(BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS)))
83 throw interprocess_exception(timeout_when_locking_error
84 , "Interprocess mutex timeout when locking. Possible deadlock: "
85 "owner died without unlocking?");
92 } //namespace ipcdetail
93 } //namespace interprocess
96 #include <boost/interprocess/detail/config_end.hpp>
98 #endif //BOOST_INTERPROCESS_SYNC_DETAIL_COMMON_ALGORITHMS_HPP