1258945Sroberto/*
2258945Sroberto * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
3258945Sroberto * Copyright (C) 1998-2001  Internet Software Consortium.
4258945Sroberto *
5258945Sroberto * Permission to use, copy, modify, and/or distribute this software for any
6258945Sroberto * purpose with or without fee is hereby granted, provided that the above
7258945Sroberto * copyright notice and this permission notice appear in all copies.
8258945Sroberto *
9258945Sroberto * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10258945Sroberto * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11258945Sroberto * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12258945Sroberto * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13258945Sroberto * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14258945Sroberto * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15258945Sroberto * PERFORMANCE OF THIS SOFTWARE.
16258945Sroberto */
17258945Sroberto
18258945Sroberto/* $Id: thread.h,v 1.26 2007/06/19 23:47:18 tbox Exp $ */
19258945Sroberto
20258945Sroberto#ifndef ISC_THREAD_H
21258945Sroberto#define ISC_THREAD_H 1
22258945Sroberto
23258945Sroberto/*! \file */
24258945Sroberto
25258945Sroberto#include <pthread.h>
26258945Sroberto
27258945Sroberto#include <isc/lang.h>
28258945Sroberto#include <isc/result.h>
29258945Sroberto
30258945SrobertoISC_LANG_BEGINDECLS
31258945Sroberto
32258945Srobertotypedef pthread_t isc_thread_t;
33258945Srobertotypedef void * isc_threadresult_t;
34258945Srobertotypedef void * isc_threadarg_t;
35258945Srobertotypedef isc_threadresult_t (*isc_threadfunc_t)(isc_threadarg_t);
36258945Srobertotypedef pthread_key_t isc_thread_key_t;
37258945Sroberto
38258945Srobertoisc_result_t
39258945Srobertoisc_thread_create(isc_threadfunc_t, isc_threadarg_t, isc_thread_t *);
40258945Sroberto
41258945Srobertovoid
42258945Srobertoisc_thread_setconcurrency(unsigned int level);
43258945Sroberto
44258945Sroberto/* XXX We could do fancier error handling... */
45258945Sroberto
46258945Sroberto#define isc_thread_join(t, rp) \
47258945Sroberto	((pthread_join((t), (rp)) == 0) ? \
48258945Sroberto	 ISC_R_SUCCESS : ISC_R_UNEXPECTED)
49258945Sroberto
50258945Sroberto#define isc_thread_self \
51258945Sroberto	(unsigned long)pthread_self
52258945Sroberto
53258945Sroberto#define isc_thread_key_create pthread_key_create
54258945Sroberto#define isc_thread_key_getspecific pthread_getspecific
55258945Sroberto#define isc_thread_key_setspecific pthread_setspecific
56258945Sroberto#define isc_thread_key_delete pthread_key_delete
57258945Sroberto
58258945SrobertoISC_LANG_ENDDECLS
59258945Sroberto
60258945Sroberto#endif /* ISC_THREAD_H */
61