class WXDLLEXPORT wxMutex
{
public:
- // constructor & destructor
- wxMutex();
- ~wxMutex();
+ // constructor & destructor
+ wxMutex();
+ ~wxMutex();
- // Lock the mutex.
- wxMutexError Lock();
- // Try to lock the mutex: if it can't, returns immediately with an error.
- wxMutexError TryLock();
- // Unlock the mutex.
- wxMutexError Unlock();
+ // Lock the mutex.
+ wxMutexError Lock();
+ // Try to lock the mutex: if it can't, returns immediately with an error.
+ wxMutexError TryLock();
+ // Unlock the mutex.
+ wxMutexError Unlock();
- // Returns true if the mutex is locked.
- bool IsLocked() const { return (m_locked > 0); }
+ // Returns true if the mutex is locked.
+ bool IsLocked() const { return (m_locked > 0); }
protected:
- friend class wxCondition;
+ friend class wxCondition;
- int m_locked;
- wxMutexInternal *p_internal;
+ // 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:
~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;
};
-#ifdef __WXMSW__
-
// ----------------------------------------------------------------------------
// 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
// you should consider wxCriticalSectionLocker whenever possible instead of
// directly working with wxCriticalSection class - it is safer
-class WXDLLEXPORT wxCriticalSectionInternal;
+#ifdef __WXMSW__
+ class WXDLLEXPORT wxCriticalSectionInternal;
+ #define WXCRITICAL_INLINE
+#else // !MSW
+ #define WXCRITICAL_INLINE inline
+#endif // MSW/!MSW
class WXDLLEXPORT wxCriticalSection
{
public:
// ctor & dtor
- wxCriticalSection();
- ~wxCriticalSection();
+ WXCRITICAL_INLINE wxCriticalSection();
+ WXCRITICAL_INLINE ~wxCriticalSection();
// enter the section (the same as locking a mutex)
- void Enter();
+ void WXCRITICAL_INLINE Enter();
// leave the critical section (same as unlocking a mutex)
- void Leave();
+ void WXCRITICAL_INLINE 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
};
// wxCriticalSectionLocker is the same to critical sections as wxMutexLocker is
{ m_critsect.Leave(); }
private:
+ // no assignment operator nor copy ctor
+ wxCriticalSectionLocker(const wxCriticalSectionLocker&);
+ wxCriticalSectionLocker& operator=(const wxCriticalSectionLocker&);
+
wxCriticalSection& m_critsect;
};
-#endif
-
// ----------------------------------------------------------------------------
// Condition handler.
// ----------------------------------------------------------------------------
void WXDLLEXPORT wxMutexGuiEnter();
void WXDLLEXPORT wxMutexGuiLeave();
-// implementation only
-#ifdef __WXMSW__
- // unlock GUI if there are threads waiting for and lock it back when
- // there are no more of them - should be called periodically by the main
- // thread
- void WXDLLEXPORT wxMutexGuiLeaveOrEnter();
-
- // returns TRUE if the main thread has GUI lock
- inline bool WXDLLEXPORT wxGuiOwnedByMainThread();
-
- // wakes up the main thread if it's sleeping inside ::GetMessage()
- inline void WXDLLEXPORT wxWakeUpMainThread();
-#endif // MSW
-
#else // !wxUSE_THREADS
// no thread support
~wxMutexGuiLocker() { wxMutexGuiLeave(); }
};
+// -----------------------------------------------------------------------------
+// implementation only until the end of file
+// -----------------------------------------------------------------------------
+#ifdef wxUSE_THREADS
+#ifdef __WXMSW__
+ // unlock GUI if there are threads waiting for and lock it back when
+ // there are no more of them - should be called periodically by the main
+ // thread
+ extern void WXDLLEXPORT wxMutexGuiLeaveOrEnter();
+
+ // returns TRUE if the main thread has GUI lock
+ extern bool WXDLLEXPORT wxGuiOwnedByMainThread();
+
+ // wakes up the main thread if it's sleeping inside ::GetMessage()
+ extern void WXDLLEXPORT wxWakeUpMainThread();
+#else // !MSW
+ // implement wxCriticalSection using mutexes
+ inline wxCriticalSection::wxCriticalSection() { }
+ inline wxCriticalSection::~wxCriticalSection() { }
+
+ inline void wxCriticalSection::Enter() { (void)m_mutex.Lock(); }
+ inline void wxCriticalSection::Leave() { (void)m_mutex.Unlock(); }
+#endif // MSW/!MSW
+#endif // wxUSE_THREADS
+
#endif // __THREADH__