VirtualBox

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

Last change on this file since 4612 was 4071, checked in by vboxsync, 18 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1/* $Id: spinlock-r0drv-linux.c 4071 2007-08-07 17:07:59Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Spinlocks, Ring-0 Driver, Linux.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#include "the-linux-kernel.h"
23
24#include <iprt/spinlock.h>
25#include <iprt/err.h>
26#include <iprt/alloc.h>
27#include <iprt/assert.h>
28#include <iprt/asm.h>
29#include "internal/magics.h"
30
31#include <linux/spinlock.h> /** @todo why is this here and not in the-linux-kernel.h? */
32
33
34/*******************************************************************************
35* Structures and Typedefs *
36*******************************************************************************/
37/**
38 * Wrapper for the spinlock_t structure.
39 */
40typedef struct RTSPINLOCKINTERNAL
41{
42 /** Spinlock magic value (RTSPINLOCK_MAGIC). */
43 uint32_t volatile u32Magic;
44 /** The linux spinlock structure. */
45 spinlock_t Spinlock;
46#if !defined(CONFIG_SMP) || defined(RT_ARCH_AMD64)
47 /** A placeholder on Uni systems so we won't piss off RTMemAlloc(). */
48 void *pvUniDummy;
49#endif
50} RTSPINLOCKINTERNAL, *PRTSPINLOCKINTERNAL;
51
52
53
54RTDECL(int) RTSpinlockCreate(PRTSPINLOCK pSpinlock)
55{
56 /*
57 * Allocate.
58 */
59 PRTSPINLOCKINTERNAL pSpinlockInt;
60 Assert(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *));
61 pSpinlockInt = (PRTSPINLOCKINTERNAL)RTMemAlloc(sizeof(*pSpinlockInt));
62 if (!pSpinlockInt)
63 return VERR_NO_MEMORY;
64 /*
65 * Initialize and return.
66 */
67 pSpinlockInt->u32Magic = RTSPINLOCK_MAGIC;
68 spin_lock_init(&pSpinlockInt->Spinlock);
69
70 *pSpinlock = pSpinlockInt;
71 return VINF_SUCCESS;
72}
73
74
75RTDECL(int) RTSpinlockDestroy(RTSPINLOCK Spinlock)
76{
77 /*
78 * Validate input.
79 */
80 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
81 if (!pSpinlockInt)
82 return VERR_INVALID_PARAMETER;
83 if (pSpinlockInt->u32Magic != RTSPINLOCK_MAGIC)
84 {
85 AssertMsgFailed(("Invalid spinlock %p magic=%#x\n", pSpinlockInt, pSpinlockInt->u32Magic));
86 return VERR_INVALID_PARAMETER;
87 }
88
89 ASMAtomicIncU32(&pSpinlockInt->u32Magic);
90 RTMemFree(pSpinlockInt);
91 return VINF_SUCCESS;
92}
93
94
95RTDECL(void) RTSpinlockAcquireNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
96{
97 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
98 AssertMsg(pSpinlockInt && pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC,
99 ("pSpinlockInt=%p u32Magic=%08x\n", pSpinlockInt, pSpinlockInt ? (int)pSpinlockInt->u32Magic : 0));
100 NOREF(pSpinlockInt);
101
102 spin_lock_irqsave(&pSpinlockInt->Spinlock, pTmp->flFlags);
103}
104
105
106RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
107{
108 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
109 AssertMsg(pSpinlockInt && pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC,
110 ("pSpinlockInt=%p u32Magic=%08x\n", pSpinlockInt, pSpinlockInt ? (int)pSpinlockInt->u32Magic : 0));
111 NOREF(pSpinlockInt);
112
113 spin_unlock_irqrestore(&pSpinlockInt->Spinlock, pTmp->flFlags);
114}
115
116
117RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
118{
119 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
120 AssertMsg(pSpinlockInt && pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC,
121 ("pSpinlockInt=%p u32Magic=%08x\n", pSpinlockInt, pSpinlockInt ? (int)pSpinlockInt->u32Magic : 0));
122 NOREF(pSpinlockInt); NOREF(pTmp);
123
124 spin_lock(&pSpinlockInt->Spinlock);
125}
126
127
128RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
129{
130 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
131 AssertMsg(pSpinlockInt && pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC,
132 ("pSpinlockInt=%p u32Magic=%08x\n", pSpinlockInt, pSpinlockInt ? (int)pSpinlockInt->u32Magic : 0));
133 NOREF(pSpinlockInt); NOREF(pTmp);
134
135 spin_unlock(&pSpinlockInt->Spinlock);
136}
137
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