+// ----------------------------------------------------------------------------
+// Critical section: this is the same as mutex but is only visible to the
+// threads of the same process. For the platforms which don't have native
+// support for critical sections, they're implemented entirely in terms of
+// mutexes
+// ----------------------------------------------------------------------------
+
+// in order to avoid any overhead under !MSW make all wxCriticalSection class
+// functions inline - but this can't be done under MSW
+#if defined(__WXMSW__) || defined(__WXPM__)
+ class WXDLLEXPORT wxCriticalSectionInternal;
+ #define WXCRITICAL_INLINE
+#else // !MSW
+ #define WXCRITICAL_INLINE inline
+#endif // MSW/!MSW
+
+// you should consider wxCriticalSectionLocker whenever possible instead of
+// directly working with wxCriticalSection class - it is safer
+class WXDLLEXPORT wxCriticalSection
+{
+public:
+ // ctor & dtor
+ WXCRITICAL_INLINE wxCriticalSection();
+ WXCRITICAL_INLINE ~wxCriticalSection();
+
+ // enter the section (the same as locking a mutex)
+ WXCRITICAL_INLINE void Enter();
+ // leave the critical section (same as unlocking a mutex)
+ WXCRITICAL_INLINE void Leave();
+
+private:
+ // no assignment operator nor copy ctor
+ wxCriticalSection(const wxCriticalSection&);
+ wxCriticalSection& operator=(const wxCriticalSection&);
+
+#if defined(__WXMSW__) || defined(__WXPM__)
+ wxCriticalSectionInternal *m_critsect;
+#else // !MSW
+ wxMutex m_mutex;
+#endif // MSW/!MSW
+};
+
+// keep your preprocessor name space clean
+#undef WXCRITICAL_INLINE
+
+// wxCriticalSectionLocker is the same to critical sections as wxMutexLocker is
+// to th mutexes
+class WXDLLEXPORT wxCriticalSectionLocker
+{
+public:
+ wxCriticalSectionLocker(wxCriticalSection& critsect) : m_critsect(critsect)
+ { m_critsect.Enter(); }
+ ~wxCriticalSectionLocker()
+ { m_critsect.Leave(); }
+
+private:
+ // no assignment operator nor copy ctor
+ wxCriticalSectionLocker(const wxCriticalSectionLocker&);
+ wxCriticalSectionLocker& operator=(const wxCriticalSectionLocker&);
+
+ wxCriticalSection& m_critsect;
+};
+
+// ----------------------------------------------------------------------------