Lines Matching refs:tq

89 task_alloc(taskq_t *tq, int tqflags)  in task_alloc()  argument
94 again: if ((t = tq->tq_freelist) != NULL && tq->tq_nalloc >= tq->tq_minalloc) { in task_alloc()
95 tq->tq_freelist = t->tqent_next; in task_alloc()
97 if (tq->tq_nalloc >= tq->tq_maxalloc) { in task_alloc()
111 tq->tq_maxalloc_wait++; in task_alloc()
112 rv = cv_timedwait(&tq->tq_maxalloc_cv, in task_alloc()
113 &tq->tq_lock, ddi_get_lbolt() + hz); in task_alloc()
114 tq->tq_maxalloc_wait--; in task_alloc()
118 mutex_exit(&tq->tq_lock); in task_alloc()
122 mutex_enter(&tq->tq_lock); in task_alloc()
124 tq->tq_nalloc++; in task_alloc()
130 task_free(taskq_t *tq, taskq_ent_t *t) in task_free() argument
132 if (tq->tq_nalloc <= tq->tq_minalloc) { in task_free()
133 t->tqent_next = tq->tq_freelist; in task_free()
134 tq->tq_freelist = t; in task_free()
136 tq->tq_nalloc--; in task_free()
137 mutex_exit(&tq->tq_lock); in task_free()
139 mutex_enter(&tq->tq_lock); in task_free()
142 if (tq->tq_maxalloc_wait) in task_free()
143 cv_signal(&tq->tq_maxalloc_cv); in task_free()
147 taskq_dispatch(taskq_t *tq, task_func_t func, void *arg, uint_t tqflags) in taskq_dispatch() argument
156 mutex_enter(&tq->tq_lock); in taskq_dispatch()
157 ASSERT(tq->tq_flags & TASKQ_ACTIVE); in taskq_dispatch()
158 if ((t = task_alloc(tq, tqflags)) == NULL) { in taskq_dispatch()
159 mutex_exit(&tq->tq_lock); in taskq_dispatch()
163 t->tqent_next = tq->tq_task.tqent_next; in taskq_dispatch()
164 t->tqent_prev = &tq->tq_task; in taskq_dispatch()
166 t->tqent_next = &tq->tq_task; in taskq_dispatch()
167 t->tqent_prev = tq->tq_task.tqent_prev; in taskq_dispatch()
174 cv_signal(&tq->tq_dispatch_cv); in taskq_dispatch()
175 mutex_exit(&tq->tq_lock); in taskq_dispatch()
180 taskq_dispatch_ent(taskq_t *tq, task_func_t func, void *arg, uint_t flags, in taskq_dispatch_ent() argument
184 ASSERT(!(tq->tq_flags & TASKQ_DYNAMIC)); in taskq_dispatch_ent()
194 mutex_enter(&tq->tq_lock); in taskq_dispatch_ent()
197 t->tqent_next = tq->tq_task.tqent_next; in taskq_dispatch_ent()
198 t->tqent_prev = &tq->tq_task; in taskq_dispatch_ent()
200 t->tqent_next = &tq->tq_task; in taskq_dispatch_ent()
201 t->tqent_prev = tq->tq_task.tqent_prev; in taskq_dispatch_ent()
207 cv_signal(&tq->tq_dispatch_cv); in taskq_dispatch_ent()
208 mutex_exit(&tq->tq_lock); in taskq_dispatch_ent()
212 taskq_wait(taskq_t *tq) in taskq_wait() argument
214 mutex_enter(&tq->tq_lock); in taskq_wait()
215 while (tq->tq_task.tqent_next != &tq->tq_task || tq->tq_active != 0) in taskq_wait()
216 cv_wait(&tq->tq_wait_cv, &tq->tq_lock); in taskq_wait()
217 mutex_exit(&tq->tq_lock); in taskq_wait()
223 taskq_t *tq = arg; in taskq_thread() local
227 mutex_enter(&tq->tq_lock); in taskq_thread()
228 while (tq->tq_flags & TASKQ_ACTIVE) { in taskq_thread()
229 if ((t = tq->tq_task.tqent_next) == &tq->tq_task) { in taskq_thread()
230 if (--tq->tq_active == 0) in taskq_thread()
231 cv_broadcast(&tq->tq_wait_cv); in taskq_thread()
232 cv_wait(&tq->tq_dispatch_cv, &tq->tq_lock); in taskq_thread()
233 tq->tq_active++; in taskq_thread()
241 mutex_exit(&tq->tq_lock); in taskq_thread()
243 rw_enter(&tq->tq_threadlock, RW_READER); in taskq_thread()
245 rw_exit(&tq->tq_threadlock); in taskq_thread()
247 mutex_enter(&tq->tq_lock); in taskq_thread()
249 task_free(tq, t); in taskq_thread()
251 tq->tq_nthreads--; in taskq_thread()
252 cv_broadcast(&tq->tq_wait_cv); in taskq_thread()
253 mutex_exit(&tq->tq_lock); in taskq_thread()
271 taskq_t *tq = kmem_zalloc(sizeof (taskq_t), KM_SLEEP); in taskq_create_proc() local
287 rw_init(&tq->tq_threadlock, NULL, RW_DEFAULT, NULL); in taskq_create_proc()
288 mutex_init(&tq->tq_lock, NULL, MUTEX_DEFAULT, NULL); in taskq_create_proc()
289 cv_init(&tq->tq_dispatch_cv, NULL, CV_DEFAULT, NULL); in taskq_create_proc()
290 cv_init(&tq->tq_wait_cv, NULL, CV_DEFAULT, NULL); in taskq_create_proc()
291 cv_init(&tq->tq_maxalloc_cv, NULL, CV_DEFAULT, NULL); in taskq_create_proc()
292 tq->tq_flags = flags | TASKQ_ACTIVE; in taskq_create_proc()
293 tq->tq_active = nthreads; in taskq_create_proc()
294 tq->tq_nthreads = nthreads; in taskq_create_proc()
295 tq->tq_minalloc = minalloc; in taskq_create_proc()
296 tq->tq_maxalloc = maxalloc; in taskq_create_proc()
297 tq->tq_task.tqent_next = &tq->tq_task; in taskq_create_proc()
298 tq->tq_task.tqent_prev = &tq->tq_task; in taskq_create_proc()
299 tq->tq_threadlist = kmem_alloc(nthreads * sizeof (thread_t), KM_SLEEP); in taskq_create_proc()
302 mutex_enter(&tq->tq_lock); in taskq_create_proc()
304 task_free(tq, task_alloc(tq, KM_SLEEP)); in taskq_create_proc()
305 mutex_exit(&tq->tq_lock); in taskq_create_proc()
310 tq, THR_BOUND, &tq->tq_threadlist[t]); in taskq_create_proc()
312 return (tq); in taskq_create_proc()
316 taskq_destroy(taskq_t *tq) in taskq_destroy() argument
319 int nthreads = tq->tq_nthreads; in taskq_destroy()
321 taskq_wait(tq); in taskq_destroy()
323 mutex_enter(&tq->tq_lock); in taskq_destroy()
325 tq->tq_flags &= ~TASKQ_ACTIVE; in taskq_destroy()
326 cv_broadcast(&tq->tq_dispatch_cv); in taskq_destroy()
328 while (tq->tq_nthreads != 0) in taskq_destroy()
329 cv_wait(&tq->tq_wait_cv, &tq->tq_lock); in taskq_destroy()
331 tq->tq_minalloc = 0; in taskq_destroy()
332 while (tq->tq_nalloc != 0) { in taskq_destroy()
333 ASSERT(tq->tq_freelist != NULL); in taskq_destroy()
334 task_free(tq, task_alloc(tq, KM_SLEEP)); in taskq_destroy()
337 mutex_exit(&tq->tq_lock); in taskq_destroy()
340 (void) thr_join(tq->tq_threadlist[t], NULL, NULL); in taskq_destroy()
342 kmem_free(tq->tq_threadlist, nthreads * sizeof (thread_t)); in taskq_destroy()
344 rw_destroy(&tq->tq_threadlock); in taskq_destroy()
345 mutex_destroy(&tq->tq_lock); in taskq_destroy()
346 cv_destroy(&tq->tq_dispatch_cv); in taskq_destroy()
347 cv_destroy(&tq->tq_wait_cv); in taskq_destroy()
348 cv_destroy(&tq->tq_maxalloc_cv); in taskq_destroy()
350 kmem_free(tq, sizeof (taskq_t)); in taskq_destroy()
354 taskq_member(taskq_t *tq, struct _kthread *t) in taskq_member() argument
361 for (i = 0; i < tq->tq_nthreads; i++) in taskq_member()
362 if (tq->tq_threadlist[i] == (thread_t)(uintptr_t)t) in taskq_member()