VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/VBoxTAP/lock.h@ 15771

Last change on this file since 15771 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/*
2 * TAP-Win32 -- A kernel driver to provide virtual tap device
3 * functionality on Windows. Originally derived
4 * from the CIPE-Win32 project by Damion K. Wilson,
5 * with extensive modifications by James Yonan.
6 *
7 * All source code which derives from the CIPE-Win32 project is
8 * Copyright (C) Damion K. Wilson, 2003, and is released under the
9 * GPL version 2 (see below).
10 *
11 * All other source code is Copyright (C) 2002-2005 OpenVPN Solutions LLC,
12 * and is released under the GPL version 2 (see below).
13 *
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.
17 *
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.
22 *
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
27 */
28
29typedef struct
30{
31 volatile long count;
32} MUTEX;
33
34#define MUTEX_SLEEP_TIME 10000 // microseconds
35
36#define INIT_MUTEX(m) { (m)->count = 0; }
37
38#define ACQUIRE_MUTEX_BLOCKING(m) \
39{ \
40 while (NdisInterlockedIncrement (&((m)->count)) != 1) \
41 { \
42 NdisInterlockedDecrement(&((m)->count)); \
43 NdisMSleep(MUTEX_SLEEP_TIME); \
44 } \
45}
46
47#define RELEASE_MUTEX(m) \
48{ \
49 NdisInterlockedDecrement(&((m)->count)); \
50}
51
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 } \
63}
64
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 } \
79}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette