From: Bart Van Assche Date: Mon, 24 Mar 2008 08:33:47 +0000 (+0000) Subject: Make sure no error message is printed when pthread_mutex_trylock() is called on a... X-Git-Tag: svn/VALGRIND_3_4_0~811 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f3db559a9d7cf0c68bfe27e01a041a064f231d0f;p=thirdparty%2Fvalgrind.git Make sure no error message is printed when pthread_mutex_trylock() is called on a non-recursive mutex from the thread that holds a lock on the mutex. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7769 --- diff --git a/exp-drd/drd_clientreq.c b/exp-drd/drd_clientreq.c index c2a34857f5..5076688017 100644 --- a/exp-drd/drd_clientreq.c +++ b/exp-drd/drd_clientreq.c @@ -147,7 +147,7 @@ static Bool drd_handle_client_request(ThreadId vg_tid, UWord* arg, UWord* ret) case VG_USERREQ__PRE_MUTEX_LOCK: if (thread_enter_synchr(drd_tid) == 0) - drd_pre_mutex_lock(arg[1], arg[2]); + drd_pre_mutex_lock(arg[1], arg[2], arg[3]); break; case VG_USERREQ__POST_MUTEX_LOCK: diff --git a/exp-drd/drd_clientreq.h b/exp-drd/drd_clientreq.h index 8d421d6514..3657319383 100644 --- a/exp-drd/drd_clientreq.h +++ b/exp-drd/drd_clientreq.h @@ -57,7 +57,7 @@ enum { /* args: Addr, MutexT */ /* to notify the drd tool of pthread_mutex_lock calls */ VG_USERREQ__PRE_MUTEX_LOCK, - /* args: Addr, MutexT */ + /* args: Addr, MutexT, Bool */ /* to notify the drd tool of pthread_mutex_lock calls */ VG_USERREQ__POST_MUTEX_LOCK, /* args: Addr, Bool */ diff --git a/exp-drd/drd_main.c b/exp-drd/drd_main.c index 32f85bd909..fb5fa5bfa9 100644 --- a/exp-drd/drd_main.c +++ b/exp-drd/drd_main.c @@ -628,9 +628,10 @@ void drd_post_mutex_destroy(const Addr mutex, const MutexT mutex_type) mutex_post_destroy(mutex); } -void drd_pre_mutex_lock(const Addr mutex, const MutexT mutex_type) +void drd_pre_mutex_lock(const Addr mutex, const MutexT mutex_type, + const Bool trylock) { - mutex_pre_lock(mutex, mutex_type); + mutex_pre_lock(mutex, mutex_type, trylock); } void drd_post_mutex_lock(const Addr mutex, const Bool took_lock) diff --git a/exp-drd/drd_mutex.c b/exp-drd/drd_mutex.c index 2d55c31e1b..e72286ac15 100644 --- a/exp-drd/drd_mutex.c +++ b/exp-drd/drd_mutex.c @@ -201,14 +201,12 @@ void mutex_post_destroy(const Addr mutex) * an attempt is made to lock recursively a synchronization object that must * not be locked recursively. */ -void mutex_pre_lock(const Addr mutex, MutexT mutex_type) +void mutex_pre_lock(const Addr mutex, const MutexT mutex_type, + const Bool trylock) { struct mutex_info* p; p = mutex_get_or_allocate(mutex, mutex_type); - - tl_assert(p); - if (s_trace_mutex) { VG_(message)(Vg_UserMsg, @@ -217,10 +215,23 @@ void mutex_pre_lock(const Addr mutex, MutexT mutex_type) thread_get_running_tid(), mutex_get_typename(p), mutex, - p->recursion_count, - p->owner); + p ? p->recursion_count : -1, + p ? p->owner : DRD_INVALID_THREADID); + } + + if (p == 0) + { + GenericErrInfo GEI; + VG_(maybe_record_error)(VG_(get_running_tid)(), + GenericErr, + VG_(get_IP)(VG_(get_running_tid)()), + "Not a mutex", + &GEI); + return; } + tl_assert(p); + if (mutex_type == mutex_type_invalid_mutex) { GenericErrInfo GEI; @@ -232,7 +243,8 @@ void mutex_pre_lock(const Addr mutex, MutexT mutex_type) return; } - if (p->owner == thread_get_running_tid() + if (! trylock + && p->owner == thread_get_running_tid() && p->recursion_count >= 1 && mutex_type != mutex_type_recursive_mutex) { diff --git a/exp-drd/drd_mutex.h b/exp-drd/drd_mutex.h index b44c3b8ec4..caabfb35ee 100644 --- a/exp-drd/drd_mutex.h +++ b/exp-drd/drd_mutex.h @@ -44,8 +44,8 @@ struct mutex_info* mutex_init(const Addr mutex, const MutexT mutex_type); void mutex_post_destroy(const Addr mutex); struct mutex_info* mutex_get(const Addr mutex); -void mutex_pre_lock(const Addr mutex, - const MutexT mutex_type); +void mutex_pre_lock(const Addr mutex, const MutexT mutex_type, + const Bool trylock); void mutex_post_lock(const Addr mutex, const Bool took_lock); void mutex_unlock(const Addr mutex, const MutexT mutex_type); const char* mutex_get_typename(struct mutex_info* const p); diff --git a/exp-drd/drd_pthread_intercepts.c b/exp-drd/drd_pthread_intercepts.c index 34229f5250..c363a2f003 100644 --- a/exp-drd/drd_pthread_intercepts.c +++ b/exp-drd/drd_pthread_intercepts.c @@ -375,7 +375,7 @@ PTH_FUNC(int, pthreadZumutexZutrylock, // pthread_mutex_trylock OrigFn fn; VALGRIND_GET_ORIG_FN(fn); VALGRIND_DO_CLIENT_REQUEST(res, 0, VG_USERREQ__PRE_MUTEX_LOCK, - mutex, mutex_type(mutex), 0, 0, 0); + mutex, mutex_type(mutex), 1, 0, 0); CALL_FN_W_W(ret, fn, mutex); VALGRIND_DO_CLIENT_REQUEST(res, -1, VG_USERREQ__POST_MUTEX_LOCK, mutex, ret == 0, 0, 0, 0); diff --git a/exp-drd/drd_track.h b/exp-drd/drd_track.h index 4cde2afb78..bf4c9ff3c4 100644 --- a/exp-drd/drd_track.h +++ b/exp-drd/drd_track.h @@ -29,7 +29,8 @@ void drd_trace_addr(const Addr addr); void drd_pre_mutex_init(Addr mutex, const MutexT mutex_type); void drd_post_mutex_destroy(Addr mutex, const MutexT mutex_type); -void drd_pre_mutex_lock(const Addr mutex, const MutexT mutex_type); +void drd_pre_mutex_lock(const Addr mutex, const MutexT mutex_type, + const Bool trylock); void drd_post_mutex_lock(Addr mutex, const Bool took_lock); void drd_pre_mutex_unlock(const Addr mutex, const MutexT mutex_type);