+ friend class wxCondition;
+
+ // no assignment operator nor copy ctor
+ wxMutex(const wxMutex&);
+ wxMutex& operator=(const wxMutex&);
+
+ int m_locked;
+ wxMutexInternal *p_internal;
+};
+
+// a helper class which locks the mutex in the ctor and unlocks it in the dtor:
+// this ensures that mutex is always unlocked, even if the function returns or
+// throws an exception before it reaches the end
+class WXDLLEXPORT wxMutexLocker
+{
+public:
+ // lock the mutex in the ctor
+ wxMutexLocker(wxMutex& mutex) : m_mutex(mutex)
+ { m_isOk = m_mutex.Lock() == wxMUTEX_NO_ERROR; }
+
+ // returns TRUE if mutex was successfully locked in ctor
+ bool IsOk() const
+ { return m_isOk; }
+
+ // unlock the mutex in dtor
+ ~wxMutexLocker()
+ { if ( IsOk() ) m_mutex.Unlock(); }
+
+private:
+ // no assignment operator nor copy ctor
+ wxMutexLocker(const wxMutexLocker&);
+ wxMutexLocker& operator=(const wxMutexLocker&);
+
+ bool m_isOk;
+ wxMutex& m_mutex;
+};
+
+// ----------------------------------------------------------------------------
+// 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
+#ifdef __WXMSW__
+ 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&);
+
+#ifdef __WXMSW__
+ 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(); }