| 1 | #include "ActionLock.h" |
|---|---|
| 2 | #include <Common/ActionBlocker.h> |
| 3 | |
| 4 | |
| 5 | namespace DB |
| 6 | { |
| 7 | |
| 8 | ActionLock::ActionLock(const ActionBlocker & blocker) : counter_ptr(blocker.counter) |
| 9 | { |
| 10 | if (auto counter = counter_ptr.lock()) |
| 11 | ++(*counter); |
| 12 | } |
| 13 | |
| 14 | ActionLock::ActionLock(ActionLock && other) |
| 15 | { |
| 16 | *this = std::move(other); |
| 17 | } |
| 18 | |
| 19 | ActionLock & ActionLock::operator=(ActionLock && other) |
| 20 | { |
| 21 | auto lock_lhs = this->counter_ptr.lock(); |
| 22 | |
| 23 | counter_ptr = std::move(other.counter_ptr); |
| 24 | /// After move other.counter_ptr still points to counter, reset it explicitly |
| 25 | other.counter_ptr.reset(); |
| 26 | |
| 27 | if (lock_lhs) |
| 28 | --(*lock_lhs); |
| 29 | |
| 30 | return *this; |
| 31 | } |
| 32 | |
| 33 | } |
| 34 |