]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/benchmarks/tls.cpp
implement wxTreeCtrl::GetFocusedItem() for wxMSW too (see #10859)
[wxWidgets.git] / tests / benchmarks / tls.cpp
index afccef537784e6f9baa47b245b6e39475f52f80f..b187566c17d85184b72d7273bb76f012da37bf55 100644 (file)
 
 #include "bench.h"
 
 
 #include "bench.h"
 
-#ifdef __UNIX__
+#include "wx/tls.h"
+
+#if defined(__UNIX__)
     #define HAVE_PTHREAD
     #include <pthread.h>
     #define HAVE_PTHREAD
     #include <pthread.h>
+#elif defined(__WIN32__)
+    #define HAVE_WIN32_THREAD
+    #include "wx/msw/wrapwin.h"
 #endif
 
 #if wxCHECK_GCC_VERSION(3, 3)
     #define HAVE_COMPILER_THREAD
     #define wxTHREAD_SPECIFIC __thread
 #endif
 
 #if wxCHECK_GCC_VERSION(3, 3)
     #define HAVE_COMPILER_THREAD
     #define wxTHREAD_SPECIFIC __thread
+#elif wxCHECK_VISUALC_VERSION(7)
+    #define HAVE_COMPILER_THREAD
+    #define wxTHREAD_SPECIFIC __declspec(thread)
 #endif
 
 // uncomment this to also test Boost version (you will also need to link with
 #endif
 
 // uncomment this to also test Boost version (you will also need to link with
@@ -105,6 +113,46 @@ BENCHMARK_FUNC(PosixTLS)
 
 #endif // HAVE_PTHREAD
 
 
 #endif // HAVE_PTHREAD
 
+#ifdef HAVE_WIN32_THREAD
+
+class TlsSlot
+{
+public:
+    TlsSlot()
+    {
+        m_slot = ::TlsAlloc();
+    }
+
+    ~TlsSlot()
+    {
+        ::TlsFree(m_slot);
+    }
+
+    operator DWORD() const { return m_slot; }
+
+private:
+    DWORD m_slot;
+
+    DECLARE_NO_COPY_CLASS(TlsSlot)
+};
+
+BENCHMARK_FUNC(Win32TLS)
+{
+    static TlsSlot s_slot;
+
+    for ( int n = 0; n < NUM_ITER; n++ )
+    {
+        if ( n % 2 )
+            ::TlsSetValue(s_slot, 0);
+        else
+            ::TlsSetValue(s_slot, &n);
+    }
+
+    return !::TlsGetValue(s_slot);
+}
+
+#endif // HAVE_WIN32_THREAD
+
 #ifdef HAVE_BOOST_THREAD
 
 BENCHMARK_FUNC(BoostTLS)
 #ifdef HAVE_BOOST_THREAD
 
 BENCHMARK_FUNC(BoostTLS)
@@ -125,3 +173,19 @@ BENCHMARK_FUNC(BoostTLS)
 }
 
 #endif // HAVE_BOOST_THREAD
 }
 
 #endif // HAVE_BOOST_THREAD
+
+BENCHMARK_FUNC(wxTLS)
+{
+    static wxTLS_TYPE(int) s_globalVar;
+    #define s_global wxTLS_VALUE(s_globalVar)
+
+    for ( int n = 0; n < NUM_ITER; n++ )
+    {
+        if ( n % 2 )
+            s_global = 0;
+        else
+            s_global = n;
+    }
+
+    return !s_global;
+}