]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxCRITICAL_SECTION macro
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 7 Jun 2002 00:34:56 +0000 (00:34 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 7 Jun 2002 00:34:56 +0000 (00:34 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15770 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/thread.h

index 9917e594df689cd9cfb81df265b77061966455a3..f4fec4683c638de42e6903764d548950d1cd2814 100644 (file)
@@ -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
 {