VirtualBox

source: vbox/trunk/src/VBox/Runtime/include/internal/iprt.h@ 22131

Last change on this file since 22131 was 22131, checked in by vboxsync, 16 years ago

spinlock-r0drv-[solaris|linux].c: More preemption assertions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: iprt.h 22131 2009-08-10 13:07:43Z vboxsync $ */
2/** @file
3 * IPRT - Internal header for miscellaneous global defs and types.
4 */
5
6/*
7 * Copyright (C) 2009 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31#ifndef ___internal_iprt_h
32#define ___internal_iprt_h
33
34#include <iprt/cdefs.h>
35#include <iprt/types.h>
36
37/** @def RT_EXPORT_SYMBOL
38 * This define is really here just for the linux kernel.
39 * @param Name The symbol name.
40 */
41#if defined(RT_OS_LINUX) \
42 && defined(IN_RING0) \
43 && defined(MODULE) \
44 && !defined(RT_NO_EXPORT_SYMBOL)
45# define bool linux_bool /* see r0drv/linux/the-linux-kernel.h */
46# include <linux/autoconf.h>
47# include <linux/module.h>
48# undef bool
49# define RT_EXPORT_SYMBOL(Name) EXPORT_SYMBOL(Name)
50#else
51# define RT_EXPORT_SYMBOL(Name) extern int g_rtExportSymbolDummyVariable
52#endif
53
54
55/** @def RT_MORE_STRICT
56 * Enables more assertions in IPRT. */
57#if !defined(RT_MORE_STRICT) && (defined(DEBUG) || defined(RT_STRICT) || defined(DOXYGEN_RUNNING)) && !defined(RT_OS_WINDOWS) /** @todo enable on windows after testing */
58# define RT_MORE_STRICT
59#endif
60
61/** @def RT_ASSERT_PREEMPT_CPUID_VAR
62 * Partner to RT_ASSERT_PREEMPT_CPUID_VAR. Declares and initializes a variable
63 * idAssertCpu to NIL_RTCPUID if preemption is enabled and to RTMpCpuId if
64 * disabled. When RT_MORE_STRICT isn't defined it declares an uninitialized
65 * dummy variable.
66 *
67 * Requires iprt/mp.h and iprt/asm.h.
68 */
69/** @def RT_ASSERT_PREEMPT_CPUID
70 * Asserts that we didn't change CPU since RT_ASSERT_PREEMPT_CPUID_VAR if
71 * preemption is disabled. Will also detect changes in preemption
72 * disable/enable status. This is a noop when RT_MORE_STRICT isn't defined. */
73#ifdef RT_MORE_STRICT
74# define RT_ASSERT_PREEMPT_CPUID_VAR() \
75 RTCPUID const idAssertCpu = RTThreadPreemptIsEnabled(NIL_RTTHREAD) ? NIL_RTCPUID : RTMpCpuId()
76# define RT_ASSERT_PREEMPT_CPUID() \
77 do \
78 { \
79 RTCPUID const idAssertCpuNow = RTThreadPreemptIsEnabled(NIL_RTTHREAD) ? NIL_RTCPUID : RTMpCpuId(); \
80 AssertMsg(idAssertCpu == idAssertCpuNow, ("%#x, %#x\n", idAssertCpu, idAssertCpuNow)); \
81 } while (0)
82
83#else
84# define RT_ASSERT_PREEMPT_CPUID_VAR() RTCPUID idAssertCpuDummy
85# define RT_ASSERT_PREEMPT_CPUID() NOREF(idAssertCpuDummy)
86#endif
87
88/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED
89 * Extended version of RT_ASSERT_PREEMPT_CPUID for use before
90 * RTSpinlockAcquired* returns. This macro works the idCpuOwner and idAssertCpu
91 * members of the spinlock instance data. */
92#ifdef RT_MORE_STRICT
93# define RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis) \
94 do \
95 { \
96 RTCPUID const idAssertCpuNow = RTMpCpuId(); \
97 AssertMsg(idAssertCpu == idAssertCpuNow || idAssertCpu == NIL_RTCPUID, ("%#x, %#x\n", idAssertCpu, idAssertCpuNow)); \
98 (pThis)->idAssertCpu = idAssertCpu; \
99 (pThis)->idCpuOwner = idAssertCpuNow; \
100 } while (0)
101#else
102# define RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis) NOREF(idAssertCpuDummy)
103#endif
104
105/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS
106 * Extended version of RT_ASSERT_PREEMPT_CPUID_VAR for use with
107 * RTSpinlockRelease* returns. */
108#ifdef RT_MORE_STRICT
109# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS() RTCPUID idAssertCpu, idAssertCpuAfter
110#else
111# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS() RTCPUID idAssertCpuDummy
112#endif
113
114/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE
115 * Extended version of RT_ASSERT_PREEMPT_CPUID for use in RTSpinlockRelease*
116 * before calling the native API for releasing the spinlock. It must be
117 * teamed up with RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED. */
118#ifdef RT_MORE_STRICT
119# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis) \
120 do \
121 { \
122 idAssertCpu = (pThis)->idCpuOwner; \
123 idAssertCpuAfter = (pThis)->idAssertCpu; \
124 RT_ASSERT_PREEMPT_CPUID(); \
125 (pThis)->idCpuOwner = NIL_RTCPUID; \
126 (pThis)->idAssertCpu = NIL_RTCPUID; \
127 } while (0)
128#else
129# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis) NOREF(idAssertCpuDummy)
130#endif
131
132/** @def RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASED
133 * Extended version of RT_ASSERT_PREEMPT_CPUID for use in RTSpinlockRelease*
134 * after having released the spinlock. It must be teamed up with
135 * RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE. */
136#ifdef RT_MORE_STRICT
137# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASED() \
138 do \
139 { \
140 idAssertCpu = idAssertCpuAfter; \
141 RT_ASSERT_PREEMPT_CPUID(); \
142 } while (0)
143#else
144# define RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASED() NOREF(idAssertCpuDummy)
145#endif
146
147/** @def RT_ASSERT_INTS_ON
148 * Asserts that interrupts are disabled when RT_MORE_STRICT is defined. */
149#ifdef RT_MORE_STRICT
150# define RT_ASSERT_INTS_ON() Assert(ASMIntAreEnabled())
151#else
152# define RT_ASSERT_INTS_ON() do { } while (0)
153#endif
154
155/** @def RT_ASSERT_PREEMPTIBLE
156 * Asserts that preemption hasn't been disabled (using
157 * RTThreadPreemptDisable) when RT_MORE_STRICT is defined. */
158#ifdef RT_MORE_STRICT
159# define RT_ASSERT_PREEMPTIBLE() Assert(RTThreadPreemptIsEnabled(NIL_RTTHREAD))
160#else
161# define RT_ASSERT_PREEMPTIBLE() do { } while (0)
162#endif
163
164#endif
165
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