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>
This commit is contained in:
parent
efc167b8e4
commit
9c29beb9ea
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user