1d54cfbdroberto/*
2d54cfbdroberto * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
3d54cfbdroberto * Copyright (C) 1998-2001  Internet Software Consortium.
4d54cfbdroberto *
5d54cfbdroberto * Permission to use, copy, modify, and/or distribute this software for any
6d54cfbdroberto * purpose with or without fee is hereby granted, provided that the above
7d54cfbdroberto * copyright notice and this permission notice appear in all copies.
8d54cfbdroberto *
9d54cfbdroberto * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10d54cfbdroberto * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11d54cfbdroberto * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12d54cfbdroberto * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13d54cfbdroberto * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14d54cfbdroberto * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15d54cfbdroberto * PERFORMANCE OF THIS SOFTWARE.
16d54cfbdroberto */
17d54cfbdroberto
18d54cfbdroberto/* $Id: thread.h,v 1.26 2007/06/19 23:47:18 tbox Exp $ */
19d54cfbdroberto
20d54cfbdroberto#ifndef ISC_THREAD_H
21d54cfbdroberto#define ISC_THREAD_H 1
22d54cfbdroberto
23d54cfbdroberto/*! \file */
24d54cfbdroberto
25d54cfbdroberto#include <pthread.h>
26d54cfbdroberto
27d54cfbdroberto#include <isc/lang.h>
28d54cfbdroberto#include <isc/result.h>
29d54cfbdroberto
30d54cfbdrobertoISC_LANG_BEGINDECLS
31d54cfbdroberto
32d54cfbdrobertotypedef pthread_t isc_thread_t;
33d54cfbdrobertotypedef void * isc_threadresult_t;
34d54cfbdrobertotypedef void * isc_threadarg_t;
35d54cfbdrobertotypedef isc_threadresult_t (*isc_threadfunc_t)(isc_threadarg_t);
36d54cfbdrobertotypedef pthread_key_t isc_thread_key_t;
37d54cfbdroberto
38d54cfbdrobertoisc_result_t
39d54cfbdrobertoisc_thread_create(isc_threadfunc_t, isc_threadarg_t, isc_thread_t *);
40d54cfbdroberto
41d54cfbdrobertovoid
42d54cfbdrobertoisc_thread_setconcurrency(unsigned int level);
43d54cfbdroberto
44d54cfbdroberto/* XXX We could do fancier error handling... */
45d54cfbdroberto
46d54cfbdroberto#define isc_thread_join(t, rp) \
47d54cfbdroberto	((pthread_join((t), (rp)) == 0) ? \
48d54cfbdroberto	 ISC_R_SUCCESS : ISC_R_UNEXPECTED)
49d54cfbdroberto
50d54cfbdroberto#define isc_thread_self \
51d54cfbdroberto	(unsigned long)pthread_self
52d54cfbdroberto
53d54cfbdroberto#define isc_thread_key_create pthread_key_create
54d54cfbdroberto#define isc_thread_key_getspecific pthread_getspecific
55d54cfbdroberto#define isc_thread_key_setspecific pthread_setspecific
56d54cfbdroberto#define isc_thread_key_delete pthread_key_delete
57d54cfbdroberto
58d54cfbdrobertoISC_LANG_ENDDECLS
59d54cfbdroberto
60d54cfbdroberto#endif /* ISC_THREAD_H */
61