VirtualBox

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

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

Build fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1/* $Id: spinlock-r0drv-solaris.c 22134 2009-08-10 13:23:41Z 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.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
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 RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis);
127}
128
129
130RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
131{
132 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
133 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS();
134
135 AssertPtr(pThis);
136 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
137 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis);
138 NOREF(pTmp);
139
140 mutex_exit(&pThis->Mtx);
141 ASMSetFlags(pTmp->uFlags);
142
143 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASED();
144}
145
146
147RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
148{
149 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
150 RT_ASSERT_PREEMPT_CPUID_VAR();
151 AssertPtr(pThis);
152 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
153 NOREF(pTmp);
154
155 mutex_enter(&pThis->Mtx);
156
157 RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis);
158}
159
160
161RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
162{
163 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
164 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS();
165
166 AssertPtr(pThis);
167 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
168 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis);
169 NOREF(pTmp);
170
171 mutex_exit(&pThis->Mtx);
172
173 RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASED();
174}
175
Note: See TracBrowser for help on using the repository browser.

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