/* $NetBSD: ltsleep.c,v 1.36 2020/03/14 20:23:51 ad Exp $ */
/*
* Copyright (c) 2009, 2010 Antti Kantee. All Rights Reserved.
*
* 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 AUTHOR ``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 AUTHOR 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.
*/
/*
* Implementation of the tsleep/mtsleep kernel sleep interface. There
* are two sides to our implementation. For historic spinlocks we
* assume the kernel is giantlocked and use kernel giantlock as the
* wait interlock. For mtsleep, we use the interlock supplied by
* the caller. This duality leads to some if/else messiness in the code ...
*/
if (kinterlock)
cv_destroy(<s.kcv);
else
rumpuser_cv_destroy(lts.ucv);
return rv;
}
int
tsleep(wchan_t ident, pri_t prio, const char *wmesg, int timo)
{
int rv, nlocks;
/*
* Since we cannot use slock as the rumpuser interlock,
* require that everyone using this prehistoric interface
* is biglocked. Wrap around the biglock and drop lockcnt,
* but retain the rumpuser mutex so that we can use it as an
* interlock to rumpuser_cv_wait().
*/
rump_kernel_bigwrap(&nlocks);
mutex_spin_enter(&qlock);
rv = sleeper(ident, timo, false);
rump_kernel_bigunwrap(nlocks);
return rv;
}
int
mtsleep(wchan_t ident, pri_t prio, const char *wmesg, int timo, kmutex_t *lock)
{
int rv;