From 9c29beb9eaa35a0c62aca9abb369540fe4edc4d5 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 28 Aug 2012 13:46:16 +0200 Subject: 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 --- .../corelib/thread/qmutex/tst_qmutex.cpp | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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 +//#define USE_SEM_T + #if defined(Q_OS_UNIX) +#if !defined(USE_SEM_T) # include # include typedef pthread_mutex_t NativeMutexType; @@ -64,6 +67,26 @@ void NativeMutexUnlock(NativeMutexType *mutex) { pthread_mutex_unlock(mutex); } +#else +# include +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 -- cgit v1.2.3