1*8f8cb840SMaxim Sobolev /*-
2*8f8cb840SMaxim Sobolev * Copyright (c) 2006-2016 Maxim Sobolev <sobomax@FreeBSD.org>
3*8f8cb840SMaxim Sobolev * All rights reserved.
4*8f8cb840SMaxim Sobolev *
5*8f8cb840SMaxim Sobolev * Redistribution and use in source and binary forms, with or without
6*8f8cb840SMaxim Sobolev * modification, are permitted provided that the following conditions
7*8f8cb840SMaxim Sobolev * are met:
8*8f8cb840SMaxim Sobolev * 1. Redistributions of source code must retain the above copyright
9*8f8cb840SMaxim Sobolev * notice, this list of conditions and the following disclaimer.
10*8f8cb840SMaxim Sobolev * 2. Redistributions in binary form must reproduce the above copyright
11*8f8cb840SMaxim Sobolev * notice, this list of conditions and the following disclaimer in the
12*8f8cb840SMaxim Sobolev * documentation and/or other materials provided with the distribution.
13*8f8cb840SMaxim Sobolev *
14*8f8cb840SMaxim Sobolev * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*8f8cb840SMaxim Sobolev * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*8f8cb840SMaxim Sobolev * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*8f8cb840SMaxim Sobolev * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*8f8cb840SMaxim Sobolev * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*8f8cb840SMaxim Sobolev * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*8f8cb840SMaxim Sobolev * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*8f8cb840SMaxim Sobolev * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*8f8cb840SMaxim Sobolev * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*8f8cb840SMaxim Sobolev * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*8f8cb840SMaxim Sobolev * SUCH DAMAGE.
25*8f8cb840SMaxim Sobolev */
26*8f8cb840SMaxim Sobolev
27*8f8cb840SMaxim Sobolev #include <sys/types.h>
28*8f8cb840SMaxim Sobolev #include <sys/param.h>
29*8f8cb840SMaxim Sobolev #include <sys/lock.h>
30*8f8cb840SMaxim Sobolev #include <sys/mutex.h>
31*8f8cb840SMaxim Sobolev #include <sys/bio.h>
32*8f8cb840SMaxim Sobolev #include <sys/proc.h>
33*8f8cb840SMaxim Sobolev #include <sys/sched.h>
34*8f8cb840SMaxim Sobolev #include <sys/kthread.h>
35*8f8cb840SMaxim Sobolev #include <sys/malloc.h>
36*8f8cb840SMaxim Sobolev
37*8f8cb840SMaxim Sobolev #include <geom/uzip/g_uzip.h>
38*8f8cb840SMaxim Sobolev #include <geom/uzip/g_uzip_softc.h>
39*8f8cb840SMaxim Sobolev #include <geom/uzip/g_uzip_wrkthr.h>
40*8f8cb840SMaxim Sobolev
41*8f8cb840SMaxim Sobolev void
g_uzip_wrkthr(void * arg)42*8f8cb840SMaxim Sobolev g_uzip_wrkthr(void *arg)
43*8f8cb840SMaxim Sobolev {
44*8f8cb840SMaxim Sobolev struct g_uzip_softc *sc;
45*8f8cb840SMaxim Sobolev struct bio *bp;
46*8f8cb840SMaxim Sobolev
47*8f8cb840SMaxim Sobolev sc = (struct g_uzip_softc *)arg;
48*8f8cb840SMaxim Sobolev thread_lock(curthread);
49*8f8cb840SMaxim Sobolev sched_prio(curthread, PRIBIO);
50*8f8cb840SMaxim Sobolev thread_unlock(curthread);
51*8f8cb840SMaxim Sobolev
52*8f8cb840SMaxim Sobolev for (;;) {
53*8f8cb840SMaxim Sobolev mtx_lock(&sc->queue_mtx);
54*8f8cb840SMaxim Sobolev if (sc->wrkthr_flags & GUZ_SHUTDOWN) {
55*8f8cb840SMaxim Sobolev sc->wrkthr_flags |= GUZ_EXITING;
56*8f8cb840SMaxim Sobolev mtx_unlock(&sc->queue_mtx);
57*8f8cb840SMaxim Sobolev kproc_exit(0);
58*8f8cb840SMaxim Sobolev }
59*8f8cb840SMaxim Sobolev bp = bioq_takefirst(&sc->bio_queue);
60*8f8cb840SMaxim Sobolev if (!bp) {
61*8f8cb840SMaxim Sobolev msleep(sc, &sc->queue_mtx, PRIBIO | PDROP,
62*8f8cb840SMaxim Sobolev "wrkwait", 0);
63*8f8cb840SMaxim Sobolev continue;
64*8f8cb840SMaxim Sobolev }
65*8f8cb840SMaxim Sobolev mtx_unlock(&sc->queue_mtx);
66*8f8cb840SMaxim Sobolev sc->uzip_do(sc, bp);
67*8f8cb840SMaxim Sobolev }
68*8f8cb840SMaxim Sobolev }
69