1303167Ssobomax/*- 2303167Ssobomax * Copyright (c) 2006-2016 Maxim Sobolev <sobomax@FreeBSD.org> 3303167Ssobomax * All rights reserved. 4303167Ssobomax * 5303167Ssobomax * Redistribution and use in source and binary forms, with or without 6303167Ssobomax * modification, are permitted provided that the following conditions 7303167Ssobomax * are met: 8303167Ssobomax * 1. Redistributions of source code must retain the above copyright 9303167Ssobomax * notice, this list of conditions and the following disclaimer. 10303167Ssobomax * 2. Redistributions in binary form must reproduce the above copyright 11303167Ssobomax * notice, this list of conditions and the following disclaimer in the 12303167Ssobomax * documentation and/or other materials provided with the distribution. 13303167Ssobomax * 14303167Ssobomax * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15303167Ssobomax * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16303167Ssobomax * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17303167Ssobomax * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18303167Ssobomax * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19303167Ssobomax * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20303167Ssobomax * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21303167Ssobomax * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22303167Ssobomax * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23303167Ssobomax * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24303167Ssobomax * SUCH DAMAGE. 25303167Ssobomax */ 26303167Ssobomax 27303167Ssobomax#include <sys/cdefs.h> 28303167Ssobomax__FBSDID("$FreeBSD$"); 29303167Ssobomax 30303167Ssobomax#include <sys/types.h> 31303167Ssobomax#include <sys/param.h> 32303167Ssobomax#include <sys/lock.h> 33303167Ssobomax#include <sys/mutex.h> 34303167Ssobomax#include <sys/bio.h> 35303167Ssobomax#include <sys/systm.h> 36303167Ssobomax#include <sys/proc.h> 37303167Ssobomax#include <sys/sched.h> 38303167Ssobomax#include <sys/kthread.h> 39303167Ssobomax#include <sys/malloc.h> 40303167Ssobomax 41303167Ssobomax#include <geom/uzip/g_uzip.h> 42303167Ssobomax#include <geom/uzip/g_uzip_softc.h> 43303167Ssobomax#include <geom/uzip/g_uzip_wrkthr.h> 44303167Ssobomax 45303167Ssobomaxvoid 46303167Ssobomaxg_uzip_wrkthr(void *arg) 47303167Ssobomax{ 48303167Ssobomax struct g_uzip_softc *sc; 49303167Ssobomax struct bio *bp; 50303167Ssobomax 51303167Ssobomax sc = (struct g_uzip_softc *)arg; 52303167Ssobomax thread_lock(curthread); 53303167Ssobomax sched_prio(curthread, PRIBIO); 54303167Ssobomax thread_unlock(curthread); 55303167Ssobomax 56303167Ssobomax for (;;) { 57303167Ssobomax mtx_lock(&sc->queue_mtx); 58303167Ssobomax if (sc->wrkthr_flags & GUZ_SHUTDOWN) { 59303167Ssobomax sc->wrkthr_flags |= GUZ_EXITING; 60303167Ssobomax mtx_unlock(&sc->queue_mtx); 61303167Ssobomax kproc_exit(0); 62303167Ssobomax } 63303167Ssobomax bp = bioq_takefirst(&sc->bio_queue); 64303167Ssobomax if (!bp) { 65303167Ssobomax msleep(sc, &sc->queue_mtx, PRIBIO | PDROP, 66303167Ssobomax "wrkwait", 0); 67303167Ssobomax continue; 68303167Ssobomax } 69303167Ssobomax mtx_unlock(&sc->queue_mtx); 70303167Ssobomax sc->uzip_do(sc, bp); 71303167Ssobomax } 72303167Ssobomax} 73