]> git.proxmox.com Git - mirror_spl.git/blob - include/sys/taskq.h
Fix taskq_wait() not waiting bug
[mirror_spl.git] / include / sys / taskq.h
1 /*
2 * This file is part of the SPL: Solaris Porting Layer.
3 *
4 * Copyright (c) 2008 Lawrence Livermore National Security, LLC.
5 * Produced at Lawrence Livermore National Laboratory
6 * Written by:
7 * Brian Behlendorf <behlendorf1@llnl.gov>,
8 * Herb Wartens <wartens2@llnl.gov>,
9 * Jim Garlick <garlick@llnl.gov>
10 * UCRL-CODE-235197
11 *
12 * This is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 */
26
27 #ifndef _SPL_TASKQ_H
28 #define _SPL_TASKQ_H
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #include <linux/module.h>
35 #include <linux/gfp.h>
36 #include <linux/slab.h>
37 #include <linux/interrupt.h>
38 #include <linux/kthread.h>
39 #include <sys/types.h>
40 #include <sys/thread.h>
41
42 #define TASKQ_NAMELEN 31
43
44 #define TASKQ_PREPOPULATE 0x00000001
45 #define TASKQ_CPR_SAFE 0x00000002
46 #define TASKQ_DYNAMIC 0x00000004
47
48 typedef unsigned long taskqid_t;
49 typedef void (task_func_t)(void *);
50
51 /*
52 * Flags for taskq_dispatch. TQ_SLEEP/TQ_NOSLEEP should be same as
53 * KM_SLEEP/KM_NOSLEEP. TQ_NOQUEUE/TQ_NOALLOC are set particularly
54 * large so as not to conflict with already used GFP_* defines.
55 */
56 #define TQ_SLEEP KM_SLEEP
57 #define TQ_NOSLEEP KM_NOSLEEP
58 #define TQ_NOQUEUE 0x01000000
59 #define TQ_NOALLOC 0x02000000
60 #define TQ_NEW 0x04000000
61 #define TQ_ACTIVE 0x80000000
62
63 typedef struct taskq {
64 spinlock_t tq_lock; /* protects taskq_t */
65 unsigned long tq_lock_flags; /* interrupt state */
66 struct task_struct **tq_threads; /* thread pointers */
67 const char *tq_name; /* taskq name */
68 int tq_nactive; /* # of active threads */
69 int tq_nthreads; /* # of total threads */
70 int tq_pri; /* priority */
71 int tq_minalloc; /* min task_t pool size */
72 int tq_maxalloc; /* max task_t pool size */
73 int tq_nalloc; /* cur task_t pool size */
74 uint_t tq_flags; /* flags */
75 taskqid_t tq_next_id; /* next pend/work id */
76 taskqid_t tq_lowest_id; /* lowest pend/work id */
77 struct list_head tq_free_list; /* free task_t's */
78 struct list_head tq_work_list; /* work task_t's */
79 struct list_head tq_pend_list; /* pending task_t's */
80 wait_queue_head_t tq_work_waitq; /* new work waitq */
81 wait_queue_head_t tq_wait_waitq; /* wait waitq */
82 } taskq_t;
83
84 /* Global system-wide dynamic task queue available for all consumers */
85 extern taskq_t *system_taskq;
86
87 extern taskqid_t __taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
88 extern taskq_t *__taskq_create(const char *, int, pri_t, int, int, uint_t);
89 extern void __taskq_destroy(taskq_t *);
90 extern void __taskq_wait_id(taskq_t *, taskqid_t);
91 extern void __taskq_wait(taskq_t *);
92 extern int __taskq_member(taskq_t *, void *);
93
94 int spl_taskq_init(void);
95 void spl_taskq_fini(void);
96
97 #define taskq_member(tq, t) __taskq_member(tq, t)
98 #define taskq_wait_id(tq, id) __taskq_wait_id(tq, id)
99 #define taskq_wait(tq) __taskq_wait(tq)
100 #define taskq_dispatch(tq, f, p, fl) __taskq_dispatch(tq, f, p, fl)
101 #define taskq_create(n, th, p, mi, ma, fl) __taskq_create(n, th, p, mi, ma, fl)
102 #define taskq_destroy(tq) __taskq_destroy(tq)
103
104 #ifdef __cplusplus
105 }
106 #endif
107
108 #endif /* _SPL_TASKQ_H */