2 * Copyright 2016 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * This file contains LockTraits specializations for boost mutex types.
20 * These need to be specialized simply due to the fact that the timed
21 * methods take boost::chrono arguments instead of std::chrono.
25 #include <folly/LockTraits.h>
27 #if FOLLY_LOCK_TRAITS_HAVE_TIMED_MUTEXES
29 #include <boost/thread.hpp>
34 * LockTraits specialization for boost::shared_mutex
37 struct LockTraits<boost::shared_mutex>
38 : public folly::detail::LockTraitsSharedBase<boost::shared_mutex> {
39 static constexpr bool is_shared = true;
40 static constexpr bool is_timed = true;
42 static bool try_lock_for(
43 boost::shared_mutex& mutex,
44 std::chrono::milliseconds timeout) {
45 // Convert the std::chrono argument to boost::chrono
46 return mutex.try_lock_for(boost::chrono::milliseconds(timeout.count()));
49 static bool try_lock_shared_for(
50 boost::shared_mutex& mutex,
51 std::chrono::milliseconds timeout) {
52 // Convert the std::chrono argument to boost::chrono
53 return mutex.try_lock_shared_for(
54 boost::chrono::milliseconds(timeout.count()));
59 * LockTraits specialization for boost::timed_mutex
62 struct LockTraits<boost::timed_mutex>
63 : public folly::detail::LockTraitsUniqueBase<boost::timed_mutex> {
64 static constexpr bool is_shared = false;
65 static constexpr bool is_timed = true;
67 static bool try_lock_for(
68 boost::timed_mutex& mutex,
69 std::chrono::milliseconds timeout) {
70 // Convert the std::chrono argument to boost::chrono
71 return mutex.try_lock_for(boost::chrono::milliseconds(timeout.count()));
76 * LockTraits specialization for boost::recursive_timed_mutex
79 struct LockTraits<boost::recursive_timed_mutex>
80 : public folly::detail::LockTraitsUniqueBase<boost::recursive_timed_mutex> {
81 static constexpr bool is_shared = false;
82 static constexpr bool is_timed = true;
84 static bool try_lock_for(
85 boost::recursive_timed_mutex& mutex,
86 std::chrono::milliseconds timeout) {
87 // Convert the std::chrono argument to boost::chrono
88 return mutex.try_lock_for(boost::chrono::milliseconds(timeout.count()));
93 #endif // FOLLY_LOCK_TRAITS_HAVE_TIMED_MUTEXES