1d54cfbdroberto/*
2047f369cy * Copyright (C) 2004, 2005, 2007, 2009  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
18047f369cy/* $Id: thread.h,v 1.25 2009/09/29 04:37:08 marka Exp $ */
19d54cfbdroberto
20d54cfbdroberto#ifndef ISC_THREAD_H
21d54cfbdroberto#define ISC_THREAD_H 1
22d54cfbdroberto
23d54cfbdroberto#include <windows.h>
24d54cfbdroberto
25d54cfbdroberto#include <isc/lang.h>
26d54cfbdroberto#include <isc/result.h>
27d54cfbdroberto
28d54cfbdroberto/*
29d54cfbdroberto * Inlines to help with wait retrun checking
30d54cfbdroberto */
31d54cfbdroberto
32d54cfbdroberto/* check handle for NULL and INVALID_HANDLE */
33d54cfbdrobertoinline BOOL IsValidHandle( HANDLE hHandle) {
34d54cfbdroberto    return ((hHandle != NULL) && (hHandle != INVALID_HANDLE_VALUE));
35d54cfbdroberto}
36d54cfbdroberto
37d54cfbdroberto/* validate wait return codes... */
38d54cfbdrobertoinline BOOL WaitSucceeded( DWORD dwWaitResult, DWORD dwHandleCount) {
39d54cfbdroberto    return ((dwWaitResult >= WAIT_OBJECT_0) &&
40047f369cy	    (dwWaitResult < WAIT_OBJECT_0 + dwHandleCount));
41d54cfbdroberto}
42d54cfbdroberto
43d54cfbdrobertoinline BOOL WaitAbandoned( DWORD dwWaitResult, DWORD dwHandleCount) {
44d54cfbdroberto    return ((dwWaitResult >= WAIT_ABANDONED_0) &&
45047f369cy	    (dwWaitResult < WAIT_ABANDONED_0 + dwHandleCount));
46d54cfbdroberto}
47d54cfbdroberto
48d54cfbdrobertoinline BOOL WaitTimeout( DWORD dwWaitResult) {
49d54cfbdroberto    return (dwWaitResult == WAIT_TIMEOUT);
50d54cfbdroberto}
51047f369cy
52d54cfbdrobertoinline BOOL WaitFailed( DWORD dwWaitResult) {
53d54cfbdroberto    return (dwWaitResult == WAIT_FAILED);
54d54cfbdroberto}
55d54cfbdroberto
56d54cfbdroberto/* compute object indices for waits... */
57d54cfbdrobertoinline DWORD WaitSucceededIndex( DWORD dwWaitResult) {
58d54cfbdroberto    return (dwWaitResult - WAIT_OBJECT_0);
59d54cfbdroberto}
60d54cfbdroberto
61d54cfbdrobertoinline DWORD WaitAbandonedIndex( DWORD dwWaitResult) {
62d54cfbdroberto    return (dwWaitResult - WAIT_ABANDONED_0);
63d54cfbdroberto}
64d54cfbdroberto
65d54cfbdroberto
66d54cfbdroberto
67d54cfbdrobertotypedef HANDLE isc_thread_t;
68047f369cytypedef DWORD isc_threadresult_t;
69d54cfbdrobertotypedef void * isc_threadarg_t;
70d54cfbdrobertotypedef isc_threadresult_t (WINAPI *isc_threadfunc_t)(isc_threadarg_t);
71d54cfbdrobertotypedef DWORD isc_thread_key_t;
72d54cfbdroberto
73d54cfbdroberto#define isc_thread_self (unsigned long)GetCurrentThreadId
74d54cfbdroberto
75d54cfbdrobertoISC_LANG_BEGINDECLS
76d54cfbdroberto
77d54cfbdrobertoisc_result_t
78d54cfbdrobertoisc_thread_create(isc_threadfunc_t, isc_threadarg_t, isc_thread_t *);
79d54cfbdroberto
80d54cfbdrobertoisc_result_t
81d54cfbdrobertoisc_thread_join(isc_thread_t, isc_threadresult_t *);
82d54cfbdroberto
83d54cfbdrobertovoid
84d54cfbdrobertoisc_thread_setconcurrency(unsigned int level);
85d54cfbdroberto
86d54cfbdrobertoint
87d54cfbdrobertoisc_thread_key_create(isc_thread_key_t *key, void (*func)(void *));
88d54cfbdroberto
89d54cfbdrobertoint
90d54cfbdrobertoisc_thread_key_delete(isc_thread_key_t key);
91d54cfbdroberto
92d54cfbdrobertovoid *
93d54cfbdrobertoisc_thread_key_getspecific(isc_thread_key_t);
94d54cfbdroberto
95d54cfbdrobertoint
96d54cfbdrobertoisc_thread_key_setspecific(isc_thread_key_t key, void *value);
97d54cfbdroberto
98d54cfbdrobertoISC_LANG_ENDDECLS
99d54cfbdroberto
100d54cfbdroberto#endif /* ISC_THREAD_H */
101