1*a466cc55SCy Schubert /* 2*a466cc55SCy Schubert * Copyright (C) 2004, 2007-2009 Internet Systems Consortium, Inc. ("ISC") 3*a466cc55SCy Schubert * Copyright (C) 1998-2001 Internet Software Consortium. 4*a466cc55SCy Schubert * 5*a466cc55SCy Schubert * Permission to use, copy, modify, and/or distribute this software for any 6*a466cc55SCy Schubert * purpose with or without fee is hereby granted, provided that the above 7*a466cc55SCy Schubert * copyright notice and this permission notice appear in all copies. 8*a466cc55SCy Schubert * 9*a466cc55SCy Schubert * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10*a466cc55SCy Schubert * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11*a466cc55SCy Schubert * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12*a466cc55SCy Schubert * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13*a466cc55SCy Schubert * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14*a466cc55SCy Schubert * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15*a466cc55SCy Schubert * PERFORMANCE OF THIS SOFTWARE. 16*a466cc55SCy Schubert */ 17*a466cc55SCy Schubert 18*a466cc55SCy Schubert /* $Id: mutex.h,v 1.22 2009/01/18 23:48:14 tbox Exp $ */ 19*a466cc55SCy Schubert 20*a466cc55SCy Schubert #ifndef ISC_MUTEX_H 21*a466cc55SCy Schubert #define ISC_MUTEX_H 1 22*a466cc55SCy Schubert 23*a466cc55SCy Schubert #include <isc/net.h> 24*a466cc55SCy Schubert #include <windows.h> 25*a466cc55SCy Schubert 26*a466cc55SCy Schubert #include <isc/result.h> 27*a466cc55SCy Schubert 28*a466cc55SCy Schubert typedef CRITICAL_SECTION isc_mutex_t; 29*a466cc55SCy Schubert 30*a466cc55SCy Schubert /* 31*a466cc55SCy Schubert * This definition is here since some versions of WINBASE.H 32*a466cc55SCy Schubert * omits it for some reason. 33*a466cc55SCy Schubert */ 34*a466cc55SCy Schubert #if (_WIN32_WINNT < 0x0400) 35*a466cc55SCy Schubert WINBASEAPI BOOL WINAPI 36*a466cc55SCy Schubert TryEnterCriticalSection(LPCRITICAL_SECTION lpCriticalSection); 37*a466cc55SCy Schubert #endif /* _WIN32_WINNT < 0x0400 */ 38*a466cc55SCy Schubert 39*a466cc55SCy Schubert #define isc_mutex_init(mp) \ 40*a466cc55SCy Schubert (InitializeCriticalSection((mp)), ISC_R_SUCCESS) 41*a466cc55SCy Schubert #define isc_mutex_lock(mp) \ 42*a466cc55SCy Schubert (EnterCriticalSection((mp)), ISC_R_SUCCESS) 43*a466cc55SCy Schubert #define isc_mutex_unlock(mp) \ 44*a466cc55SCy Schubert (LeaveCriticalSection((mp)), ISC_R_SUCCESS) 45*a466cc55SCy Schubert #define isc_mutex_trylock(mp) \ 46*a466cc55SCy Schubert (TryEnterCriticalSection((mp)) ? ISC_R_SUCCESS : ISC_R_LOCKBUSY) 47*a466cc55SCy Schubert #define isc_mutex_destroy(mp) \ 48*a466cc55SCy Schubert (DeleteCriticalSection((mp)), ISC_R_SUCCESS) 49*a466cc55SCy Schubert 50*a466cc55SCy Schubert /* 51*a466cc55SCy Schubert * This is a placeholder for now since we are not keeping any mutex stats 52*a466cc55SCy Schubert */ 53*a466cc55SCy Schubert #define isc_mutex_stats(fp) do {} while (0) 54*a466cc55SCy Schubert 55*a466cc55SCy Schubert #endif /* ISC_MUTEX_H */ 56