1258945Sroberto/*
2258945Sroberto * Copyright (C) 2004, 2007-2009  Internet Systems Consortium, Inc. ("ISC")
3258945Sroberto * Copyright (C) 1998-2001  Internet Software Consortium.
4258945Sroberto *
5258945Sroberto * Permission to use, copy, modify, and/or distribute this software for any
6258945Sroberto * purpose with or without fee is hereby granted, provided that the above
7258945Sroberto * copyright notice and this permission notice appear in all copies.
8258945Sroberto *
9258945Sroberto * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10258945Sroberto * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11258945Sroberto * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12258945Sroberto * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13258945Sroberto * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14258945Sroberto * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15258945Sroberto * PERFORMANCE OF THIS SOFTWARE.
16258945Sroberto */
17258945Sroberto
18280849Scy/* $Id: mutex.h,v 1.22 2009/01/18 23:48:14 tbox Exp $ */
19258945Sroberto
20258945Sroberto#ifndef ISC_MUTEX_H
21258945Sroberto#define ISC_MUTEX_H 1
22258945Sroberto
23258945Sroberto#include <isc/net.h>
24258945Sroberto#include <windows.h>
25258945Sroberto
26258945Sroberto#include <isc/result.h>
27258945Sroberto
28258945Srobertotypedef CRITICAL_SECTION isc_mutex_t;
29258945Sroberto
30258945Sroberto/*
31258945Sroberto * This definition is here since some versions of WINBASE.H
32258945Sroberto * omits it for some reason.
33258945Sroberto */
34258945Sroberto#if (_WIN32_WINNT < 0x0400)
35258945SrobertoWINBASEAPI BOOL WINAPI
36258945SrobertoTryEnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection);
37258945Sroberto#endif /* _WIN32_WINNT < 0x0400 */
38258945Sroberto
39258945Sroberto#define isc_mutex_init(mp) \
40258945Sroberto	(InitializeCriticalSection((mp)), ISC_R_SUCCESS)
41258945Sroberto#define isc_mutex_lock(mp) \
42258945Sroberto	(EnterCriticalSection((mp)), ISC_R_SUCCESS)
43258945Sroberto#define isc_mutex_unlock(mp) \
44258945Sroberto	(LeaveCriticalSection((mp)), ISC_R_SUCCESS)
45258945Sroberto#define isc_mutex_trylock(mp) \
46258945Sroberto	(TryEnterCriticalSection((mp)) ? ISC_R_SUCCESS : ISC_R_LOCKBUSY)
47258945Sroberto#define isc_mutex_destroy(mp) \
48258945Sroberto	(DeleteCriticalSection((mp)), ISC_R_SUCCESS)
49258945Sroberto
50258945Sroberto/*
51258945Sroberto * This is a placeholder for now since we are not keeping any mutex stats
52258945Sroberto */
53258945Sroberto#define isc_mutex_stats(fp) do {} while (0)
54258945Sroberto
55258945Sroberto#endif /* ISC_MUTEX_H */
56