Merge from vendor branch INTEL_ACPICA:
[dragonfly.git] / contrib / bind-9.3 / 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.2.2.2 2004/12/04 06:50:03 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 #if defined(PTHREAD_SCOPE_SYSTEM) && defined(NEED_PTHREAD_SCOPE_SYSTEM)
53         ret = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
54         if (ret != 0)
55                 return (ISC_R_UNEXPECTED);
56 #endif
57
58         ret = pthread_create(thread, &attr, func, arg);
59         if (ret != 0)
60                 return (ISC_R_UNEXPECTED);
61
62         pthread_attr_destroy(&attr);
63
64         return (ISC_R_SUCCESS);
65 }
66
67 void
68 isc_thread_setconcurrency(unsigned int level) {
69 #if defined(CALL_PTHREAD_SETCONCURRENCY)
70         (void)pthread_setconcurrency(level);
71 #else
72         UNUSED(level);
73 #endif
74 }