VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/os2/spinlock-r0drv-os2.cpp@ 1191

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

svn properties.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1/* $Id: spinlock-r0drv-os2.cpp 1191 2007-03-04 20:46:04Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime - Spinlocks, Ring-0 Driver, OS/2.
4 */
5
6/*
7 * Copyright (c) 2007 knut st. osmundsen <[email protected]>
8 *
9 * Permission is hereby granted, free of charge, to any person
10 * obtaining a copy of this software and associated documentation
11 * files (the "Software"), to deal in the Software without
12 * restriction, including without limitation the rights to use,
13 * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following
16 * conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 */
30
31/*******************************************************************************
32* Header Files *
33*******************************************************************************/
34#include "the-os2-kernel.h"
35
36#include <iprt/spinlock.h>
37#include <iprt/err.h>
38#include <iprt/alloc.h>
39#include <iprt/assert.h>
40#include <iprt/asm.h>
41
42
43/*******************************************************************************
44* Structures and Typedefs *
45*******************************************************************************/
46/**
47 * Wrapper for the SpinLock_t type.
48 */
49typedef struct RTSPINLOCKINTERNAL
50{
51 /** Spinlock magic value (RTSPINLOCK_MAGIC). */
52 uint32_t volatile u32Magic;
53 /** The OS/2 spinlock structure. */
54 SpinLock_t Spinlock;
55} RTSPINLOCKINTERNAL, *PRTSPINLOCKINTERNAL;
56
57/** Magic value for RTSPINLOCKINTERNAL::u32Magic. (Terry Pratchett) */
58#define RTSPINLOCK_MAGIC 0x19480428
59
60
61
62RTDECL(int) RTSpinlockCreate(PRTSPINLOCK pSpinlock)
63{
64 /*
65 * Allocate.
66 */
67 AssertCompile(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *));
68 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)RTMemAlloc(sizeof(*pSpinlockInt));
69 if (!pSpinlockInt)
70 return VERR_NO_MEMORY;
71
72 /*
73 * Initialize & return.
74 */
75 pSpinlockInt->u32Magic = RTSPINLOCK_MAGIC;
76 KernAllocSpinLock(&pSpinlockInt->Spinlock);
77 *pSpinlock = pSpinlockInt;
78 return VINF_SUCCESS;
79}
80
81
82RTDECL(int) RTSpinlockDestroy(RTSPINLOCK Spinlock)
83{
84 /*
85 * Validate input.
86 */
87 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
88 if (!pSpinlockInt)
89 return VERR_INVALID_PARAMETER;
90 AssertMsgReturn(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC,
91 ("Invalid spinlock %p magic=%#x\n", pSpinlockInt, pSpinlockInt->u32Magic),
92 VERR_INVALID_PARAMETER);
93
94 /*
95 * Make the lock invalid and release the memory.
96 */
97 ASMAtomicIncU32(&pSpinlockInt->u32Magic);
98 KernFreeSpinLock(&pSpinlockInt->Spinlock);
99 RTMemFree(pSpinlockInt);
100 return VINF_SUCCESS;
101}
102
103
104RTDECL(void) RTSpinlockAcquireNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
105{
106 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
107 AssertPtr(pSpinlockInt);
108 Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
109
110 KernAcquireSpinLock(&pSpinlockInt->Spinlock);
111 NOREF(pTmp);
112}
113
114
115RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
116{
117 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
118 AssertPtr(pSpinlockInt);
119 Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
120
121 KernReleaseSpinLock(&pSpinlockInt->Spinlock);
122 NOREF(pTmp);
123}
124
125
126RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
127{
128 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
129 AssertPtr(pSpinlockInt);
130 Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
131
132 KernAcquireSpinLock(&pSpinlockInt->Spinlock);
133 NOREF(pTmp);
134}
135
136
137RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
138{
139 PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
140 AssertPtr(pSpinlockInt);
141 Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
142
143 KernReleaseSpinLock(&pSpinlockInt->Spinlock);
144 NOREF(pTmp);
145}
146
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