Skip to content

Commit

Permalink
chore: add move assign operator for MultiLockGuard (#2693)
Browse files Browse the repository at this point in the history
Signed-off-by: PragmaTwice <twice@apache.org>
  • Loading branch information
PragmaTwice authored Dec 15, 2024
1 parent 64de844 commit fd2e317
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/common/lock_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <rocksdb/db.h>

#include <functional>
#include <memory>
#include <mutex>
#include <set>
#include <string>
Expand Down Expand Up @@ -125,7 +126,14 @@ class MultiLockGuard {
MultiLockGuard(const MultiLockGuard &) = delete;
MultiLockGuard &operator=(const MultiLockGuard &) = delete;

MultiLockGuard(MultiLockGuard &&guard) : locks_(std::move(guard.locks_)) {}
MultiLockGuard(MultiLockGuard &&guard) : locks_(std::move(guard.locks_)) { guard.locks_.clear(); }
MultiLockGuard &operator=(MultiLockGuard &&other) noexcept {
if (this != &other) {
std::destroy_at(this);
new (this) MultiLockGuard(std::move(other));
}
return *this;
}

private:
std::vector<std::mutex *> locks_;
Expand Down

0 comments on commit fd2e317

Please sign in to comment.