2015-08-07 09:22:12 +03:00
|
|
|
/* $NetBSD: kern_condvar.c,v 1.35 2015/08/07 06:22:12 uebayasi Exp $ */
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
/*-
|
2008-03-05 20:05:21 +03:00
|
|
|
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
|
2007-02-10 00:55:00 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Andrew Doran.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2008-06-16 14:03:47 +04:00
|
|
|
* Kernel condition variable implementation.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2015-08-07 09:22:12 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.35 2015/08/07 06:22:12 uebayasi Exp $");
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2015-08-07 09:22:12 +03:00
|
|
|
#include <sys/lwp.h>
|
2007-02-10 00:55:00 +03:00
|
|
|
#include <sys/condvar.h>
|
|
|
|
#include <sys/sleepq.h>
|
2008-05-31 17:36:25 +04:00
|
|
|
#include <sys/lockdebug.h>
|
2008-06-16 14:03:47 +04:00
|
|
|
#include <sys/cpu.h>
|
2008-05-31 17:36:25 +04:00
|
|
|
|
2008-12-19 10:57:28 +03:00
|
|
|
/*
|
|
|
|
* Accessors for the private contents of the kcondvar_t data type.
|
|
|
|
*
|
|
|
|
* cv_opaque[0] sleepq...
|
|
|
|
* cv_opaque[1] ...pointers
|
|
|
|
* cv_opaque[2] description for ps(1)
|
|
|
|
*
|
|
|
|
* cv_opaque[0..1] is protected by the interlock passed to cv_wait() (enqueue
|
|
|
|
* only), and the sleep queue lock acquired with sleeptab_lookup() (enqueue
|
|
|
|
* and dequeue).
|
|
|
|
*
|
|
|
|
* cv_opaque[2] (the wmesg) is static and does not change throughout the life
|
|
|
|
* of the CV.
|
|
|
|
*/
|
|
|
|
#define CV_SLEEPQ(cv) ((sleepq_t *)(cv)->cv_opaque)
|
|
|
|
#define CV_WMESG(cv) ((const char *)(cv)->cv_opaque[2])
|
|
|
|
#define CV_SET_WMESG(cv, v) (cv)->cv_opaque[2] = __UNCONST(v)
|
|
|
|
|
|
|
|
#define CV_DEBUG_P(cv) (CV_WMESG(cv) != nodebug)
|
2008-05-31 17:36:25 +04:00
|
|
|
#define CV_RA ((uintptr_t)__builtin_return_address(0))
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2009-10-22 01:11:57 +04:00
|
|
|
static void cv_unsleep(lwp_t *, bool);
|
2008-05-31 17:36:25 +04:00
|
|
|
static void cv_wakeup_one(kcondvar_t *);
|
|
|
|
static void cv_wakeup_all(kcondvar_t *);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2007-08-02 00:30:38 +04:00
|
|
|
static syncobj_t cv_syncobj = {
|
2007-02-10 00:55:00 +03:00
|
|
|
SOBJ_SLEEPQ_SORTED,
|
|
|
|
cv_unsleep,
|
2007-11-06 03:42:39 +03:00
|
|
|
sleepq_changepri,
|
2007-02-26 12:20:52 +03:00
|
|
|
sleepq_lendpri,
|
|
|
|
syncobj_noowner,
|
2007-02-10 00:55:00 +03:00
|
|
|
};
|
|
|
|
|
2008-05-31 17:36:25 +04:00
|
|
|
lockops_t cv_lockops = {
|
|
|
|
"Condition variable",
|
|
|
|
LOCKOPS_CV,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2007-08-02 00:30:38 +04:00
|
|
|
static const char deadcv[] = "deadcv";
|
2013-09-14 17:18:31 +04:00
|
|
|
#ifdef LOCKDEBUG
|
2008-05-31 17:36:25 +04:00
|
|
|
static const char nodebug[] = "nodebug";
|
2013-09-14 17:18:31 +04:00
|
|
|
#endif
|
2007-08-02 00:30:38 +04:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* cv_init:
|
|
|
|
*
|
|
|
|
* Initialize a condition variable for use.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cv_init(kcondvar_t *cv, const char *wmesg)
|
|
|
|
{
|
2008-05-31 20:25:23 +04:00
|
|
|
#ifdef LOCKDEBUG
|
2008-05-31 17:36:25 +04:00
|
|
|
bool dodebug;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-05-31 17:36:25 +04:00
|
|
|
dodebug = LOCKDEBUG_ALLOC(cv, &cv_lockops,
|
|
|
|
(uintptr_t)__builtin_return_address(0));
|
2008-05-31 20:25:23 +04:00
|
|
|
if (!dodebug) {
|
2008-05-31 17:36:25 +04:00
|
|
|
/* XXX This will break vfs_lockf. */
|
2008-05-31 20:25:23 +04:00
|
|
|
wmesg = nodebug;
|
2008-05-31 17:36:25 +04:00
|
|
|
}
|
2008-05-31 20:25:23 +04:00
|
|
|
#endif
|
|
|
|
KASSERT(wmesg != NULL);
|
2008-12-19 10:57:28 +03:00
|
|
|
CV_SET_WMESG(cv, wmesg);
|
2008-05-31 17:36:25 +04:00
|
|
|
sleepq_init(CV_SLEEPQ(cv));
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cv_destroy:
|
|
|
|
*
|
|
|
|
* Tear down a condition variable.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cv_destroy(kcondvar_t *cv)
|
|
|
|
{
|
|
|
|
|
2008-05-31 17:36:25 +04:00
|
|
|
LOCKDEBUG_FREE(CV_DEBUG_P(cv), cv);
|
2007-02-10 00:55:00 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
2008-03-05 20:05:21 +03:00
|
|
|
KASSERT(cv_is_valid(cv));
|
2008-12-19 10:57:28 +03:00
|
|
|
CV_SET_WMESG(cv, deadcv);
|
2007-02-10 00:55:00 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cv_enter:
|
|
|
|
*
|
|
|
|
* Look up and lock the sleep queue corresponding to the given
|
|
|
|
* condition variable, and increment the number of waiters.
|
|
|
|
*/
|
2008-05-31 17:36:25 +04:00
|
|
|
static inline void
|
2007-03-29 21:34:39 +04:00
|
|
|
cv_enter(kcondvar_t *cv, kmutex_t *mtx, lwp_t *l)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
|
|
|
sleepq_t *sq;
|
2008-05-26 16:08:38 +04:00
|
|
|
kmutex_t *mp;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-03-05 20:05:21 +03:00
|
|
|
KASSERT(cv_is_valid(cv));
|
2008-06-16 14:03:47 +04:00
|
|
|
KASSERT(!cpu_intr_p());
|
2007-11-06 03:42:39 +03:00
|
|
|
KASSERT((l->l_pflag & LP_INTR) == 0 || panicstr != NULL);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-05-31 17:36:25 +04:00
|
|
|
LOCKDEBUG_LOCKED(CV_DEBUG_P(cv), cv, mtx, CV_RA, 0);
|
|
|
|
|
2007-11-06 03:42:39 +03:00
|
|
|
l->l_kpriority = true;
|
2008-06-16 14:03:47 +04:00
|
|
|
mp = sleepq_hashlock(cv);
|
2008-05-31 17:36:25 +04:00
|
|
|
sq = CV_SLEEPQ(cv);
|
2008-05-26 16:08:38 +04:00
|
|
|
sleepq_enter(sq, l, mp);
|
2008-12-19 10:57:28 +03:00
|
|
|
sleepq_enqueue(sq, cv, CV_WMESG(cv), &cv_syncobj);
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_exit(mtx);
|
2008-06-16 14:03:47 +04:00
|
|
|
KASSERT(cv_has_waiters(cv));
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
2007-03-29 21:34:39 +04:00
|
|
|
/*
|
|
|
|
* cv_exit:
|
|
|
|
*
|
|
|
|
* After resuming execution, check to see if we have been restarted
|
|
|
|
* as a result of cv_signal(). If we have, but cannot take the
|
|
|
|
* wakeup (because of eg a pending Unix signal or timeout) then try
|
|
|
|
* to ensure that another LWP sees it. This is necessary because
|
|
|
|
* there may be multiple waiters, and at least one should take the
|
|
|
|
* wakeup if possible.
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
cv_exit(kcondvar_t *cv, kmutex_t *mtx, lwp_t *l, const int error)
|
|
|
|
{
|
|
|
|
|
|
|
|
mutex_enter(mtx);
|
2008-05-31 17:36:25 +04:00
|
|
|
if (__predict_false(error != 0))
|
2007-03-29 21:34:39 +04:00
|
|
|
cv_signal(cv);
|
|
|
|
|
2008-05-31 17:36:25 +04:00
|
|
|
LOCKDEBUG_UNLOCKED(CV_DEBUG_P(cv), cv, CV_RA, 0);
|
2008-03-05 20:05:21 +03:00
|
|
|
KASSERT(cv_is_valid(cv));
|
2007-08-02 00:30:38 +04:00
|
|
|
|
2007-03-29 21:34:39 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
/*
|
|
|
|
* cv_unsleep:
|
|
|
|
*
|
|
|
|
* Remove an LWP from the condition variable and sleep queue. This
|
|
|
|
* is called when the LWP has not been awoken normally but instead
|
|
|
|
* interrupted: for example, when a signal is received. Must be
|
|
|
|
* called with the LWP locked, and must return it unlocked.
|
|
|
|
*/
|
2009-10-22 01:11:57 +04:00
|
|
|
static void
|
2008-03-17 19:54:51 +03:00
|
|
|
cv_unsleep(lwp_t *l, bool cleanup)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
2013-10-25 19:51:36 +04:00
|
|
|
kcondvar_t *cv __diagused;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-03-05 20:05:21 +03:00
|
|
|
cv = (kcondvar_t *)(uintptr_t)l->l_wchan;
|
|
|
|
|
2008-05-31 17:36:25 +04:00
|
|
|
KASSERT(l->l_wchan == (wchan_t)cv);
|
|
|
|
KASSERT(l->l_sleepq == CV_SLEEPQ(cv));
|
2008-03-05 20:05:21 +03:00
|
|
|
KASSERT(cv_is_valid(cv));
|
2008-06-16 14:03:47 +04:00
|
|
|
KASSERT(cv_has_waiters(cv));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2009-10-22 01:11:57 +04:00
|
|
|
sleepq_unsleep(l, cleanup);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cv_wait:
|
|
|
|
*
|
|
|
|
* Wait non-interruptably on a condition variable until awoken.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cv_wait(kcondvar_t *cv, kmutex_t *mtx)
|
|
|
|
{
|
2007-03-29 21:34:39 +04:00
|
|
|
lwp_t *l = curlwp;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2007-05-17 18:51:11 +04:00
|
|
|
KASSERT(mutex_owned(mtx));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-05-31 17:36:25 +04:00
|
|
|
cv_enter(cv, mtx, l);
|
2007-05-17 18:51:11 +04:00
|
|
|
(void)sleepq_block(0, false);
|
2007-03-29 21:34:39 +04:00
|
|
|
(void)cv_exit(cv, mtx, l, 0);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cv_wait_sig:
|
|
|
|
*
|
|
|
|
* Wait on a condition variable until a awoken or a signal is received.
|
|
|
|
* Will also return early if the process is exiting. Returns zero if
|
2011-04-15 00:19:35 +04:00
|
|
|
* awoken normally, ERESTART if a signal was received and the system
|
2007-02-10 00:55:00 +03:00
|
|
|
* call is restartable, or EINTR otherwise.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
cv_wait_sig(kcondvar_t *cv, kmutex_t *mtx)
|
|
|
|
{
|
2007-03-29 21:34:39 +04:00
|
|
|
lwp_t *l = curlwp;
|
2007-02-10 00:55:00 +03:00
|
|
|
int error;
|
|
|
|
|
2007-05-17 18:51:11 +04:00
|
|
|
KASSERT(mutex_owned(mtx));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-05-31 17:36:25 +04:00
|
|
|
cv_enter(cv, mtx, l);
|
2007-05-17 18:51:11 +04:00
|
|
|
error = sleepq_block(0, true);
|
2007-03-29 21:34:39 +04:00
|
|
|
return cv_exit(cv, mtx, l, error);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cv_timedwait:
|
|
|
|
*
|
|
|
|
* Wait on a condition variable until awoken or the specified timeout
|
|
|
|
* expires. Returns zero if awoken normally or EWOULDBLOCK if the
|
|
|
|
* timeout expired.
|
2013-03-08 12:35:09 +04:00
|
|
|
*
|
|
|
|
* timo is a timeout in ticks. timo = 0 specifies an infinite timeout.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
cv_timedwait(kcondvar_t *cv, kmutex_t *mtx, int timo)
|
|
|
|
{
|
2007-03-29 21:34:39 +04:00
|
|
|
lwp_t *l = curlwp;
|
2007-02-10 00:55:00 +03:00
|
|
|
int error;
|
|
|
|
|
2007-05-17 18:51:11 +04:00
|
|
|
KASSERT(mutex_owned(mtx));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-05-31 17:36:25 +04:00
|
|
|
cv_enter(cv, mtx, l);
|
2007-05-17 18:51:11 +04:00
|
|
|
error = sleepq_block(timo, false);
|
2007-03-29 21:34:39 +04:00
|
|
|
return cv_exit(cv, mtx, l, error);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cv_timedwait_sig:
|
|
|
|
*
|
|
|
|
* Wait on a condition variable until a timeout expires, awoken or a
|
|
|
|
* signal is received. Will also return early if the process is
|
2011-04-15 00:19:35 +04:00
|
|
|
* exiting. Returns zero if awoken normally, EWOULDBLOCK if the
|
2007-02-10 00:55:00 +03:00
|
|
|
* timeout expires, ERESTART if a signal was received and the system
|
|
|
|
* call is restartable, or EINTR otherwise.
|
2013-03-08 12:36:37 +04:00
|
|
|
*
|
|
|
|
* timo is a timeout in ticks. timo = 0 specifies an infinite timeout.
|
2007-02-10 00:55:00 +03:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
cv_timedwait_sig(kcondvar_t *cv, kmutex_t *mtx, int timo)
|
|
|
|
{
|
2007-03-29 21:34:39 +04:00
|
|
|
lwp_t *l = curlwp;
|
2007-02-10 00:55:00 +03:00
|
|
|
int error;
|
|
|
|
|
2007-05-17 18:51:11 +04:00
|
|
|
KASSERT(mutex_owned(mtx));
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-05-31 17:36:25 +04:00
|
|
|
cv_enter(cv, mtx, l);
|
2007-05-17 18:51:11 +04:00
|
|
|
error = sleepq_block(timo, true);
|
2007-03-29 21:34:39 +04:00
|
|
|
return cv_exit(cv, mtx, l, error);
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cv_signal:
|
|
|
|
*
|
|
|
|
* Wake the highest priority LWP waiting on a condition variable.
|
|
|
|
* Must be called with the interlocking mutex held.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cv_signal(kcondvar_t *cv)
|
|
|
|
{
|
2008-05-31 17:36:25 +04:00
|
|
|
|
2008-06-04 15:22:55 +04:00
|
|
|
/* LOCKDEBUG_WAKEUP(CV_DEBUG_P(cv), cv, CV_RA); */
|
2008-05-31 17:36:25 +04:00
|
|
|
KASSERT(cv_is_valid(cv));
|
|
|
|
|
2008-06-16 14:03:47 +04:00
|
|
|
if (__predict_false(!TAILQ_EMPTY(CV_SLEEPQ(cv))))
|
|
|
|
cv_wakeup_one(cv);
|
2008-05-31 17:36:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __noinline
|
|
|
|
cv_wakeup_one(kcondvar_t *cv)
|
|
|
|
{
|
2007-02-10 00:55:00 +03:00
|
|
|
sleepq_t *sq;
|
2008-05-26 16:08:38 +04:00
|
|
|
kmutex_t *mp;
|
2008-05-31 17:36:25 +04:00
|
|
|
lwp_t *l;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-03-05 20:05:21 +03:00
|
|
|
KASSERT(cv_is_valid(cv));
|
|
|
|
|
2008-06-16 14:03:47 +04:00
|
|
|
mp = sleepq_hashlock(cv);
|
2008-05-31 17:36:25 +04:00
|
|
|
sq = CV_SLEEPQ(cv);
|
|
|
|
l = TAILQ_FIRST(sq);
|
|
|
|
if (l == NULL) {
|
|
|
|
mutex_spin_exit(mp);
|
2007-02-10 00:55:00 +03:00
|
|
|
return;
|
2008-05-31 17:36:25 +04:00
|
|
|
}
|
|
|
|
KASSERT(l->l_sleepq == sq);
|
|
|
|
KASSERT(l->l_mutex == mp);
|
|
|
|
KASSERT(l->l_wchan == cv);
|
2009-10-22 01:11:57 +04:00
|
|
|
sleepq_remove(sq, l);
|
2008-05-31 17:36:25 +04:00
|
|
|
mutex_spin_exit(mp);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-03-05 20:05:21 +03:00
|
|
|
KASSERT(cv_is_valid(cv));
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cv_broadcast:
|
|
|
|
*
|
|
|
|
* Wake all LWPs waiting on a condition variable. Must be called
|
|
|
|
* with the interlocking mutex held.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
cv_broadcast(kcondvar_t *cv)
|
2008-05-31 17:36:25 +04:00
|
|
|
{
|
|
|
|
|
2008-06-04 15:22:55 +04:00
|
|
|
/* LOCKDEBUG_WAKEUP(CV_DEBUG_P(cv), cv, CV_RA); */
|
2008-05-31 17:36:25 +04:00
|
|
|
KASSERT(cv_is_valid(cv));
|
|
|
|
|
2008-06-16 14:03:47 +04:00
|
|
|
if (__predict_false(!TAILQ_EMPTY(CV_SLEEPQ(cv))))
|
|
|
|
cv_wakeup_all(cv);
|
2008-05-31 17:36:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __noinline
|
|
|
|
cv_wakeup_all(kcondvar_t *cv)
|
2007-02-10 00:55:00 +03:00
|
|
|
{
|
|
|
|
sleepq_t *sq;
|
2008-05-26 16:08:38 +04:00
|
|
|
kmutex_t *mp;
|
2008-05-31 17:36:25 +04:00
|
|
|
lwp_t *l, *next;
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-03-05 20:05:21 +03:00
|
|
|
KASSERT(cv_is_valid(cv));
|
|
|
|
|
2008-06-16 14:03:47 +04:00
|
|
|
mp = sleepq_hashlock(cv);
|
|
|
|
sq = CV_SLEEPQ(cv);
|
2008-05-31 17:36:25 +04:00
|
|
|
for (l = TAILQ_FIRST(sq); l != NULL; l = next) {
|
|
|
|
KASSERT(l->l_sleepq == sq);
|
|
|
|
KASSERT(l->l_mutex == mp);
|
|
|
|
KASSERT(l->l_wchan == cv);
|
|
|
|
next = TAILQ_NEXT(l, l_sleepchain);
|
2009-10-22 01:11:57 +04:00
|
|
|
sleepq_remove(sq, l);
|
2008-05-31 17:36:25 +04:00
|
|
|
}
|
|
|
|
mutex_spin_exit(mp);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2008-03-05 20:05:21 +03:00
|
|
|
KASSERT(cv_is_valid(cv));
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cv_has_waiters:
|
|
|
|
*
|
|
|
|
* For diagnostic assertions: return non-zero if a condition
|
|
|
|
* variable has waiters.
|
|
|
|
*/
|
2007-03-29 21:39:34 +04:00
|
|
|
bool
|
2007-02-10 00:55:00 +03:00
|
|
|
cv_has_waiters(kcondvar_t *cv)
|
|
|
|
{
|
2008-06-15 13:56:18 +04:00
|
|
|
|
2008-06-16 16:03:01 +04:00
|
|
|
return !TAILQ_EMPTY(CV_SLEEPQ(cv));
|
2007-02-10 00:55:00 +03:00
|
|
|
}
|
2008-03-05 20:05:21 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* cv_is_valid:
|
|
|
|
*
|
|
|
|
* For diagnostic assertions: return non-zero if a condition
|
|
|
|
* variable appears to be valid. No locks need be held.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
cv_is_valid(kcondvar_t *cv)
|
|
|
|
{
|
|
|
|
|
2008-12-19 10:57:28 +03:00
|
|
|
return CV_WMESG(cv) != deadcv && CV_WMESG(cv) != NULL;
|
2008-03-05 20:05:21 +03:00
|
|
|
}
|