X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9e84b84742248ef54a561b4937bbc039332c2c51..bf43d750e66d491255c090dd0336c46def997178:/include/wx/thread.h diff --git a/include/wx/thread.h b/include/wx/thread.h index 9917e594df..49e7b0a582 100644 --- a/include/wx/thread.h +++ b/include/wx/thread.h @@ -222,14 +222,14 @@ class WXDLLEXPORT wxCriticalSection { public: // ctor & dtor - inline wxCriticalSection(); - inline ~wxCriticalSection(); + wxCriticalSection(); + ~wxCriticalSection(); // enter the section (the same as locking a mutex) - inline void Enter(); + void Enter(); // leave the critical section (same as unlocking a mutex) - inline void Leave(); + void Leave(); private: #if wxCRITSECT_IS_MUTEX @@ -251,11 +251,11 @@ private: #if wxCRITSECT_IS_MUTEX // implement wxCriticalSection using mutexes - inline wxCriticalSection::wxCriticalSection() { } - inline wxCriticalSection::~wxCriticalSection() { } + wxCriticalSection::wxCriticalSection() { } + wxCriticalSection::~wxCriticalSection() { } - inline void wxCriticalSection::Enter() { (void)m_mutex.Lock(); } - inline void wxCriticalSection::Leave() { (void)m_mutex.Unlock(); } + void wxCriticalSection::Enter() { (void)m_mutex.Lock(); } + void wxCriticalSection::Leave() { (void)m_mutex.Unlock(); } #endif // wxCRITSECT_IS_MUTEX // wxCriticalSectionLocker is the same to critical sections as wxMutexLocker is @@ -594,6 +594,27 @@ inline void WXDLLEXPORT wxMutexGuiLeave() { } #endif // wxUSE_THREADS/!wxUSE_THREADS +// mark part of code as being a critical section: this macro declares a +// critical section with the given name and enters it immediately and leaves +// it at the end of the current scope +// +// example: +// +// int Count() +// { +// static int s_counter = 0; +// +// wxCRITICAL_SECTION(counter); +// +// return ++s_counter; +// } +// +// this function is MT-safe in presence of the threads but there is no +// overhead when the library is compiled without threads +#define wxCRITICAL_SECTION(name) \ + wxCRIT_SECT_DECLARE(s_cs##name); \ + wxCRIT_SECT_LOCKER(cs##name##Locker, s_cs##name) + // automatically lock GUI mutex in ctor and unlock it in dtor class WXDLLEXPORT wxMutexGuiLocker {