// 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
{
public:
// ctor & dtor
- inline wxCriticalSection();
- inline ~wxCriticalSection();
+ wxCRITSECT_INLINE wxCriticalSection();
+ wxCRITSECT_INLINE ~wxCriticalSection();
// enter the section (the same as locking a mutex)
- inline void Enter();
+ wxCRITSECT_INLINE void Enter();
// leave the critical section (same as unlocking a mutex)
- inline void Leave();
+ wxCRITSECT_INLINE void Leave();
private:
#if wxCRITSECT_IS_MUTEX
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
#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
{