From owner-freebsd-threads@FreeBSD.ORG Wed Nov 16 23:54:39 2011 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 040FE1065675 for ; Wed, 16 Nov 2011 23:54:39 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (relay04.stack.nl [IPv6:2001:610:1108:5010::107]) by mx1.freebsd.org (Postfix) with ESMTP id 9A72E8FC22 for ; Wed, 16 Nov 2011 23:54:38 +0000 (UTC) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id C1F591DD501 for ; Thu, 17 Nov 2011 00:54:37 +0100 (CET) Received: by snail.stack.nl (Postfix, from userid 1677) id 995FC28468; Thu, 17 Nov 2011 00:54:37 +0100 (CET) Date: Thu, 17 Nov 2011 00:54:37 +0100 From: Jilles Tjoelker To: freebsd-threads@freebsd.org Message-ID: <20111116235437.GA31850@stack.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Subject: [patch] Fix pthread_cond_timedwait() in realtime thread or with PI or PP mutex X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Nov 2011 23:54:39 -0000 As reported in PR 162403, pthread_cond_timedwait()'s timeout is broken if the kernel condition variable is used (that means, when it is called from a thread with realtime priority or with a priority-inherit or priority-protect mutex; process-shared mutexes and condition variables do not currently work). The below patch appears to work in my testing and for the PR submitter. I would like to see this in 9.0, if possible. Index: lib/libthr/thread/thr_umtx.c =================================================================== --- lib/libthr/thread/thr_umtx.c (revision 226880) +++ lib/libthr/thread/thr_umtx.c (working copy) @@ -231,7 +231,7 @@ int _thr_ucond_wait(struct ucond *cv, struct umutex *m, - const struct timespec *timeout, int check_unparking) + const struct timespec *timeout, int flags) { if (timeout && (timeout->tv_sec < 0 || (timeout->tv_sec == 0 && timeout->tv_nsec <= 0))) { @@ -240,7 +240,7 @@ return (ETIMEDOUT); } return _umtx_op_err(cv, UMTX_OP_CV_WAIT, - check_unparking ? UMTX_CHECK_UNPARKING : 0, + flags, m, __DECONST(void*, timeout)); } Index: lib/libthr/thread/thr_umtx.h =================================================================== --- lib/libthr/thread/thr_umtx.h (revision 226880) +++ lib/libthr/thread/thr_umtx.h (working copy) @@ -55,7 +55,7 @@ const struct timespec *timeout, int shared) __hidden; int _thr_umtx_wake(volatile void *mtx, int count, int shared) __hidden; int _thr_ucond_wait(struct ucond *cv, struct umutex *m, - const struct timespec *timeout, int check_unpaking) __hidden; + const struct timespec *timeout, int flags) __hidden; void _thr_ucond_init(struct ucond *cv) __hidden; int _thr_ucond_signal(struct ucond *cv) __hidden; int _thr_ucond_broadcast(struct ucond *cv) __hidden; -- Jilles Tjoelker