Path: blob/main/sys/contrib/openzfs/lib/libtpool/thread_pool_impl.h
48375 views
// SPDX-License-Identifier: CDDL-1.01/*2* CDDL HEADER START3*4* The contents of this file are subject to the terms of the5* 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.LICENSE9* or https://opensource.org/licenses/CDDL-1.0.10* See the License for the specific language governing permissions11* and limitations under the License.12*13* When distributing Covered Code, include this CDDL HEADER in each14* file and include the License file at usr/src/OPENSOLARIS.LICENSE.15* If applicable, add the following below this CDDL HEADER, with the16* fields enclosed by brackets "[]" replaced with your own identifying17* information: Portions Copyright [yyyy] [name of copyright owner]18*19* CDDL HEADER END20*/2122/*23* Copyright 2008 Sun Microsystems, Inc. All rights reserved.24* Use is subject to license terms.25*/2627#ifndef _THREAD_POOL_IMPL_H28#define _THREAD_POOL_IMPL_H2930#include <thread_pool.h>3132#ifdef __cplusplus33extern "C" {34#endif3536/*37* Thread pool implementation definitions.38* See <thread_pool.h> for interface declarations.39*/4041/*42* FIFO queued job43*/44typedef struct tpool_job tpool_job_t;45struct tpool_job {46tpool_job_t *tpj_next; /* list of jobs */47void (*tpj_func)(void *); /* function to call */48void *tpj_arg; /* its argument */49};5051/*52* List of active threads, linked through their stacks.53*/54typedef struct tpool_active tpool_active_t;55struct tpool_active {56tpool_active_t *tpa_next; /* list of active threads */57pthread_t tpa_tid; /* active thread id */58};5960/*61* The thread pool.62*/63struct tpool {64tpool_t *tp_forw; /* circular list of all thread pools */65tpool_t *tp_back;66pthread_mutex_t tp_mutex; /* protects the pool data */67pthread_cond_t tp_busycv; /* synchronization in tpool_dispatch */68pthread_cond_t tp_workcv; /* synchronization with workers */69pthread_cond_t tp_waitcv; /* synchronization in tpool_wait() */70tpool_active_t *tp_active; /* threads performing work */71tpool_job_t *tp_head; /* FIFO job queue */72tpool_job_t *tp_tail;73pthread_attr_t tp_attr; /* attributes of the workers */74int tp_flags; /* see below */75uint_t tp_linger; /* seconds before idle workers exit */76int tp_njobs; /* number of jobs in job queue */77int tp_minimum; /* minimum number of worker threads */78int tp_maximum; /* maximum number of worker threads */79int tp_current; /* current number of worker threads */80int tp_idle; /* number of idle workers */81};8283/* tp_flags */84#define TP_WAIT 0x01 /* waiting in tpool_wait() */85#define TP_SUSPEND 0x02 /* pool is being suspended */86#define TP_DESTROY 0x04 /* pool is being destroyed */87#define TP_ABANDON 0x08 /* pool is abandoned (auto-destroy) */8889#ifdef __cplusplus90}91#endif9293#endif /* _THREAD_POOL_IMPL_H */949596