]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Merge from trunk, revs 12897 and 12898. (Handle non-zero sem_*wait()
authorJulian Seward <jseward@acm.org>
Sun, 2 Sep 2012 20:58:17 +0000 (20:58 +0000)
committerJulian Seward <jseward@acm.org>
Sun, 2 Sep 2012 20:58:17 +0000 (20:58 +0000)
return values correctly, #305690)

git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_3_8_BRANCH@12945

drd/drd_semaphore.c

index 5045805464451336b307956ca410c73e38a7f751..226c5ea80f4b1a2386135c8965ef04d9eb1a2167 100644 (file)
@@ -339,8 +339,7 @@ void DRD_(semaphore_pre_wait)(const Addr semaphore)
 
 /**
  * Called after sem_wait() finished.
- * @note Do not rely on the value of 'waited' -- some glibc versions do
- *       not set it correctly.
+ * @note Some C libraries do not set the 'waited' value correctly.
  */
 void DRD_(semaphore_post_wait)(const DrdThreadId tid, const Addr semaphore,
                                const Bool waited)
@@ -348,16 +347,17 @@ void DRD_(semaphore_post_wait)(const DrdThreadId tid, const Addr semaphore,
    struct semaphore_info* p;
    Segment* sg;
 
+   tl_assert(waited == 0 || waited == 1);
    p = semaphore_get(semaphore);
    if (s_trace_semaphore)
-      DRD_(trace_msg)("[%d] sem_wait      0x%lx value %u -> %u",
+      DRD_(trace_msg)("[%d] sem_wait      0x%lx value %u -> %u%s",
                       DRD_(thread_get_running_tid)(), semaphore,
-                      p ? p->value : 0, p ? p->value - 1 : 0);
+                      p ? p->value : 0, p ? p->value - waited : 0,
+                     waited ? "" : " (did not wait)");
 
-   if (p)
-   {
+   if (p) {
       p->waiters--;
-      p->value--;
+      p->value -= waited;
    }
 
    /*
@@ -378,6 +378,9 @@ void DRD_(semaphore_post_wait)(const DrdThreadId tid, const Addr semaphore,
       return;
    }
 
+   if (!waited)
+      return;
+
    if (p->waits_to_skip > 0)
       p->waits_to_skip--;
    else