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
5
namespace
QGC
{
6
11
class
AutoSuspendGuard
12
{
13
public
:
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
21
AutoSuspendGuard
&
operator=
(
AutoSuspendGuard
&& other)
noexcept
22
{
23
if
(
this
!= &other) {
24
release();
25
_flag = other._flag;
26
other._flag =
nullptr
;
27
}
28
return
*
this
;
29
}
30
31
AutoSuspendGuard
(
const
AutoSuspendGuard
&) =
delete
;
32
AutoSuspendGuard
&
operator=
(
const
AutoSuspendGuard
&) =
delete
;
33
34
~AutoSuspendGuard
() { release(); }
35
36
private
:
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
QGC::AutoSuspendGuard::AutoSuspendGuard
AutoSuspendGuard(const AutoSuspendGuard &)=delete
QGC::AutoSuspendGuard::operator=
AutoSuspendGuard & operator=(const AutoSuspendGuard &)=delete
QGC::AutoSuspendGuard::AutoSuspendGuard
AutoSuspendGuard(AutoSuspendGuard &&other) noexcept
Definition
AutoSuspendGuard.h:19
QGC::AutoSuspendGuard::~AutoSuspendGuard
~AutoSuspendGuard()
Definition
AutoSuspendGuard.h:34
QGC::AutoSuspendGuard::operator=
AutoSuspendGuard & operator=(AutoSuspendGuard &&other) noexcept
Definition
AutoSuspendGuard.h:21
QGC::AutoSuspendGuard::AutoSuspendGuard
AutoSuspendGuard(std::atomic< bool > &flag)
Definition
AutoSuspendGuard.h:14
QGC
Definition
AppMessages.cc:7
src
Utilities
Concurrency
AutoSuspendGuard.h
Generated by
1.15.0