Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Nov 2010 07:03:35 +0000 (UTC)
From:      David Xu <davidxu@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r214826 - user/davidxu/libthr/lib/libthr/thread
Message-ID:  <201011050703.oA573Z5G087808@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: davidxu
Date: Fri Nov  5 07:03:35 2010
New Revision: 214826
URL: http://svn.freebsd.org/changeset/base/214826

Log:
  Don't forget to lock the mutex again before doing thread cancellation.

Modified:
  user/davidxu/libthr/lib/libthr/thread/thr_cond.c

Modified: user/davidxu/libthr/lib/libthr/thread/thr_cond.c
==============================================================================
--- user/davidxu/libthr/lib/libthr/thread/thr_cond.c	Fri Nov  5 06:42:30 2010	(r214825)
+++ user/davidxu/libthr/lib/libthr/thread/thr_cond.c	Fri Nov  5 07:03:35 2010	(r214826)
@@ -259,6 +259,7 @@ cond_wait_user(pthread_cond_t *cond, pth
 		} else if (cancel && SHOULD_CANCEL(curthread) &&
 			   !THR_IN_CRITICAL(curthread)) {
 			_thr_umtx_unlock(&cv->c_lock);
+			_mutex_cv_lock(mutex, recurse);
 			_pthread_exit(PTHREAD_CANCELED);
 		}
 	}
@@ -292,7 +293,15 @@ cond_wait_common(pthread_cond_t *cond, p
 	    (cv->c_kerncv.c_flags & USYNC_PROCESS_SHARED))
 		return (EINVAL);
 
+	/*
+	 * If the thread is real-time thread or if it holds priority mutex,
+	 * it should use kernel based cv, because the cv internal lock
+	 * does not protect priority, it can cause priority inversion.
+	 * Note that if it is robust type of mutex, we should not use
+	 * the internal lock too, because it is not robust.
+	 */
 	if (curthread->attr.sched_policy != SCHED_OTHER ||
+	    curthread->priority_mutex_count != 0  ||
 	    (m->m_lock.m_flags & (UMUTEX_PRIO_PROTECT|UMUTEX_PRIO_INHERIT)) != 0)
 		return cond_wait_kernel(cond, mutex, abstime, cancel);
 	else



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201011050703.oA573Z5G087808>