VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/linux/spinlock-r0drv-linux.c@ 13764

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

EXPORT_SYMBOL must be placed after the function/variable was implemented

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1/* $Id: spinlock-r0drv-linux.c 13764 2008-11-03 16:55:07Z vboxsync $ */
2/** @file
3 * IPRT - Spinlocks, Ring-0 Driver, Linux.
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-linux-kernel.h"
36
37#include <iprt/spinlock.h>
38#include <iprt/err.h>
39#include <iprt/alloc.h>
40#include <iprt/assert.h>
41#include <iprt/asm.h>
42#include "internal/magics.h"
43
44#include <linux/spinlock.h> /** @todo why is this here and not in the-linux-kernel.h? */
45
46/*******************************************************************************
47* Structures and Typedefs *
48*******************************************************************************/
49/**
50 * Wrapper for the spinlock_t structure.
51 */
52typedef struct RTSPINLOCKINTERNAL
53{
54 /** Spinlock magic value (RTSPINLOCK_MAGIC). */
55 uint32_t volatile u32Magic;
56 /** The linux spinlock structure. */
57 spinlock_t Spinlock;
58#if !defined(CONFIG_SMP) || defined(RT_ARCH_AMD64)
59 /** A placeholder on Uni systems so we won't piss off RTMemAlloc(). */
60 void *pvUniDummy;
61#endif
62} RTSPINLOCKINTERNAL, *PRTSPINLOCKINTERNAL;
63
64
65
66RTDECL(int) RTSpinlockCreate(PRTSPINLOCK pSpinlock)
67{
68 /*
69 * Allocate.
70 */
71 PRTSPINLOCKINTERNAL pSpinlockInt;
72 Assert(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *));
73 pSpinlockInt = (PRTSPINLOCKINTERNAL)RTMemAlloc(sizeof(*pSpinlockInt));
74 if (!pSpinlockInt)
75 return VERR_NO_MEMORY;
76 /*
77 * Initialize and return.
78 */
79 pSpinlockInt->u32Magic = RTSPINLOCK_MAGIC;
80 spin_lock_init(&pSpinlockInt->Spinlock);
81
82 *pSpinlock = pSpinlockInt;
83 return VINF_SUCCESS;
84}
85
86
87RTDECL(int) RTSpinlockDestroy(RTSPINLOCK Spinlock)
88{
89 /*
90 * Validate input.
91 */
92 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
93 if (!pSpinlockInt)
94 return VERR_INVALID_PARAMETER;
95 if (pSpinlockInt->u32Magic != RTSPINLOCK_MAGIC)
96 {
97 AssertMsgFailed(("Invalid spinlock %p magic=%#x\n", pSpinlockInt, pSpinlockInt->u32Magic));
98 return VERR_INVALID_PARAMETER;
99 }
100
101 ASMAtomicIncU32(&pSpinlockInt->u32Magic);
102 RTMemFree(pSpinlockInt);
103 return VINF_SUCCESS;
104}
105
106
107RTDECL(void) RTSpinlockAcquireNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
108{
109 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
110 AssertMsg(pSpinlockInt && pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC,
111 ("pSpinlockInt=%p u32Magic=%08x\n", pSpinlockInt, pSpinlockInt ? (int)pSpinlockInt->u32Magic : 0));
112 NOREF(pSpinlockInt);
113
114 spin_lock_irqsave(&pSpinlockInt->Spinlock, pTmp->flFlags);
115}
116
117
118RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
119{
120 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
121 AssertMsg(pSpinlockInt && pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC,
122 ("pSpinlockInt=%p u32Magic=%08x\n", pSpinlockInt, pSpinlockInt ? (int)pSpinlockInt->u32Magic : 0));
123 NOREF(pSpinlockInt);
124
125 spin_unlock_irqrestore(&pSpinlockInt->Spinlock, pTmp->flFlags);
126}
127
128
129RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
130{
131 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
132 AssertMsg(pSpinlockInt && pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC,
133 ("pSpinlockInt=%p u32Magic=%08x\n", pSpinlockInt, pSpinlockInt ? (int)pSpinlockInt->u32Magic : 0));
134 NOREF(pSpinlockInt); NOREF(pTmp);
135
136 spin_lock(&pSpinlockInt->Spinlock);
137}
138
139
140RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
141{
142 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
143 AssertMsg(pSpinlockInt && pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC,
144 ("pSpinlockInt=%p u32Magic=%08x\n", pSpinlockInt, pSpinlockInt ? (int)pSpinlockInt->u32Magic : 0));
145 NOREF(pSpinlockInt); NOREF(pTmp);
146
147 spin_unlock(&pSpinlockInt->Spinlock);
148}
149
150#if defined(IN_GUEST_R0) && defined(IN_MODULE)
151EXPORT_SYMBOL(RTSpinlockCreate);
152EXPORT_SYMBOL(RTSpinlockDestroy);
153EXPORT_SYMBOL(RTSpinlockAcquireNoInts);
154EXPORT_SYMBOL(RTSpinlockReleaseNoInts);
155#endif
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