Scarab
v2.4.7
Project 8 C++ Utility Library
library
utility
cancelable.hh
Go to the documentation of this file.
1
/*
2
* cancelable.hh
3
*
4
* Created on: Jan 24, 2016
5
* Author: nsoblath
6
*
7
* Base class for thread-safe asynchronous cancellation
8
*/
9
10
#ifndef SCARAB_CANCELABLE_HH_
11
#define SCARAB_CANCELABLE_HH_
12
13
#include "
scarab_api.hh
"
14
15
#include <atomic>
16
17
namespace
scarab
18
{
19
class
SCARAB_API
cancelable
20
{
21
public
:
22
cancelable
();
23
virtual
~
cancelable
();
24
26
void
cancel();
27
29
void
reset_cancel();
30
32
bool
is_canceled()
const
;
33
34
private
:
35
virtual
void
do_cancellation();
36
virtual
void
do_reset_cancellation();
37
38
protected
:
39
std::atomic< bool >
f_canceled
;
40
};
41
42
inline
void
cancelable::cancel
()
43
{
44
if
( f_canceled.load() )
return
;
45
f_canceled.store(
true
);
46
this->do_cancellation();
47
}
48
49
inline
void
cancelable::reset_cancel
()
50
{
51
if
( ! f_canceled.load() )
return
;
52
f_canceled.store(
false
);
53
this->do_reset_cancellation();
54
}
55
56
inline
bool
cancelable::is_canceled
()
const
57
{
58
return
f_canceled.load();
59
}
60
61
}
/* namespace scarab */
62
63
#endif
/* SCARAB_CANCELABLE_HH_ */
SCARAB_API
#define SCARAB_API
Definition:
scarab_api.hh:24
scarab
Definition:
authentication.cc:18
scarab_api.hh
scarab::cancelable::is_canceled
bool is_canceled() const
check canceled state
Definition:
cancelable.hh:56
scarab::cancelable::reset_cancel
void reset_cancel()
reset to non-canceled state
Definition:
cancelable.hh:49
scarab::cancelable::f_canceled
std::atomic< bool > f_canceled
Definition:
cancelable.hh:39
scarab::cancelable::cancel
void cancel()
asynchronous cancel function
Definition:
cancelable.hh:42
scarab::cancelable
Definition:
cancelable.hh:19
Generated by
1.8.13