2 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or 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.h,v 1.25 2009/09/29 04:37:08 marka Exp $ */
21 #define ISC_THREAD_H 1
26 #include <isc/result.h>
29 * Inlines to help with wait retrun checking
32 /* check handle for NULL and INVALID_HANDLE */
33 inline BOOL IsValidHandle( HANDLE hHandle) {
34 return ((hHandle != NULL) && (hHandle != INVALID_HANDLE_VALUE));
37 /* validate wait return codes... */
38 inline BOOL WaitSucceeded( DWORD dwWaitResult, DWORD dwHandleCount) {
39 return ((dwWaitResult >= WAIT_OBJECT_0) &&
40 (dwWaitResult < WAIT_OBJECT_0 + dwHandleCount));
43 inline BOOL WaitAbandoned( DWORD dwWaitResult, DWORD dwHandleCount) {
44 return ((dwWaitResult >= WAIT_ABANDONED_0) &&
45 (dwWaitResult < WAIT_ABANDONED_0 + dwHandleCount));
48 inline BOOL WaitTimeout( DWORD dwWaitResult) {
49 return (dwWaitResult == WAIT_TIMEOUT);
52 inline BOOL WaitFailed( DWORD dwWaitResult) {
53 return (dwWaitResult == WAIT_FAILED);
56 /* compute object indices for waits... */
57 inline DWORD WaitSucceededIndex( DWORD dwWaitResult) {
58 return (dwWaitResult - WAIT_OBJECT_0);
61 inline DWORD WaitAbandonedIndex( DWORD dwWaitResult) {
62 return (dwWaitResult - WAIT_ABANDONED_0);
67 typedef HANDLE isc_thread_t;
68 typedef DWORD isc_threadresult_t;
69 typedef void * isc_threadarg_t;
70 typedef isc_threadresult_t (WINAPI *isc_threadfunc_t)(isc_threadarg_t);
71 typedef DWORD isc_thread_key_t;
73 #define isc_thread_self (unsigned long)GetCurrentThreadId
78 isc_thread_create(isc_threadfunc_t, isc_threadarg_t, isc_thread_t *);
81 isc_thread_join(isc_thread_t, isc_threadresult_t *);
84 isc_thread_setconcurrency(unsigned int level);
87 isc_thread_key_create(isc_thread_key_t *key, void (*func)(void *));
90 isc_thread_key_delete(isc_thread_key_t key);
93 isc_thread_key_getspecific(isc_thread_key_t);
96 isc_thread_key_setspecific(isc_thread_key_t key, void *value);
100 #endif /* ISC_THREAD_H */