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 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/exp-drd/drd_mutex.c b/exp-drd/drd_mutex.c
index 2d55c31..e72286a 100644
--- a/exp-drd/drd_mutex.c
+++ b/exp-drd/drd_mutex.c
@@ -201,14 +201,12 @@
  *  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 @@
                  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 @@
     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)
   {