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