25 #include <boost/thread.hpp> 28 #if FOLLY_LOCK_TRAITS_HAVE_TIMED_MUTEXES 34 template <
class Rep, std::
intmax_t Num, std::
intmax_t Denom>
35 boost::chrono::duration<Rep, boost::ratio<Num, Denom>> toBoostDuration(
36 const std::chrono::duration<Rep, std::ratio<Num, Denom>>& d) {
37 return boost::chrono::duration<Rep, boost::ratio<Num, Denom>>(d.count());
45 struct LockTraits<boost::shared_mutex>
46 :
public LockTraitsBase<boost::shared_mutex> {
47 static constexpr
bool is_shared =
true;
48 static constexpr
bool is_timed =
true;
50 template <
class Rep,
class Period>
51 static bool try_lock_for(
52 boost::shared_mutex&
mutex,
53 const std::chrono::duration<Rep, Period>&
timeout) {
54 return mutex.try_lock_for(detail::toBoostDuration(timeout));
57 template <
class Rep,
class Period>
58 static bool try_lock_shared_for(
59 boost::shared_mutex& mutex,
60 const std::chrono::duration<Rep, Period>& timeout) {
61 return mutex.try_lock_shared_for(detail::toBoostDuration(timeout));
69 struct LockTraits<boost::timed_mutex>
70 :
public LockTraitsBase<boost::timed_mutex> {
71 static constexpr
bool is_shared =
false;
72 static constexpr
bool is_timed =
true;
74 template <
class Rep,
class Period>
75 static bool try_lock_for(
76 boost::timed_mutex& mutex,
77 const std::chrono::duration<Rep, Period>& timeout) {
78 return mutex.try_lock_for(detail::toBoostDuration(timeout));
86 struct LockTraits<boost::recursive_timed_mutex>
87 :
public LockTraitsBase<boost::recursive_timed_mutex> {
88 static constexpr
bool is_shared =
false;
89 static constexpr
bool is_timed =
true;
91 template <
class Rep,
class Period>
92 static bool try_lock_for(
93 boost::recursive_timed_mutex& mutex,
94 const std::chrono::duration<Rep, Period>& timeout) {
95 return mutex.try_lock_for(detail::toBoostDuration(timeout));
100 #endif // FOLLY_LOCK_TRAITS_HAVE_TIMED_MUTEXES
—— Concurrent Priority Queue Implementation ——