From 7414c24a7741696cbe4e2da8c2fe9837b866bd5b Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Tue, 23 Feb 2010 07:12:38 +0000 Subject: [PATCH] * thread.cc (pthread_mutex::unlock): Don't attempt to unlock if there is an error. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/thread.cc | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 8ccb68416..963b3998b 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2010-02-23 Christopher Faylor + + * thread.cc (pthread_mutex::unlock): Don't attempt to unlock if there + is an error. + 2010-02-22 Christopher Faylor * include/sys/strace.h: Define _STRACE_SPECIAL. diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 0a44d6965..474f6bd2d 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -1614,15 +1614,15 @@ pthread_mutex::lock () int pthread_mutex::unlock () { - int res; + int res = 0; pthread_t self = ::pthread_self (); if (type == PTHREAD_MUTEX_NORMAL) /* no error checking */; else if (no_owner ()) - return type == PTHREAD_MUTEX_ERRORCHECK ? EINVAL : 0; + res = type == PTHREAD_MUTEX_ERRORCHECK ? EINVAL : 0; else if (!pthread::equal (owner, self)) res = EPERM; - if (recursion_counter > 0 && --recursion_counter == 0) + if (!res && recursion_counter > 0 && --recursion_counter == 0) /* Don't try to unlock anything if recursion_counter == 0. This means the mutex was never locked or that we've forked. */ { @@ -1635,8 +1635,8 @@ pthread_mutex::unlock () res = 0; } - pthread_printf ("mutex %p, owner %p, self %p, lock_counter %d, recursion_counter %d, res %d", - this, owner, self, lock_counter, recursion_counter, res); + pthread_printf ("mutex %p, owner %p, self %p, lock_counter %d, recursion_counter %d, type %d, res %d", + this, owner, self, lock_counter, recursion_counter, type, res); return res; } -- 2.43.5