123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- #ifndef _CRITSEC_H
- #define _CRITSEC_H
- #ifdef _WIN32
- #include <windows.h>
- #elif defined(__APPLE__)
- #include <CoreServices/CoreServices.h>
- #endif
- #include <bfc/common.h>
- #include <bfc/bfc_assert.h>
- class CriticalSection {
- public:
- CriticalSection();
- virtual ~CriticalSection();
- void enter();
- void leave();
- void inout();
- private:
- #ifdef ASSERTS_ENABLED
- int within;
- #endif
- #ifdef _WIN32
- CRITICAL_SECTION cs;
- #elif defined(__APPLE__)
- MPCriticalRegionID cr;
- #endif
-
- };
- class InCriticalSection {
- public:
- InCriticalSection(CriticalSection *cs) : m_cs(cs) { m_cs->enter(); }
- InCriticalSection(CriticalSection &cs) : m_cs(&cs) { m_cs->enter(); }
- ~InCriticalSection() { m_cs->leave(); }
- private:
- CriticalSection *m_cs;
- };
- #define _INCRITICALSECTION(id, x) InCriticalSection __I_C_S__##id(x)
- #define INCRITICALSECTION(x) _INCRITICALSECTION(__LINE__, x)
- #endif
|