This is an automated email from the ASF dual-hosted git repository.
twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new fd2e317b chore: add move assign operator for MultiLockGuard (#2693)
fd2e317b is described below
commit fd2e317b047b5a6233070ff097af2d96e8f616ef
Author: Twice <[email protected]>
AuthorDate: Sun Dec 15 13:17:41 2024 +0800
chore: add move assign operator for MultiLockGuard (#2693)
Signed-off-by: PragmaTwice <[email protected]>
---
src/common/lock_manager.h | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/common/lock_manager.h b/src/common/lock_manager.h
index 782d6c82..985d5efc 100644
--- a/src/common/lock_manager.h
+++ b/src/common/lock_manager.h
@@ -23,6 +23,7 @@
#include <rocksdb/db.h>
#include <functional>
+#include <memory>
#include <mutex>
#include <set>
#include <string>
@@ -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_;