]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Make sure no error message is printed when pthread_mutex_trylock() is called on a...
authorBart Van Assche <bvanassche@acm.org>
Mon, 24 Mar 2008 08:33:47 +0000 (08:33 +0000)
committerBart Van Assche <bvanassche@acm.org>
Mon, 24 Mar 2008 08:33:47 +0000 (08:33 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7769

exp-drd/drd_clientreq.c
exp-drd/drd_clientreq.h
exp-drd/drd_main.c
exp-drd/drd_mutex.c
exp-drd/drd_mutex.h
exp-drd/drd_pthread_intercepts.c
exp-drd/drd_track.h

index c2a34857f57630757c5265bfc55a3386fcd52bed..507668801739bc5b45a804b5740fb0e53bbff024 100644 (file)
@@ -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:
index 8d421d65145d5ea0cac3cbe52a57746372363060..36573193831d7cd1a12c2e8f94c769212520ec76 100644 (file)
@@ -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 */
index 32f85bd90971402b78753fc6bf889614b1de49df..fb5fa5bfa97c42b530acdacc8bd41746b0b4626b 100644 (file)
@@ -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)
index 2d55c31e1b5bf6a9e452454be592fa4217f7602d..e72286ac1572f7ca86c0fbfd58a7af84ea6cc2a4 100644 (file)
@@ -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)
   {
index b44c3b8ec468c38ddb2dca914867eaf5554387f3..caabfb35ee667732f6c37e448a899c077a8e4f1b 100644 (file)
@@ -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);
index 34229f5250a8f295faf57e58d788fa9e60211fc0..c363a2f00301bf33519eb5742aef5d8d5c8f9843 100644 (file)
@@ -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);
index 4cde2afb78fa44f25f3a71118f0767bcc8b9dd4b..bf4c9ff3c4dff171750375019e89af9bb7048a3a 100644 (file)
@@ -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);