summaryrefslogtreecommitdiff
path: root/Runtime/Utilities/RecursionLimit.h
blob: 84253350e99a4be8964376a9e19a5988d9194e5a (plain)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef RECURSIONLIMIT_H
#define RECURSIONLIMIT_H

class RecursionLimiter {
public:
	RecursionLimiter (unsigned int *count)
	{
		m_Count = count;
		(*m_Count)++;
	}
	
	~RecursionLimiter ()
	{
		(*m_Count)--;
	}
private:
	unsigned int *m_Count;
};

#define LIMIT_RECURSION(x, retval) static unsigned int reclimit = 0; RecursionLimiter limiter(&reclimit); if (reclimit > x) return retval;


class ReentrancyChecker
{
public:
	ReentrancyChecker( bool* variable )
		: m_Variable(variable)
	{
		if( *m_Variable == false )
		{
			*m_Variable = true;
			m_OK = true;
		}
		else
		{
			m_OK = false;
		}
	}
	~ReentrancyChecker()
	{
		if( m_OK )
		{
			*m_Variable = false;
		}
	}
	bool IsOK() const { return m_OK; }

private:
	bool*	m_Variable;
	bool	m_OK;
};


#endif