4 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: thread.h,v 1.25 2009/09/29 04:37:08 marka Exp */
23 #define ISC_THREAD_H 1
28 #include <isc/result.h>
31 * Inlines to help with wait retrun checking
34 /* check handle for NULL and INVALID_HANDLE */
35 inline BOOL
IsValidHandle( HANDLE hHandle
) {
36 return ((hHandle
!= NULL
) && (hHandle
!= INVALID_HANDLE_VALUE
));
39 /* validate wait return codes... */
40 inline BOOL
WaitSucceeded( DWORD dwWaitResult
, DWORD dwHandleCount
) {
41 return ((dwWaitResult
>= WAIT_OBJECT_0
) &&
42 (dwWaitResult
< WAIT_OBJECT_0
+ dwHandleCount
));
45 inline BOOL
WaitAbandoned( DWORD dwWaitResult
, DWORD dwHandleCount
) {
46 return ((dwWaitResult
>= WAIT_ABANDONED_0
) &&
47 (dwWaitResult
< WAIT_ABANDONED_0
+ dwHandleCount
));
50 inline BOOL
WaitTimeout( DWORD dwWaitResult
) {
51 return (dwWaitResult
== WAIT_TIMEOUT
);
54 inline BOOL
WaitFailed( DWORD dwWaitResult
) {
55 return (dwWaitResult
== WAIT_FAILED
);
58 /* compute object indices for waits... */
59 inline DWORD
WaitSucceededIndex( DWORD dwWaitResult
) {
60 return (dwWaitResult
- WAIT_OBJECT_0
);
63 inline DWORD
WaitAbandonedIndex( DWORD dwWaitResult
) {
64 return (dwWaitResult
- WAIT_ABANDONED_0
);
69 typedef HANDLE isc_thread_t
;
70 typedef DWORD isc_threadresult_t
;
71 typedef void * isc_threadarg_t
;
72 typedef isc_threadresult_t (WINAPI
*isc_threadfunc_t
)(isc_threadarg_t
);
73 typedef DWORD isc_thread_key_t
;
75 #define isc_thread_self (unsigned long)GetCurrentThreadId
80 isc_thread_create(isc_threadfunc_t
, isc_threadarg_t
, isc_thread_t
*);
83 isc_thread_join(isc_thread_t
, isc_threadresult_t
*);
86 isc_thread_setconcurrency(unsigned int level
);
89 isc_thread_key_create(isc_thread_key_t
*key
, void (*func
)(void *));
92 isc_thread_key_delete(isc_thread_key_t key
);
95 isc_thread_key_getspecific(isc_thread_key_t
);
98 isc_thread_key_setspecific(isc_thread_key_t key
, void *value
);
102 #endif /* ISC_THREAD_H */