2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001, 2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: thread.c,v 1.9.2.4 2004/03/09 06:12:07 marka Exp $ */
22 #include <isc/thread.h>
25 #ifndef THREAD_MINSTACKSIZE
26 #define THREAD_MINSTACKSIZE (64U * 1024)
30 isc_thread_create(isc_threadfunc_t func
, isc_threadarg_t arg
,
37 pthread_attr_init(&attr
);
39 #if defined(HAVE_PTHREAD_ATTR_GETSTACKSIZE) && \
40 defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE)
41 ret
= pthread_attr_getstacksize(&attr
, &stacksize
);
43 return (ISC_R_UNEXPECTED
);
45 if (stacksize
< THREAD_MINSTACKSIZE
) {
46 ret
= pthread_attr_setstacksize(&attr
, THREAD_MINSTACKSIZE
);
48 return (ISC_R_UNEXPECTED
);
52 ret
= pthread_create(thread
, &attr
, func
, arg
);
54 return (ISC_R_UNEXPECTED
);
56 pthread_attr_destroy(&attr
);
58 return (ISC_R_SUCCESS
);
62 isc_thread_setconcurrency(unsigned int level
) {
63 #if defined(CALL_PTHREAD_SETCONCURRENCY)
64 (void)pthread_setconcurrency(level
);