forked from xLightsSequencer/xLights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReentrancyCounter.h
37 lines (33 loc) · 999 Bytes
/
ReentrancyCounter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once
/***************************************************************
* This source files comes from the xLights project
* https://www.xlights.org
* https://github.com/smeighan/xLights
* See the github commit history for a record of contributing
* developers.
* Copyright claimed based on commit dates recorded in Github
* License: https://github.com/smeighan/xLights/blob/master/License.txt
**************************************************************/
class ReentrancyCounter
{
int& _ref;
std::recursive_mutex _lock;
public:
ReentrancyCounter(int& ref) : _ref(ref)
{
std::lock_guard<std::recursive_mutex> locker(_lock);
++_ref;
}
virtual ~ReentrancyCounter()
{
std::lock_guard<std::recursive_mutex> locker(_lock);
--_ref;
//wxASSERT(_ref >= 0);
if (_ref < 0) _ref = 0;
}
bool SoleReference()
{
std::lock_guard<std::recursive_mutex> locker(_lock);
return _ref == 1;
}
};