avoid pthread_mutex_timedlock in valgrind

This commit is contained in:
Glenn Maynard
2004-08-22 01:31:12 +00:00
parent 0f7572ad8c
commit d176c8af17
@@ -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() bool MutexImpl_Pthreads::Lock()
{ {
#if defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK) && defined(CRASH_HANDLER) #if defined(HAVE_PTHREAD_MUTEX_TIMEDLOCK) && defined(CRASH_HANDLER)
if( UseTimedlock() )
{
int len = 10; /* seconds */ int len = 10; /* seconds */
int tries = 2; int tries = 2;
@@ -174,7 +206,9 @@ bool MutexImpl_Pthreads::Lock()
} }
return false; return false;
#else }
#endif
int ret; int ret;
do do
{ {
@@ -185,7 +219,6 @@ bool MutexImpl_Pthreads::Lock()
ASSERT_M( ret == 0, ssprintf("pthread_mutex_lock: %s", strerror(errno)) ); ASSERT_M( ret == 0, ssprintf("pthread_mutex_lock: %s", strerror(errno)) );
return true; return true;
#endif
} }
bool MutexImpl_Pthreads::TryLock() bool MutexImpl_Pthreads::TryLock()