16 #define DEFER_CONCAT_(a, b) a ## b 17 #define DEFER_CONCAT(a, b) DEFER_CONCAT_(a,b) 20 #define DEFER_CALL(fn) _ScopeGuard DEFER_CONCAT(__defer__, __LINE__) = [&] ( ) { fn ; }; 24 template<
class Callable>
25 _ScopeGuard(Callable &&fn) : fn_(
std::forward<Callable>(fn)) {}
27 _ScopeGuard(_ScopeGuard &&other) : fn_(
std::move(other.fn_)) {
37 _ScopeGuard(
const _ScopeGuard &) =
delete;
38 void operator=(
const _ScopeGuard &) =
delete;
41 std::function<void()> fn_;
44 #define IF_REENTERED(fn) \ 45 static int DEFER_CONCAT(__reenter_guard_depth__, __LINE__) = 0; \ 46 _ReentrancyGuard DEFER_CONCAT(__reenter_guard__, __LINE__)(DEFER_CONCAT(__reenter_guard_depth__, __LINE__), [&] ( ) { fn ; }); 48 class _ReentrancyGuard {
50 template<
class Callable>
51 _ReentrancyGuard(
int &entered, Callable &&fn) : depth(entered)
57 _ReentrancyGuard(_ReentrancyGuard &&other) : depth(other.depth) { }
64 _ReentrancyGuard(
const _ReentrancyGuard &) =
delete;
65 void operator=(
const _ReentrancyGuard &) =
delete;