1*ba2539a9Schs /* 2*ba2539a9Schs * CDDL HEADER START 3*ba2539a9Schs * 4*ba2539a9Schs * The contents of this file are subject to the terms of the 5*ba2539a9Schs * Common Development and Distribution License (the "License"). 6*ba2539a9Schs * You may not use this file except in compliance with the License. 7*ba2539a9Schs * 8*ba2539a9Schs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*ba2539a9Schs * or http://www.opensolaris.org/os/licensing. 10*ba2539a9Schs * See the License for the specific language governing permissions 11*ba2539a9Schs * and limitations under the License. 12*ba2539a9Schs * 13*ba2539a9Schs * When distributing Covered Code, include this CDDL HEADER in each 14*ba2539a9Schs * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*ba2539a9Schs * If applicable, add the following below this CDDL HEADER, with the 16*ba2539a9Schs * fields enclosed by brackets "[]" replaced with your own identifying 17*ba2539a9Schs * information: Portions Copyright [yyyy] [name of copyright owner] 18*ba2539a9Schs * 19*ba2539a9Schs * CDDL HEADER END 20*ba2539a9Schs */ 21*ba2539a9Schs 22*ba2539a9Schs /* 23*ba2539a9Schs * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24*ba2539a9Schs * Use is subject to license terms. 25*ba2539a9Schs */ 26*ba2539a9Schs 27*ba2539a9Schs /* 28*ba2539a9Schs * $FreeBSD: head/cddl/compat/opensolaris/misc/thread_pool_impl.h 265689 2014-05-08 16:59:36Z mav $ 29*ba2539a9Schs */ 30*ba2539a9Schs 31*ba2539a9Schs #ifndef _THREAD_POOL_IMPL_H 32*ba2539a9Schs #define _THREAD_POOL_IMPL_H 33*ba2539a9Schs 34*ba2539a9Schs #pragma ident "%Z%%M% %I% %E% SMI" 35*ba2539a9Schs 36*ba2539a9Schs #include <thread_pool.h> 37*ba2539a9Schs 38*ba2539a9Schs #ifdef __cplusplus 39*ba2539a9Schs extern "C" { 40*ba2539a9Schs #endif 41*ba2539a9Schs 42*ba2539a9Schs /* 43*ba2539a9Schs * Thread pool implementation definitions. 44*ba2539a9Schs * See <thread_pool.h> for interface declarations. 45*ba2539a9Schs */ 46*ba2539a9Schs 47*ba2539a9Schs /* 48*ba2539a9Schs * FIFO queued job 49*ba2539a9Schs */ 50*ba2539a9Schs typedef struct tpool_job tpool_job_t; 51*ba2539a9Schs struct tpool_job { 52*ba2539a9Schs tpool_job_t *tpj_next; /* list of jobs */ 53*ba2539a9Schs void (*tpj_func)(void *); /* function to call */ 54*ba2539a9Schs void *tpj_arg; /* its argument */ 55*ba2539a9Schs }; 56*ba2539a9Schs 57*ba2539a9Schs /* 58*ba2539a9Schs * List of active threads, linked through their stacks. 59*ba2539a9Schs */ 60*ba2539a9Schs typedef struct tpool_active tpool_active_t; 61*ba2539a9Schs struct tpool_active { 62*ba2539a9Schs tpool_active_t *tpa_next; /* list of active threads */ 63*ba2539a9Schs pthread_t tpa_tid; /* active thread id */ 64*ba2539a9Schs }; 65*ba2539a9Schs 66*ba2539a9Schs /* 67*ba2539a9Schs * The thread pool. 68*ba2539a9Schs */ 69*ba2539a9Schs struct tpool { 70*ba2539a9Schs tpool_t *tp_forw; /* circular list of all thread pools */ 71*ba2539a9Schs tpool_t *tp_back; 72*ba2539a9Schs mutex_t tp_mutex; /* protects the pool data */ 73*ba2539a9Schs cond_t tp_busycv; /* synchronization in tpool_dispatch */ 74*ba2539a9Schs cond_t tp_workcv; /* synchronization with workers */ 75*ba2539a9Schs cond_t tp_waitcv; /* synchronization in tpool_wait() */ 76*ba2539a9Schs tpool_active_t *tp_active; /* threads performing work */ 77*ba2539a9Schs tpool_job_t *tp_head; /* FIFO job queue */ 78*ba2539a9Schs tpool_job_t *tp_tail; 79*ba2539a9Schs pthread_attr_t tp_attr; /* attributes of the workers */ 80*ba2539a9Schs int tp_flags; /* see below */ 81*ba2539a9Schs uint_t tp_linger; /* seconds before idle workers exit */ 82*ba2539a9Schs int tp_njobs; /* number of jobs in job queue */ 83*ba2539a9Schs int tp_minimum; /* minimum number of worker threads */ 84*ba2539a9Schs int tp_maximum; /* maximum number of worker threads */ 85*ba2539a9Schs int tp_current; /* current number of worker threads */ 86*ba2539a9Schs int tp_idle; /* number of idle workers */ 87*ba2539a9Schs }; 88*ba2539a9Schs 89*ba2539a9Schs /* tp_flags */ 90*ba2539a9Schs #define TP_WAIT 0x01 /* waiting in tpool_wait() */ 91*ba2539a9Schs #define TP_SUSPEND 0x02 /* pool is being suspended */ 92*ba2539a9Schs #define TP_DESTROY 0x04 /* pool is being destroyed */ 93*ba2539a9Schs #define TP_ABANDON 0x08 /* pool is abandoned (auto-destroy) */ 94*ba2539a9Schs 95*ba2539a9Schs #ifdef __cplusplus 96*ba2539a9Schs } 97*ba2539a9Schs #endif 98*ba2539a9Schs 99*ba2539a9Schs #endif /* _THREAD_POOL_IMPL_H */ 100