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 * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 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 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A * Unlink the pool from the global list of all pools. 2N/A * There should be no pending jobs, but just in case... 2N/A * Worker thread is terminating. 2N/A * Called by a worker thread on return from a tpool_dispatch()d job. 2N/A * This is the worker's main loop. 2N/A * It will only be left if a timeout or an error has occured. 2N/A /* can't abandon a suspended pool */ 2N/A * Call the specified function. 2N/A * We don't know what this thread has been doing, 2N/A * so we reset its signal mask and cancellation 2N/A * state back to the initial values. 2N/A * We timed out and there is no work to be done 2N/A * and the number of workers exceeds the minimum. 2N/A * Exit now to reduce the size of the pool. 2N/A * Create a worker thread, with all signals blocked. 2N/A * Allow only one thread in the pool with a specified stack. 2N/A * Require threads to have at least the minimum stack size. 2N/A * We cannot just copy the attribute pointer. 2N/A * We need to initialize a new pthread_attr_t structure 2N/A * with the values from the user-supplied pthread_attr_t. 2N/A * If the attribute pointer is NULL, we need to initialize 2N/A * the new pthread_attr_t structure with default values. 2N/A /* make all pool threads be detached daemon threads */ 2N/A /* insert into the global list of all thread pools */ 2N/A * Dispatch a work request to the thread pool. 2N/A * If there are idle workers, awaken one. 2N/A * Else, if the maximum number of workers has 2N/A * not been reached, spawn a new worker thread. 2N/A * Else just return with the job added to the queue. 2N/A * Assumes: by the time tpool_destroy() is called no one will use this 2N/A * thread pool in any way and no one will try to dispatch entries to it. 2N/A * Calling tpool_destroy() from a job in the pool will cause deadlock. 2N/A /* mark the pool as being destroyed; wakeup idle workers */ 2N/A /* cancel all active workers */ 2N/A /* wait for all active workers to finish */ 2N/A /* the last worker to terminate will wake us up */ 2N/A * Like tpool_destroy(), but don't cancel workers or wait for them to finish. 2N/A * The last worker to terminate will delete the pool. 2N/A /* no workers, just delete the pool */ 2N/A /* wake up all workers, last one will delete the pool */ 2N/A * Wait for all jobs to complete. 2N/A * Calling tpool_wait() from a job in the pool will cause deadlock. 2N/A break;
/* pthread_create() failed */ 2N/A * All of the thread pool workers are gone, except possibly 2N/A * for the current thread, if it is a thread pool worker thread. 2N/A * Retain the thread pools, but make them all empty. Whatever 2N/A * jobs were queued or running belong to the parent process.