avoid pthread_mutex_timedlock in valgrind
This commit is contained in:
@@ -135,9 +135,41 @@ MutexImpl_Pthreads::~MutexImpl_Pthreads()
|
||||
}
|
||||
|
||||
|
||||
#if defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK) && defined(CRASH_HANDLER)
|
||||
static bool UseTimedlock()
|
||||
{
|
||||
#if defined(CPU_X86) && defined(__GNUC__)
|
||||
/* Valgrind crashes and burns on pthread_mutex_timedlock. */
|
||||
static int under_valgrind = -1;
|
||||
if( under_valgrind == -1 )
|
||||
{
|
||||
unsigned int magic[8] = { 0x00001001, 0, 0, 0, 0, 0, 0, 0 };
|
||||
asm(
|
||||
"mov %1, %%eax\n"
|
||||
"mov $0, %%edx\n"
|
||||
"rol $29, %%eax\n"
|
||||
"rol $3, %%eax\n"
|
||||
"ror $27, %%eax\n"
|
||||
"ror $5, %%eax\n"
|
||||
"rol $13, %%eax\n"
|
||||
"rol $19, %%eax\n"
|
||||
"mov %%edx, %0\t"
|
||||
: "=r" (under_valgrind): "r" (magic): "eax", "edx" );
|
||||
}
|
||||
|
||||
if( under_valgrind )
|
||||
return false;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool MutexImpl_Pthreads::Lock()
|
||||
{
|
||||
#if defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK) && defined(CRASH_HANDLER)
|
||||
if( UseTimedlock() )
|
||||
{
|
||||
int len = 10; /* seconds */
|
||||
int tries = 2;
|
||||
|
||||
@@ -174,7 +206,9 @@ bool MutexImpl_Pthreads::Lock()
|
||||
}
|
||||
|
||||
return false;
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
|
||||
int ret;
|
||||
do
|
||||
{
|
||||
@@ -185,7 +219,6 @@ bool MutexImpl_Pthreads::Lock()
|
||||
ASSERT_M( ret == 0, ssprintf("pthread_mutex_lock: %s", strerror(errno)) );
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool MutexImpl_Pthreads::TryLock()
|
||||
|
||||
Reference in New Issue
Block a user