X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/76df57d24ef6c9d386587a84e52901754f7c4652..87d77923a6b62816336e53abd4217a119f14675d:/include/wx/thread.h diff --git a/include/wx/thread.h b/include/wx/thread.h index 49e7b0a582..401d5f5937 100644 --- a/include/wx/thread.h +++ b/include/wx/thread.h @@ -23,7 +23,7 @@ #if wxUSE_THREADS // only for wxUSE_THREADS - otherwise we'd get undefined symbols -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(__APPLE__) #pragma interface "thread.h" #endif @@ -32,8 +32,6 @@ #undef Yield #endif -#include "wx/module.h" - // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- @@ -212,8 +210,12 @@ private: // just mutexes make all wxCriticalSection class functions inline #if !defined(__WXMSW__) && !defined(__WXPM__) #define wxCRITSECT_IS_MUTEX 1 + + #define wxCRITSECT_INLINE inline #else // MSW || OS2 #define wxCRITSECT_IS_MUTEX 0 + + #define wxCRITSECT_INLINE #endif // MSW/!MSW // you should consider wxCriticalSectionLocker whenever possible instead of @@ -222,14 +224,14 @@ class WXDLLEXPORT wxCriticalSection { public: // ctor & dtor - wxCriticalSection(); - ~wxCriticalSection(); + wxCRITSECT_INLINE wxCriticalSection(); + wxCRITSECT_INLINE ~wxCriticalSection(); // enter the section (the same as locking a mutex) - void Enter(); + wxCRITSECT_INLINE void Enter(); // leave the critical section (same as unlocking a mutex) - void Leave(); + wxCRITSECT_INLINE void Leave(); private: #if wxCRITSECT_IS_MUTEX @@ -237,11 +239,23 @@ private: #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 + // include windows.h from this public header and we also have to use the + // union to force the correct (i.e. maximal) alignment // // if CRITICAL_SECTION size changes in Windows, you'll get an assert from // thread.cpp and will need to increase the buffer size - char m_buffer[24]; + // + // finally, we need this typedef instead of declaring m_buffer directly + // because otherwise the assert mentioned above wouldn't compile with some + // compilers (notably CodeWarrior 8) + typedef char wxCritSectBuffer[24]; + union + { + unsigned long m_dummy1; + void *m_dummy2; + + wxCritSectBuffer m_buffer; + }; #else // nothing for OS/2 #endif // Unix/Win32/OS2 @@ -251,13 +265,16 @@ private: #if wxCRITSECT_IS_MUTEX // implement wxCriticalSection using mutexes - wxCriticalSection::wxCriticalSection() { } - wxCriticalSection::~wxCriticalSection() { } + inline wxCriticalSection::wxCriticalSection() { } + inline wxCriticalSection::~wxCriticalSection() { } - void wxCriticalSection::Enter() { (void)m_mutex.Lock(); } - void wxCriticalSection::Leave() { (void)m_mutex.Unlock(); } + inline void wxCriticalSection::Enter() { (void)m_mutex.Lock(); } + inline void wxCriticalSection::Leave() { (void)m_mutex.Unlock(); } #endif // wxCRITSECT_IS_MUTEX +#undef wxCRITSECT_INLINE +#undef wxCRITSECT_IS_MUTEX + // wxCriticalSectionLocker is the same to critical sections as wxMutexLocker is // to th mutexes class WXDLLEXPORT wxCriticalSectionLocker @@ -577,8 +594,13 @@ void WXDLLEXPORT wxMutexGuiLeave(); #define wxENTER_CRIT_SECT(cs) (cs).Enter() #define wxLEAVE_CRIT_SECT(cs) (cs).Leave() #define wxCRIT_SECT_DECLARE(cs) static wxCriticalSection cs +#define wxCRIT_SECT_DECLARE_MEMBER(cs) wxCriticalSection cs #define wxCRIT_SECT_LOCKER(name, cs) wxCriticalSectionLocker name(cs) +// function for checking if we're in the main thread which may be used whether +// wxUSE_THREADS is 0 or 1 +inline bool wxIsMainThread() { return wxThread::IsMain(); } + #else // !wxUSE_THREADS // no thread support @@ -590,8 +612,12 @@ inline void WXDLLEXPORT wxMutexGuiLeave() { } #define wxENTER_CRIT_SECT(cs) #define wxLEAVE_CRIT_SECT(cs) #define wxCRIT_SECT_DECLARE(cs) +#define wxCRIT_SECT_DECLARE_MEMBER(cs) #define wxCRIT_SECT_LOCKER(name, cs) +// if there is only one thread, it is always the main one +inline bool wxIsMainThread() { return true; } + #endif // wxUSE_THREADS/!wxUSE_THREADS // mark part of code as being a critical section: this macro declares a