1 | /** @file
|
---|
2 | * innotek Portable Runtime - Spinlocks.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 |
|
---|
26 | #ifndef ___iprt_spinlock_h
|
---|
27 | #define ___iprt_spinlock_h
|
---|
28 |
|
---|
29 | #include <iprt/cdefs.h>
|
---|
30 | #include <iprt/types.h>
|
---|
31 |
|
---|
32 | __BEGIN_DECLS
|
---|
33 |
|
---|
34 |
|
---|
35 | /** @defgroup grp_rt_spinlock RTSpinlock - Spinlocks
|
---|
36 | * @ingroup grp_rt
|
---|
37 | * @{
|
---|
38 | */
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Temporary spinlock state variable.
|
---|
42 | * All members are undefined and highly platform specific.
|
---|
43 | */
|
---|
44 | typedef struct RTSPINLOCKTMP
|
---|
45 | {
|
---|
46 | #ifdef IN_RING0
|
---|
47 | # ifdef RT_OS_LINUX
|
---|
48 | /** The saved [R|E]FLAGS. */
|
---|
49 | unsigned long flFlags;
|
---|
50 | # define RTSPINLOCKTMP_INITIALIZER { 0 }
|
---|
51 |
|
---|
52 | # elif defined(RT_OS_WINDOWS)
|
---|
53 | /** The saved [R|E]FLAGS. */
|
---|
54 | RTUINTREG uFlags;
|
---|
55 | /** The KIRQL. */
|
---|
56 | unsigned char uchIrqL;
|
---|
57 | # define RTSPINLOCKTMP_INITIALIZER { 0, 0 }
|
---|
58 |
|
---|
59 | # elif defined(__L4__)
|
---|
60 | /** The saved [R|E]FLAGS. */
|
---|
61 | unsigned long flFlags;
|
---|
62 | # define RTSPINLOCKTMP_INITIALIZER { 0 }
|
---|
63 |
|
---|
64 | # elif defined(RT_OS_DARWIN)
|
---|
65 | /** The saved [R|E]FLAGS. */
|
---|
66 | RTUINTREG uFlags;
|
---|
67 | # define RTSPINLOCKTMP_INITIALIZER { 0 }
|
---|
68 |
|
---|
69 | # elif defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
|
---|
70 | /** The saved [R|E]FLAGS. (dummy) */
|
---|
71 | RTUINTREG uFlags;
|
---|
72 | # define RTSPINLOCKTMP_INITIALIZER { 0 }
|
---|
73 |
|
---|
74 | # else
|
---|
75 | # error "Your OS is not supported.\n"
|
---|
76 | /** The saved [R|E]FLAGS. */
|
---|
77 | RTUINTREG uFlags;
|
---|
78 | # endif
|
---|
79 |
|
---|
80 | #else /* !IN_RING0 */
|
---|
81 | /** The saved [R|E]FLAGS.
|
---|
82 | * (RT spinlocks will by definition disable interrupts.) */
|
---|
83 | RTUINTREG uFlags;
|
---|
84 | # define RTSPINLOCKTMP_INITIALIZER { 0 }
|
---|
85 | #endif /* !IN_RING0 */
|
---|
86 | } RTSPINLOCKTMP;
|
---|
87 | /** Pointer to a temporary spinlock state variable. */
|
---|
88 | typedef RTSPINLOCKTMP *PRTSPINLOCKTMP;
|
---|
89 | /** Pointer to a const temporary spinlock state variable. */
|
---|
90 | typedef const RTSPINLOCKTMP *PCRTSPINLOCKTMP;
|
---|
91 |
|
---|
92 | /** @def RTSPINLOCKTMP_INITIALIZER
|
---|
93 | * What to assign to a RTSPINLOCKTMP at definition.
|
---|
94 | */
|
---|
95 | #ifdef DOXYGEN_RUNNING
|
---|
96 | # define RTSPINLOCKTMP_INITIALIZER
|
---|
97 | #endif
|
---|
98 |
|
---|
99 |
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Creates a spinlock.
|
---|
103 | *
|
---|
104 | * @returns iprt status code.
|
---|
105 | * @param pSpinlock Where to store the spinlock handle.
|
---|
106 | */
|
---|
107 | RTDECL(int) RTSpinlockCreate(PRTSPINLOCK pSpinlock);
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Destroys a spinlock created by RTSpinlockCreate().
|
---|
111 | *
|
---|
112 | * @returns iprt status code.
|
---|
113 | * @param Spinlock Spinlock returned by RTSpinlockCreate().
|
---|
114 | */
|
---|
115 | RTDECL(int) RTSpinlockDestroy(RTSPINLOCK Spinlock);
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Acquires the spinlock.
|
---|
119 | * Interrupts are disabled upon return.
|
---|
120 | *
|
---|
121 | * @param Spinlock The spinlock to acquire.
|
---|
122 | * @param pTmp Where to save the state.
|
---|
123 | */
|
---|
124 | RTDECL(void) RTSpinlockAcquireNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp);
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Releases the spinlock.
|
---|
128 | *
|
---|
129 | * @param Spinlock The spinlock to acquire.
|
---|
130 | * @param pTmp The state to restore. (This better be the same as for the RTSpinlockAcquire() call!)
|
---|
131 | */
|
---|
132 | RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp);
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Acquires the spinlock.
|
---|
136 | *
|
---|
137 | * @param Spinlock The spinlock to acquire.
|
---|
138 | * @param pTmp Where to save the state.
|
---|
139 | */
|
---|
140 | RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp);
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Releases the spinlock.
|
---|
144 | *
|
---|
145 | * @param Spinlock The spinlock to acquire.
|
---|
146 | * @param pTmp The state to restore. (This better be the same as for the RTSpinlockAcquire() call!)
|
---|
147 | */
|
---|
148 | RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp);
|
---|
149 |
|
---|
150 |
|
---|
151 | /** @} */
|
---|
152 |
|
---|
153 | __END_DECLS
|
---|
154 |
|
---|
155 | #endif
|
---|
156 |
|
---|