Skip to content

Commit c302212

Browse files
authored
Add scoped lock (#2045)
1 parent 5d4933d commit c302212

File tree

1 file changed

+2
-4
lines changed
  • hardware_interface/include/hardware_interface

1 file changed

+2
-4
lines changed

hardware_interface/include/hardware_interface/handle.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ class Handle
158158
private:
159159
void copy(const Handle & other) noexcept
160160
{
161-
std::unique_lock<std::shared_mutex> lock(other.handle_mutex_);
162-
std::unique_lock<std::shared_mutex> lock_this(handle_mutex_);
161+
std::scoped_lock lock(other.handle_mutex_, handle_mutex_);
163162
prefix_name_ = other.prefix_name_;
164163
interface_name_ = other.interface_name_;
165164
handle_name_ = other.handle_name_;
@@ -176,8 +175,7 @@ class Handle
176175

177176
void swap(Handle & first, Handle & second) noexcept
178177
{
179-
std::unique_lock<std::shared_mutex> lock(first.handle_mutex_);
180-
std::unique_lock<std::shared_mutex> lock_this(second.handle_mutex_);
178+
std::scoped_lock lock(first.handle_mutex_, second.handle_mutex_);
181179
std::swap(first.prefix_name_, second.prefix_name_);
182180
std::swap(first.interface_name_, second.interface_name_);
183181
std::swap(first.handle_name_, second.handle_name_);

0 commit comments

Comments
 (0)