summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-08-28 13:46:16 +0200
committerQt by Nokia <qt-info@nokia.com>2012-09-07 15:39:31 +0200
commit9c29beb9eaa35a0c62aca9abb369540fe4edc4d5 (patch)
tree06889eb9165bcfb3280ecba002f8ff7a16bd90e2 /tests/benchmarks/corelib
parentefc167b8e44bc47923b2e36d9db8bad129f9578b (diff)
Add a way to benchmark sem_t on Unix too
It's closer to what we do with in QMutex than pthread_mutex_lock. Change-Id: I86498a800b69b684bf096912e911bc5bca219727 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests/benchmarks/corelib')
-rw-r--r--tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp b/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp
index 12420e25a1..ab668f9388 100644
--- a/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp
+++ b/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp
@@ -44,7 +44,10 @@
#include <math.h>
+//#define USE_SEM_T
+
#if defined(Q_OS_UNIX)
+#if !defined(USE_SEM_T)
# include <pthread.h>
# include <errno.h>
typedef pthread_mutex_t NativeMutexType;
@@ -64,6 +67,26 @@ void NativeMutexUnlock(NativeMutexType *mutex)
{
pthread_mutex_unlock(mutex);
}
+#else
+# include <semaphore.h>
+typedef sem_t NativeMutexType;
+void NativeMutexInitialize(NativeMutexType *mutex)
+{
+ sem_init(mutex, false, 1);
+}
+void NativeMutexDestroy(NativeMutexType *mutex)
+{
+ sem_destroy(mutex);
+}
+void NativeMutexLock(NativeMutexType *mutex)
+{
+ sem_wait(mutex);
+}
+void NativeMutexUnlock(NativeMutexType *mutex)
+{
+ sem_post(mutex);
+}
+#endif
#elif defined(Q_OS_WIN)
# define _WIN32_WINNT 0x0400
# include <windows.h>