xref: /onnv-gate/usr/src/lib/libc/port/tpool/thread_pool_impl.h (revision 6812:febeba71273d)
12248Sraf /*
22248Sraf  * CDDL HEADER START
32248Sraf  *
42248Sraf  * The contents of this file are subject to the terms of the
52248Sraf  * Common Development and Distribution License (the "License").
62248Sraf  * You may not use this file except in compliance with the License.
72248Sraf  *
82248Sraf  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92248Sraf  * or http://www.opensolaris.org/os/licensing.
102248Sraf  * See the License for the specific language governing permissions
112248Sraf  * and limitations under the License.
122248Sraf  *
132248Sraf  * When distributing Covered Code, include this CDDL HEADER in each
142248Sraf  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152248Sraf  * If applicable, add the following below this CDDL HEADER, with the
162248Sraf  * fields enclosed by brackets "[]" replaced with your own identifying
172248Sraf  * information: Portions Copyright [yyyy] [name of copyright owner]
182248Sraf  *
192248Sraf  * CDDL HEADER END
202248Sraf  */
212248Sraf 
222248Sraf /*
23*6812Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
242248Sraf  * Use is subject to license terms.
252248Sraf  */
262248Sraf 
272248Sraf #ifndef _THREAD_POOL_IMPL_H
282248Sraf #define	_THREAD_POOL_IMPL_H
292248Sraf 
302248Sraf #pragma ident	"%Z%%M%	%I%	%E% SMI"
312248Sraf 
322248Sraf #include <thread_pool.h>
332248Sraf 
342248Sraf #ifdef	__cplusplus
352248Sraf extern "C" {
362248Sraf #endif
372248Sraf 
382248Sraf /*
392248Sraf  * Thread pool implementation definitions.
402248Sraf  * See <thread_pool.h> for interface declarations.
412248Sraf  */
422248Sraf 
432248Sraf /*
442248Sraf  * FIFO queued job
452248Sraf  */
462248Sraf typedef struct tpool_job tpool_job_t;
472248Sraf struct tpool_job {
482248Sraf 	tpool_job_t	*tpj_next;		/* list of jobs */
492248Sraf 	void		(*tpj_func)(void *);	/* function to call */
502248Sraf 	void		*tpj_arg;		/* its argument */
512248Sraf };
522248Sraf 
532248Sraf /*
542248Sraf  * List of active threads, linked through their stacks.
552248Sraf  */
562248Sraf typedef struct tpool_active tpool_active_t;
572248Sraf struct tpool_active {
582248Sraf 	tpool_active_t	*tpa_next;	/* list of active threads */
592248Sraf 	pthread_t	tpa_tid;	/* active thread id */
602248Sraf };
612248Sraf 
622248Sraf /*
632248Sraf  * The thread pool.
642248Sraf  */
652248Sraf struct tpool {
662248Sraf 	tpool_t		*tp_forw;	/* circular list of all thread pools */
672248Sraf 	tpool_t		*tp_back;
682248Sraf 	mutex_t		tp_mutex;	/* protects the pool data */
692248Sraf 	cond_t		tp_busycv;	/* synchronization in tpool_dispatch */
702248Sraf 	cond_t		tp_workcv;	/* synchronization with workers */
712248Sraf 	cond_t		tp_waitcv;	/* synchronization in tpool_wait() */
722248Sraf 	tpool_active_t	*tp_active;	/* threads performing work */
732248Sraf 	tpool_job_t	*tp_head;	/* FIFO job queue */
742248Sraf 	tpool_job_t	*tp_tail;
752248Sraf 	pthread_attr_t	tp_attr;	/* attributes of the workers */
762248Sraf 	int		tp_flags;	/* see below */
772248Sraf 	uint_t		tp_linger;	/* seconds before idle workers exit */
782248Sraf 	int		tp_njobs;	/* number of jobs in job queue */
792248Sraf 	int		tp_minimum;	/* minimum number of worker threads */
802248Sraf 	int		tp_maximum;	/* maximum number of worker threads */
812248Sraf 	int		tp_current;	/* current number of worker threads */
822248Sraf 	int		tp_idle;	/* number of idle workers */
832248Sraf };
842248Sraf 
852248Sraf /* tp_flags */
862248Sraf #define	TP_WAIT		0x01		/* waiting in tpool_wait() */
872248Sraf #define	TP_SUSPEND	0x02		/* pool is being suspended */
882248Sraf #define	TP_DESTROY	0x04		/* pool is being destroyed */
892248Sraf #define	TP_ABANDON	0x08		/* pool is abandoned (auto-destroy) */
902248Sraf 
91*6812Sraf extern int pthread_attr_clone(pthread_attr_t *, const pthread_attr_t *);
922248Sraf 
932248Sraf extern const sigset_t maskset;		/* set of all maskable signals */
942248Sraf 
952248Sraf #ifdef	__cplusplus
962248Sraf }
972248Sraf #endif
982248Sraf 
992248Sraf #endif /* _THREAD_POOL_IMPL_H */
100