VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/solaris/spinlock-r0drv-solaris.c@ 25720

最後變更 在這個檔案從25720是 22550,由 vboxsync 提交於 16 年 前

spinlock-r0drv-solaris.c: more assertions, now for the interrupt flag setting we're suspecting S10 to do.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 5.4 KB
 
1/* $Id: spinlock-r0drv-solaris.c 22550 2009-08-28 12:30:51Z vboxsync $ */
2/** @file
3 * IPRT - Spinlocks, Ring-0 Driver, Solaris.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include "the-solaris-kernel.h"
36#include "internal/iprt.h"
37#include <iprt/spinlock.h>
38
39#include <iprt/asm.h>
40#include <iprt/assert.h>
41#include <iprt/err.h>
42#include <iprt/mem.h>
43#include <iprt/mp.h>
44#include <iprt/thread.h>
45#include "internal/magics.h"
46
47
48/*******************************************************************************
49* Structures and Typedefs *
50*******************************************************************************/
51/**
52 * Wrapper for the struct mutex type.
53 */
54typedef struct RTSPINLOCKINTERNAL
55{
56 /** Spinlock magic value (RTSPINLOCK_MAGIC). */
57 uint32_t volatile u32Magic;
58 /** A Solaris spinlock. */
59 kmutex_t Mtx;
60#ifdef RT_MORE_STRICT
61 /** The idAssertCpu variable before acquring the lock for asserting after
62 * releasing the spinlock. */
63 RTCPUID volatile idAssertCpu;
64 /** The CPU that owns the lock. */
65 RTCPUID volatile idCpuOwner;
66#endif
67} RTSPINLOCKINTERNAL, *PRTSPINLOCKINTERNAL;
68
69
70
71RTDECL(int) RTSpinlockCreate(PRTSPINLOCK pSpinlock)
72{
73 /*
74 * Allocate.
75 */
76 RT_ASSERT_PREEMPTIBLE();
77 AssertCompile(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *));
78 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)RTMemAlloc(sizeof(*pThis));
79 if (!pThis)
80 return VERR_NO_MEMORY;
81
82 /*
83 * Initialize & return.
84 */
85 pThis->u32Magic = RTSPINLOCK_MAGIC;
86 mutex_init(&pThis->Mtx, "IPRT Spinlock", MUTEX_SPIN, (void *)ipltospl(DISP_LEVEL));
87 *pSpinlock = pThis;
88 return VINF_SUCCESS;
89}
90
91
92RTDECL(int) RTSpinlockDestroy(RTSPINLOCK Spinlock)
93{
94 /*
95 * Validate input.
96 */
97 RT_ASSERT_INTS_ON();
98 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
99 if (!pThis)
100 return VERR_INVALID_PARAMETER;
101 AssertMsgReturn(pThis->u32Magic == RTSPINLOCK_MAGIC,
102 ("Invalid spinlock %p magic=%#x\n", pThis, pThis->u32Magic),
103 VERR_INVALID_PARAMETER);
104
105 /*
106 * Make the lock invalid and release the memory.
107 */
108 ASMAtomicIncU32(&pThis->u32Magic);
109 mutex_destroy(&pThis->Mtx);
110 RTMemFree(pThis);
111 return VINF_SUCCESS;
112}
113
114
115RTDECL(void) RTSpinlockAcquireNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
116{
117 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
118 RT_ASSERT_PREEMPT_CPUID_VAR();
119
120 AssertPtr(pThis);
121 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
122
123 pTmp->uFlags = ASMIntDisableFlags();
124 mutex_enter(&pThis->Mtx);
125
126 Assert(!ASMIntAreEnabled());
127 RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis);
128}
129
130
131RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
132{
133 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
134 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS();
135
136 AssertPtr(pThis);
137 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
138 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis);
139 NOREF(pTmp);
140
141 mutex_exit(&pThis->Mtx);
142 ASMSetFlags(pTmp->uFlags);
143
144 RT_ASSERT_PREEMPT_CPUID();
145}
146
147
148RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
149{
150 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
151 RT_ASSERT_PREEMPT_CPUID_VAR();
152 AssertPtr(pThis);
153 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
154 NOREF(pTmp);
155#ifdef RT_STRICT
156 bool fIntsOn = ASMIntAreEnabled();
157#endif
158
159 mutex_enter(&pThis->Mtx);
160
161 AssertMsg(fIntsOn == ASMIntAreEnabled(), ("fIntsOn=%RTbool\n", fIntsOn));
162
163 RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis);
164}
165
166
167RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
168{
169 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
170 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS();
171
172 AssertPtr(pThis);
173 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
174 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis);
175 NOREF(pTmp);
176#ifdef RT_STRICT
177 bool fIntsOn = ASMIntAreEnabled();
178#endif
179
180 mutex_exit(&pThis->Mtx);
181
182 AssertMsg(fIntsOn == ASMIntAreEnabled(), ("fIntsOn=%RTbool\n", fIntsOn));
183 RT_ASSERT_PREEMPT_CPUID();
184}
185
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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