From 51a32b0907ade460f2dd228ff03e7880f43b8aaa Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 26 Apr 2004 08:05:24 +0000 Subject: [PATCH] Split some combined error messages, so they are more informative. Also return EPERM where appropriate, instead of EINVAL. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2387 --- coregrind/vg_scheduler.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/coregrind/vg_scheduler.c b/coregrind/vg_scheduler.c index a20af0b53f..53a967009d 100644 --- a/coregrind/vg_scheduler.c +++ b/coregrind/vg_scheduler.c @@ -2368,9 +2368,16 @@ void do_pthread_cond_wait ( ThreadId tid, vg_assert(VG_(is_valid_tid)(tid) && VG_(threads)[tid].status == VgTs_Runnable); - if (mutex == NULL || cond == NULL) { + if (mutex == NULL) { + VG_(record_pthread_error)( tid, + "pthread_cond_wait/timedwait: mutex is NULL"); + SET_PTHREQ_RETVAL(tid, VKI_EINVAL); + return; + } + + if (cond == NULL) { VG_(record_pthread_error)( tid, - "pthread_cond_wait/timedwait: cond or mutex is NULL"); + "pthread_cond_wait/timedwait: cond is NULL"); SET_PTHREQ_RETVAL(tid, VKI_EINVAL); return; } @@ -2396,12 +2403,17 @@ void do_pthread_cond_wait ( ThreadId tid, } /* Barf if we don't currently hold the mutex. */ - if (mutex->__vg_m_count == 0 /* nobody holds it */ - || (ThreadId)mutex->__vg_m_owner != tid /* we don't hold it */) { + if (mutex->__vg_m_count == 0 /* nobody holds it */) { VG_(record_pthread_error)( tid, - "pthread_cond_wait/timedwait: mutex is unlocked " - "or is locked but not owned by thread"); - SET_PTHREQ_RETVAL(tid, VKI_EINVAL); + "pthread_cond_wait/timedwait: mutex is unlocked"); + SET_PTHREQ_RETVAL(tid, VKI_EPERM); + return; + } + + if ((ThreadId)mutex->__vg_m_owner != tid /* we don't hold it */) { + VG_(record_pthread_error)( tid, + "pthread_cond_wait/timedwait: mutex is locked by another thread"); + SET_PTHREQ_RETVAL(tid, VKI_EPERM); return; } -- 2.47.2