1 /*	$NetBSD: mutex.h,v 1.7 2014/12/10 04:38:01 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2004, 2007-2009  Internet Systems Consortium, Inc. ("ISC")
5  * Copyright (C) 1998-2001  Internet Software Consortium.
6  *
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.
10  *
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.
18  */
19 
20 /* Id: mutex.h,v 1.22 2009/01/18 23:48:14 tbox Exp  */
21 
22 #ifndef ISC_MUTEX_H
23 #define ISC_MUTEX_H 1
24 
25 #include <isc/net.h>
26 #include <windows.h>
27 
28 #include <isc/result.h>
29 
30 typedef CRITICAL_SECTION isc_mutex_t;
31 
32 /*
33  * This definition is here since some versions of WINBASE.H
34  * omits it for some reason.
35  */
36 #if (_WIN32_WINNT < 0x0400)
37 WINBASEAPI BOOL WINAPI
38 TryEnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection);
39 #endif /* _WIN32_WINNT < 0x0400 */
40 
41 #define isc_mutex_init(mp) \
42 	(InitializeCriticalSection((mp)), ISC_R_SUCCESS)
43 #define isc_mutex_lock(mp) \
44 	(EnterCriticalSection((mp)), ISC_R_SUCCESS)
45 #define isc_mutex_unlock(mp) \
46 	(LeaveCriticalSection((mp)), ISC_R_SUCCESS)
47 #define isc_mutex_trylock(mp) \
48 	(TryEnterCriticalSection((mp)) ? ISC_R_SUCCESS : ISC_R_LOCKBUSY)
49 #define isc_mutex_destroy(mp) \
50 	(DeleteCriticalSection((mp)), ISC_R_SUCCESS)
51 
52 /*
53  * This is a placeholder for now since we are not keeping any mutex stats
54  */
55 #define isc_mutex_stats(fp) do {} while (0)
56 
57 #endif /* ISC_MUTEX_H */
58