+class MemoryCriticalSection : public wxCriticalSection
+{
+public:
+ MemoryCriticalSection() {
+ memSectionOk = true;
+ }
+ ~MemoryCriticalSection() {
+ memSectionOk = false;
+ }
+};
+
+class MemoryCriticalSectionLocker
+{
+public:
+ inline MemoryCriticalSectionLocker(wxCriticalSection& critsect)
+ : m_critsect(critsect), m_locked(memSectionOk) { if(m_locked) m_critsect.Enter(); }
+ inline ~MemoryCriticalSectionLocker() { if(m_locked) m_critsect.Leave(); }
+
+private:
+ // no assignment operator nor copy ctor
+ MemoryCriticalSectionLocker(const MemoryCriticalSectionLocker&);
+ MemoryCriticalSectionLocker& operator=(const MemoryCriticalSectionLocker&);
+
+ wxCriticalSection& m_critsect;
+ bool m_locked;
+};
+
+static MemoryCriticalSection memLocker;
+
+#endif // USE_THREADSAFE_MEMORY_ALLOCATION