wxCriticalSection implemented using mutexes for !MSW (sample compiles again)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1372 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -114,8 +114,6 @@ private:
|
|||||||
wxMutex *m_mutex;
|
wxMutex *m_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Critical section: this is the same as mutex but is only visible to the
|
// 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
|
// threads of the same process. For the platforms which don't have native
|
||||||
@@ -125,25 +123,34 @@ private:
|
|||||||
|
|
||||||
// you should consider wxCriticalSectionLocker whenever possible instead of
|
// you should consider wxCriticalSectionLocker whenever possible instead of
|
||||||
// directly working with wxCriticalSection class - it is safer
|
// 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
|
class WXDLLEXPORT wxCriticalSection
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// ctor & dtor
|
// ctor & dtor
|
||||||
wxCriticalSection();
|
WXCRITICAL_INLINE wxCriticalSection();
|
||||||
~wxCriticalSection();
|
WXCRITICAL_INLINE ~wxCriticalSection();
|
||||||
|
|
||||||
// enter the section (the same as locking a mutex)
|
// enter the section (the same as locking a mutex)
|
||||||
void Enter();
|
void WXCRITICAL_INLINE Enter();
|
||||||
// leave the critical section (same as unlocking a mutex)
|
// leave the critical section (same as unlocking a mutex)
|
||||||
void Leave();
|
void WXCRITICAL_INLINE Leave();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// no assignment operator nor copy ctor
|
// no assignment operator nor copy ctor
|
||||||
wxCriticalSection(const wxCriticalSection&);
|
wxCriticalSection(const wxCriticalSection&);
|
||||||
wxCriticalSection& operator=(const wxCriticalSection&);
|
wxCriticalSection& operator=(const wxCriticalSection&);
|
||||||
|
|
||||||
|
#ifdef __WXMSW__
|
||||||
wxCriticalSectionInternal *m_critsect;
|
wxCriticalSectionInternal *m_critsect;
|
||||||
|
#else // !MSW
|
||||||
|
wxMutex m_mutex;
|
||||||
|
#endif // MSW/!MSW
|
||||||
};
|
};
|
||||||
|
|
||||||
// wxCriticalSectionLocker is the same to critical sections as wxMutexLocker is
|
// wxCriticalSectionLocker is the same to critical sections as wxMutexLocker is
|
||||||
@@ -164,8 +171,6 @@ private:
|
|||||||
wxCriticalSection& m_critsect;
|
wxCriticalSection& m_critsect;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Condition handler.
|
// Condition handler.
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -269,20 +274,6 @@ private:
|
|||||||
void WXDLLEXPORT wxMutexGuiEnter();
|
void WXDLLEXPORT wxMutexGuiEnter();
|
||||||
void WXDLLEXPORT wxMutexGuiLeave();
|
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
|
#else // !wxUSE_THREADS
|
||||||
|
|
||||||
// no thread support
|
// no thread support
|
||||||
@@ -299,4 +290,29 @@ public:
|
|||||||
~wxMutexGuiLocker() { wxMutexGuiLeave(); }
|
~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
|
||||||
|
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();
|
||||||
|
#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__
|
#endif // __THREADH__
|
||||||
|
Reference in New Issue
Block a user