/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "lint.h"
#include "thr_uberdata.h"
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include "thread_pool_impl.h"
static void
{
/*
* Unlink the pool from the global list of all pools.
*/
if (thread_pools == tpool)
if (thread_pools == tpool)
thread_pools = NULL;
else {
}
/*
* There should be no pending jobs, but just in case...
*/
}
}
/*
* Worker thread is terminating.
*/
static void
{
if (--tpool->tp_current == 0 &&
return;
}
}
}
static void
{
}
}
/*
* Called by a worker thread on return from a tpool_dispatch()d job.
*/
static void
{
/* CSTYLED */
break;
}
}
}
static void *
{
int elapsed;
void (*func)(void *);
/*
* This is the worker's main loop.
* It will only be left if a timeout or an error has occured.
*/
for (;;) {
elapsed = 0;
} else {
elapsed = 1;
break;
}
}
}
break;
/* can't abandon a suspended pool */
}
break;
}
elapsed = 0;
/*
* Call the specified function.
*/
/*
* We don't know what this thread has been doing,
* so we reset its signal mask and cancellation
* state back to the initial values.
*/
NULL);
NULL);
}
/*
* We timed out and there is no work to be done
* and the number of workers exceeds the minimum.
* Exit now to reduce the size of the pool.
*/
break;
}
}
return (arg);
}
/*
* Create a worker thread, with all signals blocked.
*/
static int
{
int error;
return (error);
}
tpool_t *
{
void *stackaddr;
int error;
return (NULL);
}
return (NULL);
}
/*
* Allow only one thread in the pool with a specified stack.
* Require threads to have at least the minimum stack size.
*/
minstack = thr_min_stack();
return (NULL);
}
return (NULL);
}
}
return (NULL);
}
/*
* We cannot just copy the attribute pointer.
* We need to initialize a new pthread_attr_t structure
* with the values from the user-supplied pthread_attr_t.
* If the attribute pointer is NULL, we need to initialize
* the new pthread_attr_t structure with default values.
*/
if (error) {
return (NULL);
}
/* make all pool threads be detached daemon threads */
/* insert into the global list of all thread pools */
if (thread_pools == NULL) {
} else {
}
return (tpool);
}
/*
* Dispatch a work request to the thread pool.
* If there are idle workers, awaken one.
* Else, if the maximum number of workers has
* not been reached, spawn a new worker thread.
* Else just return with the job added to the queue.
*/
int
{
return (-1);
else
create_worker(tpool) == 0)
tpool->tp_current++;
}
return (0);
}
/*
* Assumes: by the time tpool_destroy() is called no one will use this
* thread pool in any way and no one will try to dispatch entries to it.
* Calling tpool_destroy() from a job in the pool will cause deadlock.
*/
void
{
/* mark the pool as being destroyed; wakeup idle workers */
/* cancel all active workers */
/* wait for all active workers to finish */
}
/* the last worker to terminate will wake us up */
while (tpool->tp_current != 0)
}
/*
* Like tpool_destroy(), but don't cancel workers or wait for them to finish.
* The last worker to terminate will delete the pool.
*/
void
{
if (tpool->tp_current == 0) {
/* no workers, just delete the pool */
} else {
/* wake up all workers, last one will delete the pool */
}
}
/*
* Wait for all jobs to complete.
* Calling tpool_wait() from a job in the pool will cause deadlock.
*/
void
{
}
}
void
{
}
int
{
int suspended;
return (suspended);
}
void
{
int excess;
return;
}
if (create_worker(tpool) != 0)
break; /* pthread_create() failed */
tpool->tp_current++;
}
}
int
{
return (1);
}
}
return (0);
}
void
postfork1_child_tpool(void)
{
/*
* All of the thread pool workers are gone, except possibly
* for the current thread, if it is a thread pool worker thread.
* Retain the thread pools, but make them all empty. Whatever
* jobs were queued or running belong to the parent process.
*/
top:
return;
do {
}
break;
}
}
tpool->tp_current = 0;
if (tpool->tp_current == 0) {
goto top; /* start over */
}
}
}