rclcpp  master
C++ ROS Client Library API
write_preferring_read_write_lock.hpp
Go to the documentation of this file.
1 // Copyright 2020 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCLCPP__WAIT_SET_POLICIES__DETAIL__WRITE_PREFERRING_READ_WRITE_LOCK_HPP_
16 #define RCLCPP__WAIT_SET_POLICIES__DETAIL__WRITE_PREFERRING_READ_WRITE_LOCK_HPP_
17 
18 #include <condition_variable>
19 #include <functional>
20 #include <mutex>
21 
23 
24 namespace rclcpp
25 {
26 namespace wait_set_policies
27 {
28 namespace detail
29 {
30 
32 
171 {
172 public:
174  explicit WritePreferringReadWriteLock(std::function<void()> enter_waiting_function = nullptr);
175 
177 
181  {
182 public:
183  void
184  lock();
185 
186  void
187  unlock();
188 
189 protected:
190  explicit ReadMutex(WritePreferringReadWriteLock & parent_lock);
191 
193 
195  };
196 
198 
202  {
203 public:
204  void
205  lock();
206 
207  void
208  unlock();
209 
210 protected:
211  explicit WriteMutex(WritePreferringReadWriteLock & parent_lock);
212 
214 
216  };
217 
220  ReadMutex &
221  get_read_mutex();
222 
225  WriteMutex &
226  get_write_mutex();
227 
228 protected:
229  bool reader_active_ = false;
231  bool writer_active_ = false;
237 };
238 
239 } // namespace detail
240 } // namespace wait_set_policies
241 } // namespace rclcpp
242 
243 #endif // RCLCPP__WAIT_SET_POLICIES__DETAIL__WRITE_PREFERRING_READ_WRITE_LOCK_HPP_
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::ReadMutex::WritePreferringReadWriteLock
friend WritePreferringReadWriteLock
Definition: write_preferring_read_write_lock.hpp:194
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::write_mutex_
WriteMutex write_mutex_
Definition: write_preferring_read_write_lock.hpp:235
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::get_read_mutex
ReadMutex & get_read_mutex()
Return read mutex which can be used with standard constructs like std::lock_guard.
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::condition_variable_
std::condition_variable condition_variable_
Definition: write_preferring_read_write_lock.hpp:233
std::function
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::number_of_writers_waiting_
std::size_t number_of_writers_waiting_
Definition: write_preferring_read_write_lock.hpp:230
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::ReadMutex
Read mutex for the WritePreferringReadWriteLock.
Definition: write_preferring_read_write_lock.hpp:180
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::WritePreferringReadWriteLock
WritePreferringReadWriteLock(std::function< void()> enter_waiting_function=nullptr)
RCLCPP_PUBLIC
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::get_write_mutex
WriteMutex & get_write_mutex()
Return write mutex which can be used with standard constructs like std::lock_guard.
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::writer_active_
bool writer_active_
Definition: write_preferring_read_write_lock.hpp:231
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::enter_waiting_function_
std::function< void()> enter_waiting_function_
Definition: write_preferring_read_write_lock.hpp:236
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::WriteMutex
Write mutex for the WritePreferringReadWriteLock.
Definition: write_preferring_read_write_lock.hpp:201
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::reader_active_
bool reader_active_
Definition: write_preferring_read_write_lock.hpp:229
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::ReadMutex::parent_lock_
WritePreferringReadWriteLock & parent_lock_
Definition: write_preferring_read_write_lock.hpp:192
visibility_control.hpp
std::condition_variable
std::mutex
std::size_t
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::WriteMutex::parent_lock_
WritePreferringReadWriteLock & parent_lock_
Definition: write_preferring_read_write_lock.hpp:213
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::WriteMutex::WritePreferringReadWriteLock
friend WritePreferringReadWriteLock
Definition: write_preferring_read_write_lock.hpp:215
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::read_mutex_
ReadMutex read_mutex_
Definition: write_preferring_read_write_lock.hpp:234
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock
Writer-perferring read-write lock.
Definition: write_preferring_read_write_lock.hpp:170
rclcpp::wait_set_policies::detail::WritePreferringReadWriteLock::mutex_
std::mutex mutex_
Definition: write_preferring_read_write_lock.hpp:232