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