1 /*
2 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998-2001 Internet Software Consortium.
4 *
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.
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.h,v 1.25 2009/09/29 04:37:08 marka Exp $ */
19
20 #ifndef ISC_THREAD_H
21 #define ISC_THREAD_H 1
22
23 #include <windows.h>
24
25 #include <isc/lang.h>
26 #include <isc/result.h>
27
28 /*
29 * Inlines to help with wait retrun checking
30 */
31
32 /* check handle for NULL and INVALID_HANDLE */
IsValidHandle(HANDLE hHandle)33 inline BOOL IsValidHandle( HANDLE hHandle) {
34 return ((hHandle != NULL) && (hHandle != INVALID_HANDLE_VALUE));
35 }
36
37 /* validate wait return codes... */
WaitSucceeded(DWORD dwWaitResult,DWORD dwHandleCount)38 inline BOOL WaitSucceeded( DWORD dwWaitResult, DWORD dwHandleCount) {
39 return ((dwWaitResult >= WAIT_OBJECT_0) &&
40 (dwWaitResult < WAIT_OBJECT_0 + dwHandleCount));
41 }
42
WaitAbandoned(DWORD dwWaitResult,DWORD dwHandleCount)43 inline BOOL WaitAbandoned( DWORD dwWaitResult, DWORD dwHandleCount) {
44 return ((dwWaitResult >= WAIT_ABANDONED_0) &&
45 (dwWaitResult < WAIT_ABANDONED_0 + dwHandleCount));
46 }
47
WaitTimeout(DWORD dwWaitResult)48 inline BOOL WaitTimeout( DWORD dwWaitResult) {
49 return (dwWaitResult == WAIT_TIMEOUT);
50 }
51
WaitFailed(DWORD dwWaitResult)52 inline BOOL WaitFailed( DWORD dwWaitResult) {
53 return (dwWaitResult == WAIT_FAILED);
54 }
55
56 /* compute object indices for waits... */
WaitSucceededIndex(DWORD dwWaitResult)57 inline DWORD WaitSucceededIndex( DWORD dwWaitResult) {
58 return (dwWaitResult - WAIT_OBJECT_0);
59 }
60
WaitAbandonedIndex(DWORD dwWaitResult)61 inline DWORD WaitAbandonedIndex( DWORD dwWaitResult) {
62 return (dwWaitResult - WAIT_ABANDONED_0);
63 }
64
65
66
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;
72
73 #define isc_thread_self (unsigned long)GetCurrentThreadId
74
75 ISC_LANG_BEGINDECLS
76
77 isc_result_t
78 isc_thread_create(isc_threadfunc_t, isc_threadarg_t, isc_thread_t *);
79
80 isc_result_t
81 isc_thread_join(isc_thread_t, isc_threadresult_t *);
82
83 void
84 isc_thread_setconcurrency(unsigned int level);
85
86 int
87 isc_thread_key_create(isc_thread_key_t *key, void (*func)(void *));
88
89 int
90 isc_thread_key_delete(isc_thread_key_t key);
91
92 void *
93 isc_thread_key_getspecific(isc_thread_key_t);
94
95 int
96 isc_thread_key_setspecific(isc_thread_key_t key, void *value);
97
98 ISC_LANG_ENDDECLS
99
100 #endif /* ISC_THREAD_H */
101