+// 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.
+//
+// NB: wxCriticalSection object does not allocate any memory in its ctor
+// which makes it possible to have static globals of this class
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxCriticalSectionInternal;
+
+// in order to avoid any overhead under platforms where critical sections are
+// just mutexes make all wxCriticalSection class functions inline
+#if !defined(__WXMSW__) && !defined(__WXPM__) && !defined(__WXMAC__)
+ #define WXCRITICAL_INLINE inline
+
+ #define wxCRITSECT_IS_MUTEX 1
+#else // MSW || Mac || OS2
+ #define WXCRITICAL_INLINE
+
+ #define wxCRITSECT_IS_MUTEX 0
+#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 wxCRITSECT_IS_MUTEX
+ wxMutex m_mutex;
+#elif defined(__WXMSW__)
+ // we can't allocate any memory in the ctor, so use placement new -
+ // unfortunately, we have to hardcode the sizeof() here because we can't
+ // include windows.h from this public header
+ char m_buffer[24];
+#elif !defined(__WXPM__)
+ wxCriticalSectionInternal *m_critsect;
+#else
+ // nothing for OS/2
+#endif // !Unix/Unix
+};
+
+// 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:
+ inline wxCriticalSectionLocker(wxCriticalSection& critsect);
+ inline ~wxCriticalSectionLocker();
+
+private:
+ // no assignment operator nor copy ctor
+ wxCriticalSectionLocker(const wxCriticalSectionLocker&);
+ wxCriticalSectionLocker& operator=(const wxCriticalSectionLocker&);
+
+ wxCriticalSection& m_critsect;
+};
+
+// ----------------------------------------------------------------------------
+// Condition variable: allows to block the thread execution until something
+// happens (== condition is signaled)
+// ----------------------------------------------------------------------------
+