Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / isc / pthreads / thread.c
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2000, 2001, 2003  Internet Software Consortium.
4  *
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.
8  *
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.
16  */
17
18 /* $Id: thread.c,v 1.9.2.4 2004/03/09 06:12:07 marka Exp $ */
19
20 #include <config.h>
21
22 #include <isc/thread.h>
23 #include <isc/util.h>
24
25 #ifndef THREAD_MINSTACKSIZE
26 #define THREAD_MINSTACKSIZE             (64U * 1024)
27 #endif
28
29 isc_result_t
30 isc_thread_create(isc_threadfunc_t func, isc_threadarg_t arg,
31                   isc_thread_t *thread)
32 {
33         pthread_attr_t attr;
34         size_t stacksize;
35         int ret;
36
37         pthread_attr_init(&attr);
38
39 #if defined(HAVE_PTHREAD_ATTR_GETSTACKSIZE) && \
40     defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE)
41         ret = pthread_attr_getstacksize(&attr, &stacksize);
42         if (ret != 0)
43                 return (ISC_R_UNEXPECTED);
44
45         if (stacksize < THREAD_MINSTACKSIZE) {
46                 ret = pthread_attr_setstacksize(&attr, THREAD_MINSTACKSIZE);
47                 if (ret != 0)
48                         return (ISC_R_UNEXPECTED);
49         }
50 #endif
51
52         ret = pthread_create(thread, &attr, func, arg);
53         if (ret != 0)
54                 return (ISC_R_UNEXPECTED);
55
56         pthread_attr_destroy(&attr);
57
58         return (ISC_R_SUCCESS);
59 }
60
61 void
62 isc_thread_setconcurrency(unsigned int level) {
63 #if defined(CALL_PTHREAD_SETCONCURRENCY)
64         (void)pthread_setconcurrency(level);
65 #else
66         UNUSED(level);
67 #endif
68 }