QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
AutoSuspendGuard.h
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4
5namespace QGC {
6
12{
13public:
14 explicit AutoSuspendGuard(std::atomic<bool>& flag) : _flag(&flag)
15 {
16 _flag->store(true, std::memory_order_release);
17 }
18
19 AutoSuspendGuard(AutoSuspendGuard&& other) noexcept : _flag(other._flag) { other._flag = nullptr; }
20
22 {
23 if (this != &other) {
24 release();
25 _flag = other._flag;
26 other._flag = nullptr;
27 }
28 return *this;
29 }
30
33
34 ~AutoSuspendGuard() { release(); }
35
36private:
37 void release() noexcept
38 {
39 if (_flag) {
40 _flag->store(false, std::memory_order_release);
41 _flag = nullptr;
42 }
43 }
44
45 std::atomic<bool>* _flag;
46};
47
48} // namespace QGC
RAII guard for an atomic suspend flag: sets on construction, clears on destruction.
AutoSuspendGuard(const AutoSuspendGuard &)=delete
AutoSuspendGuard & operator=(const AutoSuspendGuard &)=delete
AutoSuspendGuard(AutoSuspendGuard &&other) noexcept
AutoSuspendGuard & operator=(AutoSuspendGuard &&other) noexcept
AutoSuspendGuard(std::atomic< bool > &flag)