2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#ifndef _THREAD_POOL_IMPL_H
2N/A#define _THREAD_POOL_IMPL_H
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <thread_pool.h>
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/A/*
2N/A * Thread pool implementation definitions.
2N/A * See <thread_pool.h> for interface declarations.
2N/A */
2N/A
2N/A/*
2N/A * FIFO queued job
2N/A */
2N/Atypedef struct tpool_job tpool_job_t;
2N/Astruct tpool_job {
2N/A tpool_job_t *tpj_next; /* list of jobs */
2N/A void (*tpj_func)(void *); /* function to call */
2N/A void *tpj_arg; /* its argument */
2N/A};
2N/A
2N/A/*
2N/A * List of active threads, linked through their stacks.
2N/A */
2N/Atypedef struct tpool_active tpool_active_t;
2N/Astruct tpool_active {
2N/A tpool_active_t *tpa_next; /* list of active threads */
2N/A pthread_t tpa_tid; /* active thread id */
2N/A};
2N/A
2N/A/*
2N/A * The thread pool.
2N/A */
2N/Astruct tpool {
2N/A tpool_t *tp_forw; /* circular list of all thread pools */
2N/A tpool_t *tp_back;
2N/A mutex_t tp_mutex; /* protects the pool data */
2N/A cond_t tp_busycv; /* synchronization in tpool_dispatch */
2N/A cond_t tp_workcv; /* synchronization with workers */
2N/A cond_t tp_waitcv; /* synchronization in tpool_wait() */
2N/A tpool_active_t *tp_active; /* threads performing work */
2N/A tpool_job_t *tp_head; /* FIFO job queue */
2N/A tpool_job_t *tp_tail;
2N/A pthread_attr_t tp_attr; /* attributes of the workers */
2N/A int tp_flags; /* see below */
2N/A uint_t tp_linger; /* seconds before idle workers exit */
2N/A int tp_njobs; /* number of jobs in job queue */
2N/A int tp_minimum; /* minimum number of worker threads */
2N/A int tp_maximum; /* maximum number of worker threads */
2N/A int tp_current; /* current number of worker threads */
2N/A int tp_idle; /* number of idle workers */
2N/A};
2N/A
2N/A/* tp_flags */
2N/A#define TP_WAIT 0x01 /* waiting in tpool_wait() */
2N/A#define TP_SUSPEND 0x02 /* pool is being suspended */
2N/A#define TP_DESTROY 0x04 /* pool is being destroyed */
2N/A#define TP_ABANDON 0x08 /* pool is abandoned (auto-destroy) */
2N/A
2N/Aextern int pthread_attr_clone(pthread_attr_t *, const pthread_attr_t *);
2N/A
2N/Aextern const sigset_t maskset; /* set of all maskable signals */
2N/A
2N/A#ifdef __cplusplus
2N/A}
2N/A#endif
2N/A
2N/A#endif /* _THREAD_POOL_IMPL_H */