taskqueue_drain man page on DragonFly

Man page or keyword search:  
man Server   44335 pages
apropos Keyword Search (all sections)
Output format
DragonFly logo
[printable version]

TASKQUEUE(9)		 BSD Kernel Developer's Manual		  TASKQUEUE(9)

NAME
     taskqueue_block, taskqueue_create, tastqueue_drain, taskqueue_enqueue,
     taskqueue_free, taskqueue_find, taskqueue_run, taskqueue_start_threads,
     taskqueue_unblock, TASK_INIT, TASKQUEUE_DECLARE, TASKQUEUE_DEFINE — asyn‐
     chronous task execution

SYNOPSIS
     #include <sys/param.h>
     #include <sys/kernel.h>
     #include <sys/malloc.h>
     #include <sys/queue.h>
     #include <sys/taskqueue.h>

     typedef void (*task_fn_t)(void *context, int pending);

     typedef void (*taskqueue_enqueue_fn)(void *context);

     struct task {
	     STAILQ_ENTRY(task)	     ta_link;	     /* link for queue */
	     int		     ta_pending;     /* count times queued */
	     int		     ta_priority;    /* priority of task in queue */
	     task_fn_t		     ta_func;	     /* task handler */
	     void		     *ta_context;    /* argument for handler */
     };

     struct taskqueue *
     taskqueue_create(const char *name, int mflags,
	 taskqueue_enqueue_fn enqueue, void *context);

     void
     taskqueue_free(struct taskqueue *queue);

     struct taskqueue *
     taskqueue_find(const char *name);

     int
     taskqueue_enqueue(struct taskqueue *queue, struct task *task);

     void
     taskqueue_run(struct taskqueue *queue);

     void
     taskqueue_drain(struct taskqueue *queue, struct task *task);

     void
     taskqueue_block(struct taskqueue *queue);

     void
     taskqueue_unblock(struct taskqueue *queue);

     int
     taskqueue_start_threads(struct taskqueue **tqp, int count, int pri,
	 int ncpu, const char *fmt, ...);

     TASK_INIT(struct task *task, int priority, task_fn_t *func,
	 void *context);

     TASKQUEUE_DECLARE(name);

     TASKQUEUE_DEFINE(name, taskqueue_enqueue_fn enqueue, void *context,
	 init);

DESCRIPTION
     These functions provide a simple interface for asynchronous execution of
     code.

     The function taskqueue_create() is used to create new queues.  The argu‐
     ments to taskqueue_create() include a name that should be unique, a set
     of kmalloc(9) flags that specify whether the call to malloc() is allowed
     to sleep, and a function which is called from taskqueue_enqueue() when a
     task is added to the queue to allow the queue to arrange to be run later
     (for instance by scheduling a software interrupt or waking a kernel
     thread).

     The function taskqueue_free() should be used to remove the queue from the
     global list of queues and free the memory used by the queue.  Any tasks
     that are on the queue will be executed at this time.

     The system maintains a list of all queues which can be searched using
     taskqueue_find().	The first queue whose name matches is returned, other‐
     wise NULL.

     To add a task to the list of tasks queued on a taskqueue, call
     taskqueue_enqueue() with pointers to the queue and task.  If the task's
     ta_pending field is non-zero, then it is simply incremented to reflect
     the number of times the task was enqueued.	 Otherwise, the task is added
     to the list before the first task which has a lower ta_priority value or
     at the end of the list if no tasks have a lower priority.	Enqueueing a
     task does not perform any memory allocation which makes it suitable for
     calling from an interrupt handler.	 This function will return EPIPE if
     the queue is being freed.

     To execute all the tasks on a queue, call taskqueue_run().	 When a task
     is executed, first it is removed from the queue, the value of ta_pending
     is recorded and then the field is zeroed.	The function ta_func from the
     task structure is called with the value of the field ta_context as its
     first argument and the value of ta_pending as its second argument.

     The taskqueue_drain() function is used to wait for the task to finish.
     There is no guarantee that the task will not be enqueued after call to
     taskqueue_drain().

     The taskqueue_block() function is used to block a taskqueue.  When a
     taskqueue is blocked, calls to taskqueue_enqueue() will still enqueue
     tasks but they will not be run until the taskqueue is unblocked by call‐
     ing taskqueue_unblock().

     The taskqueue_start_threads() function is used to create and start count
     dedicated threads for the taskqueue specified by tqp.  These threads will
     be created with the priority specified by pri and the name given by fmt
     with _N appended to it, where N is the number of the thread.  If count >
     1 and ncpu is -1, each of the count threads will be allocated to a dif‐
     ferent CPU among all available CPUs in a round robin fashion.  The
     taskqueue specified by tqp must be created previously by calling
     taskqueue_create() with the argument enqueue set to
     taskqueue_thread_enqueue.

     A convenience macro, TASK_INIT() is provided to initialise a task struc‐
     ture.  The values of priority, func, and context are simply copied into
     the task structure fields and the ta_pending field is cleared.

     Two macros, TASKQUEUE_DECLARE() and TASKQUEUE_DEFINE() are used to
     declare a reference to a global queue, and to define the implementation
     of the queue.  The TASKQUEUE_DEFINE() macro arranges to call
     taskqueue_create() with the values of its name, enqueue and context argu‐
     ments during system initialisation.  After calling taskqueue_create(),
     the init argument to the macro is executed as a C statement, allowing any
     further initialisation to be performed (such as registering an interrupt
     handler etc.)

     The system provides two global taskqueues, taskqueue_swi and
     taskqueue_swi_mp, which are run via a software interrupt mechanism.  To
     use these queues, call taskqueue_enqueue() with the value of the global
     variable taskqueue_swi or taskqueue_swi_mp.

     While taskqueue_swi acquires the mplock for its tasks, taskqueue_swi_mp
     is intended for mpsafe tasks and no mplock will be acquired for them.
     These queues can be used, for instance, for implementing interrupt han‐
     dlers which must perform a significant amount of processing in the han‐
     dler.  The hardware interrupt handler would perform minimal processing of
     the interrupt and then enqueue a task to finish the work.	This reduces
     to a minimum the amount of time spent with interrupts disabled.

HISTORY
     This interface first appeared in FreeBSD 5.0.  There is a similar facil‐
     ity called tqueue in the Linux kernel.

AUTHORS
     This manual page was written by Doug Rabson.

BSD				October 2, 2009				   BSD
[top]

List of man pages available for DragonFly

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net