mavtables  0.2.1
MAVLink router and firewall.
RecursionData.hpp
Go to the documentation of this file.
1 // MAVLink router and firewall.
2 // Copyright (C) 2018 Michael R. Shannon <mrshannon.aerospace@gmail.com>
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 
18 #ifndef RECURSIONDATA_HPP_
19 #define RECURSIONDATA_HPP_
20 
21 
22 #include <mutex>
23 #include <set>
24 #include <thread>
25 
26 
27 /** A data structure used by \ref RecursionGuard to detect unwanted recursion.
28  *
29  * \note While \ref RecursionData supports copy and move semantics both with
30  * constructors and assignment operator, a recursion data structure should
31  * never change instance. One way to deal with this would have been to
32  * delete these operators but this would force users to manually implement
33  * copy and move semantics for their classes. Therefore, \ref
34  * RecursionData will always make a new data structure on copy, move or
35  * assignment, allowing default copy and move constructors/assignment
36  * operators to be created for classes containing a \ref RecursionData
37  * instance.
38  */
40 {
41  friend class RecursionGuard;
42 
43  public:
44  RecursionData() = default;
46  {
47  (void)other;
48  }
50  {
51  (void)other;
52  }
54  {
55  (void)other;
56  calling_threads_.clear();
57  return *this;
58  }
60  {
61  (void)other;
62  calling_threads_.clear();
63  return *this;
64  }
65 
66  private:
67  std::set<std::thread::id> calling_threads_;
68  std::mutex mutex_;
69 };
70 
71 
72 #endif // RECURSIONDATA_HPP_
RecursionData()=default
RecursionData(RecursionData &&other)
RecursionData & operator=(RecursionData &&other)
RecursionData(const RecursionData &other)
RecursionData & operator=(const RecursionData &other)