task.c revision 3be0a4382d6b0e9f9ecf2fa1f2e9154087f3a175
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt * Copyright (C) 1998-2000 Internet Software Consortium.
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt * Permission to use, copy, modify, and distribute this software for any
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt * purpose with or without fee is hereby granted, provided that the above
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt * copyright notice and this permission notice appear in all copies.
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
44931133ff16d6da48a1823b12dc4cfddf619412Automatic Updater * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
44931133ff16d6da48a1823b12dc4cfddf619412Automatic Updater * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt/* $Id: task.c,v 1.72 2000/08/29 22:30:14 bwelling Exp $ */
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt * Principal Author: Bob Halley
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt * XXXRTH Need to document the states a task can be in, and the rules
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt * for changing states.
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt#define XTRACE(m) fprintf(stderr, "task %p thread %lu: %s\n", \
64c66c801f5a23f2050b263819181e6f6c6c108aEvan Hunt#define XTTRACE(t, m) fprintf(stderr, "task %p thread %lu: %s\n", \
isc_thread_self(), (m))
#define XTRACE(m)
#define XTTRACE(t, m)
#define XTHREADTRACE(m)
} task_state_t;
struct isc_task {
unsigned int magic;
unsigned int references;
unsigned int quantum;
unsigned int flags;
#ifdef ISC_TASK_NAMES
void * tag;
struct isc_taskmgr {
unsigned int magic;
unsigned int workers;
#ifdef ISC_PLATFORM_USETHREADS
unsigned int default_quantum;
#ifdef ISC_PLATFORM_USETHREADS
#ifndef ISC_PLATFORM_USETHREADS
unsigned int refs;
#ifndef ISC_PLATFORM_USETHREADS
#ifdef ISC_PLATFORM_USETHREADS
return (ISC_R_NOMEMORY);
return (ISC_R_UNEXPECTED);
#ifdef ISC_TASK_NAMES
if (exiting) {
return (ISC_R_SHUTTINGDOWN);
return (ISC_R_SUCCESS);
static inline isc_boolean_t
return (was_idle);
#ifdef ISC_PLATFORM_USETHREADS
static inline isc_boolean_t
return (ISC_TRUE);
return (ISC_FALSE);
if (was_idle)
static inline isc_boolean_t
return (was_idle);
if (was_idle) {
unsigned int count = 0;
count++;
return (count);
unsigned int count;
ISC_TRUE);
return (count);
void *tag)
return (ISC_FALSE);
return (ISC_TRUE);
ISC_FALSE));
ISC_FALSE));
NULL,
arg,
sizeof *event);
return (ISC_R_NOMEMORY);
if (disallowed)
return (result);
if (was_idle)
#ifdef ISC_TASK_NAMES
(void)name;
(void)tag;
#ifndef ISC_PLATFORM_USETHREADS
unsigned int dispatch_count = 0;
} while (!done);
if (finished)
if (requeue) {
#ifdef ISC_PLATFORM_USETHREADS
static isc_threadresult_t
#ifdef _WIN32
return ((isc_threadresult_t)0);
#ifdef ISC_PLATFORM_USETHREADS
unsigned int i, started = 0;
#ifndef ISC_PLATFORM_USETHREADS
UNUSED(i);
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
return (ISC_R_UNEXPECTED);
#ifdef ISC_PLATFORM_USETHREADS
return (ISC_R_NOMEMORY);
return (ISC_R_UNEXPECTED);
if (default_quantum == 0)
#ifdef ISC_PLATFORM_USETHREADS
for (i = 0; i < workers; i++) {
started++;
if (started == 0) {
return (ISC_R_NOTHREADS);
return (ISC_R_SUCCESS);
#ifndef ISC_PLATFORM_USETHREADS
UNUSED(i);
#ifdef ISC_PLATFORM_USETHREADS
#ifndef ISC_PLATFORM_USETHREADS
isc__taskmgr_dispatch(void) {
return (ISC_R_NOTFOUND);
return (ISC_R_SUCCESS);