From 0aa57eef725fd6a1ea3e96ae15a40511e8346f49 Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Sun, 2 Sep 2012 20:58:17 +0000 Subject: [PATCH] Merge from trunk, revs 12897 and 12898. (Handle non-zero sem_*wait() return values correctly, #305690) git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_3_8_BRANCH@12945 --- drd/drd_semaphore.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drd/drd_semaphore.c b/drd/drd_semaphore.c index 5045805464..226c5ea80f 100644 --- a/drd/drd_semaphore.c +++ b/drd/drd_semaphore.c @@ -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 -- 2.47.2