Home | History | Annotate | Line # | Download | only in sys
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the "License").
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets "[]" replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 /*
     22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     23  * Use is subject to license terms.
     24  */
     25 
     26 #ifndef	_SYS_TASKQ_H
     27 #define	_SYS_TASKQ_H
     28 
     29 #include <sys/types.h>
     30 #include <sys/proc.h>
     31 #ifdef __FreeBSD__
     32 #include <sys/taskqueue.h>
     33 #endif
     34 
     35 #ifdef	__cplusplus
     36 extern "C" {
     37 #endif
     38 
     39 #define	TASKQ_NAMELEN	31
     40 
     41 #ifdef __FreeBSD__
     42 struct taskqueue;
     43 struct taskq {
     44 	struct taskqueue	*tq_queue;
     45 };
     46 typedef struct taskq_ent {
     47 	struct task	 tqent_task;
     48 	task_func_t	*tqent_func;
     49 	void		*tqent_arg;
     50 } taskq_ent_t;
     51 #endif
     52 
     53 typedef struct taskq taskq_t;
     54 typedef uintptr_t taskqid_t;
     55 typedef void (task_func_t)(void *);
     56 
     57 #ifdef __NetBSD__
     58 typedef struct taskq_ent {
     59 	SIMPLEQ_ENTRY(taskq_ent) tqent_list; /* Task queue. */
     60 	task_func_t	*tqent_func;	/* Function to run. */
     61 	void		*tqent_arg;	/* Argument to function above. */
     62 	unsigned	tqent_dynamic:1; /* Must kmem_free() if true. */
     63 	unsigned	tqent_queued:1; /* Queued and waiting to run if true. */
     64 } taskq_ent_t;
     65 #endif
     66 
     67 struct proc;
     68 
     69 /*
     70  * Public flags for taskq_create(): bit range 0-15
     71  */
     72 #define	TASKQ_PREPOPULATE	0x0001	/* Prepopulate with threads and data */
     73 #define	TASKQ_CPR_SAFE		0x0002	/* Use CPR safe protocol */
     74 #define	TASKQ_DYNAMIC		0x0004	/* Use dynamic thread scheduling */
     75 #define	TASKQ_THREADS_CPU_PCT	0x0008	/* number of threads as % of ncpu */
     76 #define	TASKQ_DC_BATCH		0x0010	/* Taskq uses SDC in batch mode */
     77 
     78 /*
     79  * Flags for taskq_dispatch. TQ_SLEEP/TQ_NOSLEEP should be same as
     80  * KM_SLEEP/KM_NOSLEEP.
     81  */
     82 #define	TQ_SLEEP	0x00	/* Can block for memory */
     83 #define	TQ_NOSLEEP	0x01	/* cannot block for memory; may fail */
     84 #define	TQ_NOQUEUE	0x02	/* Do not enqueue if can't dispatch */
     85 #define	TQ_NOALLOC	0x04	/* cannot allocate memory; may fail */
     86 #define	TQ_FRONT	0x08	/* Put task at the front of the queue */
     87 
     88 #ifdef _KERNEL
     89 
     90 extern taskq_t *system_taskq;
     91 
     92 void	taskq_init(void);
     93 void	taskq_mp_init(void);
     94 
     95 taskq_t	*taskq_create(const char *, int, pri_t, int, int, uint_t);
     96 taskq_t	*taskq_create_instance(const char *, int, int, pri_t, int, int, uint_t);
     97 taskq_t	*taskq_create_proc(const char *, int, pri_t, int, int,
     98     struct proc *, uint_t);
     99 taskq_t	*taskq_create_sysdc(const char *, int, int, int,
    100     struct proc *, uint_t, uint_t);
    101 taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
    102 #if defined(__FreeBSD__) || defined(__NetBSD__)
    103 void	taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t,
    104     taskq_ent_t *);
    105 #endif
    106 void	nulltask(void *);
    107 void	taskq_destroy(taskq_t *);
    108 void	taskq_wait(taskq_t *);
    109 void	taskq_suspend(taskq_t *);
    110 int	taskq_suspended(taskq_t *);
    111 void	taskq_resume(taskq_t *);
    112 int	taskq_member(taskq_t *, kthread_t *);
    113 
    114 #endif	/* _KERNEL */
    115 
    116 #ifdef	__cplusplus
    117 }
    118 #endif
    119 
    120 #endif	/* _SYS_TASKQ_H */
    121