Upgrade to OpenVPN 2.1.0
[tomato.git] / release / src / router / openvpn / tap-win32 / tmp / lock.h
blobc3b52b1c1a18a9c7fee1aa350269b33201094ce6
1 /*
2 * TAP-Win32/TAP-Win64 -- A kernel driver to provide virtual tap
3 * device functionality on Windows.
5 * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
7 * This source code is Copyright (C) 2002-2009 OpenVPN Technologies, Inc.,
8 * and is released under the GPL version 2 (see below), however due
9 * to the extra costs of supporting Windows Vista, OpenVPN Solutions
10 * LLC reserves the right to change the terms of the TAP-Win32/TAP-Win64
11 * license for versions 9.1 and higher prior to the official release of
12 * OpenVPN 2.1.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2
16 * as published by the Free Software Foundation.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program (see the file COPYING included with this
25 * distribution); if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 typedef struct
31 volatile long count;
32 } MUTEX;
34 #define MUTEX_SLEEP_TIME 10000 // microseconds
36 #define INIT_MUTEX(m) { (m)->count = 0; }
38 #define ACQUIRE_MUTEX_BLOCKING(m) \
39 { \
40 while (NdisInterlockedIncrement (&((m)->count)) != 1) \
41 { \
42 NdisInterlockedDecrement(&((m)->count)); \
43 NdisMSleep(MUTEX_SLEEP_TIME); \
44 } \
47 #define RELEASE_MUTEX(m) \
48 { \
49 NdisInterlockedDecrement(&((m)->count)); \
52 #define ACQUIRE_MUTEX_NONBLOCKING(m, result) \
53 { \
54 if (NdisInterlockedIncrement (&((m)->count)) != 1) \
55 { \
56 NdisInterlockedDecrement(&((m)->count)); \
57 result = FALSE; \
58 } \
59 else \
60 { \
61 result = TRUE; \
62 } \
65 #define ACQUIRE_MUTEX_ADAPTIVE(m, result) \
66 { \
67 result = TRUE; \
68 while (NdisInterlockedIncrement (&((m)->count)) != 1) \
69 { \
70 NdisInterlockedDecrement(&((m)->count)); \
71 if (KeGetCurrentIrql () < DISPATCH_LEVEL) \
72 NdisMSleep(MUTEX_SLEEP_TIME); \
73 else \
74 { \
75 result = FALSE; \
76 break; \
77 } \
78 } \