mavtables  0.2.1
MAVLink router and firewall.
Public Member Functions | List of all members
RecursionGuard Class Reference

#include <RecursionGuard.hpp>

Collaboration diagram for RecursionGuard:
Collaboration graph

Public Member Functions

 RecursionGuard (RecursionData &data)
 
 ~RecursionGuard ()
 

Detailed Description

Guard against recursion.

A recursion guard is an RAII (Resource Acquisition Is Initialization) data structure used to raise an error upon recursion. The constructor marks a RecursionData structure, acquiring ownership of the containing function (within the given thread). Recursion guards treat calls from different threads separately, therefore, it will not guard against re-entrantcy.

An example of how to use this is:

int a_function(int value)
{
// shared data between calls
static RecursionData rdata;
// take ownership of the call
RecursionGuard rguard(rdata);
return b_function(value);
// the recursion guard is released upon destruction of rguard
}

If b_function, or any function it calls, ever calls a_function then this will throw RecursionError. However, if multiple threads call a_function (possibly at the same time) but b_function does not call a_function then no error will be thrown.

See also
RecursionData
RecursionError

Definition at line 60 of file RecursionGuard.hpp.

Constructor & Destructor Documentation

◆ RecursionGuard()

RecursionGuard::RecursionGuard ( RecursionData data)

Construct a RecursionGuard.

This marks the given RecursionData structure, ensuring it cannot be used to construct another guard without raising a RecursionError.

Parameters
dataThe object used to prevent recursion.
Exceptions
RecursionErrorif the given data structure has already been marked by a RecursionGuard instance that is still in scope.

Definition at line 35 of file RecursionGuard.cpp.

References mavlink::id().

Here is the call graph for this function:

◆ ~RecursionGuard()

RecursionGuard::~RecursionGuard ( )

Release the lock on the contain RecursionData.

This allows the function to be called again without error.

Definition at line 52 of file RecursionGuard.cpp.


The documentation for this class was generated from the following files: