VirtualBox

source: vbox/trunk/include/iprt/spinlock.h@ 26201

Last change on this file since 26201 was 22650, checked in by vboxsync, 15 years ago

spinlock-r0drv-freebsd.c,spinlock.h: quick review w/ bugfixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/** @file
2 * IPRT - Spinlocks.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___iprt_spinlock_h
31#define ___iprt_spinlock_h
32
33#include <iprt/cdefs.h>
34#include <iprt/types.h>
35
36RT_C_DECLS_BEGIN
37
38
39/** @defgroup grp_rt_spinlock RTSpinlock - Spinlocks
40 * @ingroup grp_rt
41 * @{
42 */
43
44/**
45 * Temporary spinlock state variable.
46 * All members are undefined and highly platform specific.
47 */
48typedef struct RTSPINLOCKTMP
49{
50#ifdef IN_RING0
51# ifdef RT_OS_LINUX
52 /** The saved [R|E]FLAGS. */
53 unsigned long flFlags;
54# define RTSPINLOCKTMP_INITIALIZER { 0 }
55
56# elif defined(RT_OS_WINDOWS)
57 /** The saved [R|E]FLAGS. */
58 RTCCUINTREG uFlags;
59 /** The KIRQL. */
60 unsigned char uchIrqL;
61# define RTSPINLOCKTMP_INITIALIZER { 0, 0 }
62
63# elif defined(__L4__)
64 /** The saved [R|E]FLAGS. */
65 unsigned long flFlags;
66# define RTSPINLOCKTMP_INITIALIZER { 0 }
67
68# elif defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
69 /** The saved [R|E]FLAGS. */
70 RTCCUINTREG uFlags;
71# define RTSPINLOCKTMP_INITIALIZER { 0 }
72
73# elif defined(RT_OS_OS2)
74 /** The saved [R|E]FLAGS. (dummy) */
75 RTCCUINTREG uFlags;
76# define RTSPINLOCKTMP_INITIALIZER { 0 }
77
78# else
79# error "PORTME\n"
80 /** The saved [R|E]FLAGS. */
81 RTCCUINTREG uFlags;
82# endif
83
84#else /* !IN_RING0 */
85 /** The saved [R|E]FLAGS. (dummy) */
86 RTCCUINTREG uFlags;
87# define RTSPINLOCKTMP_INITIALIZER { 0 }
88#endif /* !IN_RING0 */
89} RTSPINLOCKTMP;
90/** Pointer to a temporary spinlock state variable. */
91typedef RTSPINLOCKTMP *PRTSPINLOCKTMP;
92/** Pointer to a const temporary spinlock state variable. */
93typedef const RTSPINLOCKTMP *PCRTSPINLOCKTMP;
94
95/** @def RTSPINLOCKTMP_INITIALIZER
96 * What to assign to a RTSPINLOCKTMP at definition.
97 */
98#ifdef DOXYGEN_RUNNING
99# define RTSPINLOCKTMP_INITIALIZER
100#endif
101
102
103
104/**
105 * Creates a spinlock.
106 *
107 * @returns iprt status code.
108 * @param pSpinlock Where to store the spinlock handle.
109 */
110RTDECL(int) RTSpinlockCreate(PRTSPINLOCK pSpinlock);
111
112/**
113 * Destroys a spinlock created by RTSpinlockCreate().
114 *
115 * @returns iprt status code.
116 * @param Spinlock Spinlock returned by RTSpinlockCreate().
117 */
118RTDECL(int) RTSpinlockDestroy(RTSPINLOCK Spinlock);
119
120/**
121 * Acquires the spinlock.
122 * Interrupts are disabled upon return.
123 *
124 * @param Spinlock The spinlock to acquire.
125 * @param pTmp Where to save the state.
126 */
127RTDECL(void) RTSpinlockAcquireNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp);
128
129/**
130 * Releases the spinlock.
131 *
132 * @param Spinlock The spinlock to acquire.
133 * @param pTmp The state to restore. (This better be the same as for the RTSpinlockAcquire() call!)
134 */
135RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp);
136
137/**
138 * Acquires the spinlock.
139 *
140 * @param Spinlock The spinlock to acquire.
141 * @param pTmp Where to save the state.
142 */
143RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp);
144
145/**
146 * Releases the spinlock.
147 *
148 * @param Spinlock The spinlock to acquire.
149 * @param pTmp The state to restore. (This better be the same as for the RTSpinlockAcquire() call!)
150 */
151RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp);
152
153
154/** @} */
155
156RT_C_DECLS_END
157
158#endif
159
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