diff options
author | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
commit | 15740faf9fe9fe4be08965098bbf2947e096aeeb (patch) | |
tree | a730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/Utilities/RecursionLimit.h |
Diffstat (limited to 'Runtime/Utilities/RecursionLimit.h')
-rw-r--r-- | Runtime/Utilities/RecursionLimit.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Runtime/Utilities/RecursionLimit.h b/Runtime/Utilities/RecursionLimit.h new file mode 100644 index 0000000..8425335 --- /dev/null +++ b/Runtime/Utilities/RecursionLimit.h @@ -0,0 +1,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 |