thread.h revision 290001
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 */
33inline BOOL IsValidHandle( HANDLE hHandle) {
34    return ((hHandle != NULL) && (hHandle != INVALID_HANDLE_VALUE));
35}
36
37/* validate wait return codes... */
38inline BOOL WaitSucceeded( DWORD dwWaitResult, DWORD dwHandleCount) {
39    return ((dwWaitResult >= WAIT_OBJECT_0) &&
40	    (dwWaitResult < WAIT_OBJECT_0 + dwHandleCount));
41}
42
43inline BOOL WaitAbandoned( DWORD dwWaitResult, DWORD dwHandleCount) {
44    return ((dwWaitResult >= WAIT_ABANDONED_0) &&
45	    (dwWaitResult < WAIT_ABANDONED_0 + dwHandleCount));
46}
47
48inline BOOL WaitTimeout( DWORD dwWaitResult) {
49    return (dwWaitResult == WAIT_TIMEOUT);
50}
51
52inline BOOL WaitFailed( DWORD dwWaitResult) {
53    return (dwWaitResult == WAIT_FAILED);
54}
55
56/* compute object indices for waits... */
57inline DWORD WaitSucceededIndex( DWORD dwWaitResult) {
58    return (dwWaitResult - WAIT_OBJECT_0);
59}
60
61inline DWORD WaitAbandonedIndex( DWORD dwWaitResult) {
62    return (dwWaitResult - WAIT_ABANDONED_0);
63}
64
65
66
67typedef HANDLE isc_thread_t;
68typedef DWORD isc_threadresult_t;
69typedef void * isc_threadarg_t;
70typedef isc_threadresult_t (WINAPI *isc_threadfunc_t)(isc_threadarg_t);
71typedef DWORD isc_thread_key_t;
72
73#define isc_thread_self (unsigned long)GetCurrentThreadId
74
75ISC_LANG_BEGINDECLS
76
77isc_result_t
78isc_thread_create(isc_threadfunc_t, isc_threadarg_t, isc_thread_t *);
79
80isc_result_t
81isc_thread_join(isc_thread_t, isc_threadresult_t *);
82
83void
84isc_thread_setconcurrency(unsigned int level);
85
86int
87isc_thread_key_create(isc_thread_key_t *key, void (*func)(void *));
88
89int
90isc_thread_key_delete(isc_thread_key_t key);
91
92void *
93isc_thread_key_getspecific(isc_thread_key_t);
94
95int
96isc_thread_key_setspecific(isc_thread_key_t key, void *value);
97
98ISC_LANG_ENDDECLS
99
100#endif /* ISC_THREAD_H */
101