taskqueue.h revision 124882
161033Sdfr/*- 261033Sdfr * Copyright (c) 2000 Doug Rabson 361033Sdfr * All rights reserved. 461033Sdfr * 561033Sdfr * Redistribution and use in source and binary forms, with or without 661033Sdfr * modification, are permitted provided that the following conditions 761033Sdfr * are met: 861033Sdfr * 1. Redistributions of source code must retain the above copyright 961033Sdfr * notice, this list of conditions and the following disclaimer. 1061033Sdfr * 2. Redistributions in binary form must reproduce the above copyright 1161033Sdfr * notice, this list of conditions and the following disclaimer in the 1261033Sdfr * documentation and/or other materials provided with the distribution. 1361033Sdfr * 1461033Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1561033Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1661033Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1761033Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1861033Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1961033Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2061033Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2161033Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2261033Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2361033Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2461033Sdfr * SUCH DAMAGE. 2561033Sdfr * 2661086Sdfr * $FreeBSD: head/sys/sys/taskqueue.h 124882 2004-01-23 20:44:26Z rwatson $ 2761033Sdfr */ 2861033Sdfr 2961033Sdfr#ifndef _SYS_TASKQUEUE_H_ 3061033Sdfr#define _SYS_TASKQUEUE_H_ 3161033Sdfr 3261086Sdfr#ifndef _KERNEL 3361086Sdfr#error "no user-servicable parts inside" 3461086Sdfr#endif 3561033Sdfr 3661086Sdfr#include <sys/queue.h> 37124882Srwatson#include <sys/_task.h> 3861086Sdfr 3961033Sdfrstruct taskqueue; 4061033Sdfr 4161033Sdfr/* 4261033Sdfr * A notification callback function which is called from 4361086Sdfr * taskqueue_enqueue(). The context argument is given in the call to 4461086Sdfr * taskqueue_create(). This function would normally be used to allow the 4561086Sdfr * queue to arrange to run itself later (e.g., by scheduling a software 4661033Sdfr * interrupt or waking a kernel thread). 4761033Sdfr */ 4861033Sdfrtypedef void (*taskqueue_enqueue_fn)(void *context); 4961033Sdfr 5061086Sdfrstruct taskqueue *taskqueue_create(const char *name, int mflags, 5161086Sdfr taskqueue_enqueue_fn enqueue, 5261086Sdfr void *context); 5361086Sdfrint taskqueue_enqueue(struct taskqueue *queue, struct task *task); 5461086Sdfrstruct taskqueue *taskqueue_find(const char *name); 5561086Sdfrvoid taskqueue_free(struct taskqueue *queue); 5661086Sdfrvoid taskqueue_run(struct taskqueue *queue); 5761033Sdfr 5861033Sdfr/* 5961033Sdfr * Initialise a task structure. 6061033Sdfr */ 6185560Sjhb#define TASK_INIT(task, priority, func, context) do { \ 6285560Sjhb (task)->ta_pending = 0; \ 6385560Sjhb (task)->ta_priority = (priority); \ 6485560Sjhb (task)->ta_func = (func); \ 6585560Sjhb (task)->ta_context = (context); \ 6685560Sjhb} while (0) 6761033Sdfr 6861033Sdfr/* 6961033Sdfr * Declare a reference to a taskqueue. 7061033Sdfr */ 7161033Sdfr#define TASKQUEUE_DECLARE(name) \ 7261033Sdfrextern struct taskqueue *taskqueue_##name 7361033Sdfr 7461033Sdfr/* 7561033Sdfr * Define and initialise a taskqueue. 7661033Sdfr */ 7761086Sdfr#define TASKQUEUE_DEFINE(name, enqueue, context, init) \ 7861033Sdfr \ 7961033Sdfrstruct taskqueue *taskqueue_##name; \ 8061033Sdfr \ 8161033Sdfrstatic void \ 8261033Sdfrtaskqueue_define_##name(void *arg) \ 8361033Sdfr{ \ 8461033Sdfr taskqueue_##name = \ 8561086Sdfr taskqueue_create(#name, M_NOWAIT, (enqueue), (context)); \ 8661033Sdfr init; \ 8761033Sdfr} \ 8861033Sdfr \ 8961033SdfrSYSINIT(taskqueue_##name, SI_SUB_CONFIGURE, SI_ORDER_SECOND, \ 9061086Sdfr taskqueue_define_##name, NULL) \ 9161086Sdfr \ 9261086Sdfrstruct __hack 9361033Sdfr 9461033Sdfr/* 95119708Sken * These queues are serviced by software interrupt handlers. To enqueue 96119708Sken * a task, call taskqueue_enqueue(taskqueue_swi, &task) or 97119708Sken * taskqueue_enqueue(taskqueue_swi_giant, &task). 9861033Sdfr */ 99111528SscottlTASKQUEUE_DECLARE(swi_giant); 10061033SdfrTASKQUEUE_DECLARE(swi); 10161033Sdfr 102119708Sken/* 103119708Sken * This queue is serviced by a kernel thread. To enqueue a task, call 104119708Sken * taskqueue_enqueue(taskqueue_thread, &task). 105119708Sken */ 106119708SkenTASKQUEUE_DECLARE(thread); 107119708Sken 108119789Ssam/* 109119789Ssam * Queue for swi handlers dispatched from fast interrupt handlers. 110119789Ssam * These are necessarily different from the above because the queue 111119789Ssam * must be locked with spinlocks since sleep mutex's cannot be used 112119789Ssam * from a fast interrupt handler context. 113119789Ssam */ 114119789SsamTASKQUEUE_DECLARE(fast); 115119789Ssamint taskqueue_enqueue_fast(struct taskqueue *queue, struct task *task); 116119789Ssam 11761033Sdfr#endif /* !_SYS_TASKQUEUE_H_ */ 118