VirtualBox

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

Last change on this file since 55998 was 52618, checked in by vboxsync, 10 years ago

HostDrivers, Runtime, Devices, Additions: TSC delta measurement and other changes resulting from bumping supdrv major version. TSC delta measurement currently disabled.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 4.0 KB
Line 
1/* $Id: spinlock-r0drv-os2.cpp 52618 2014-09-05 12:07:29Z vboxsync $ */
2/** @file
3 * IPRT - 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#ifdef RT_STRICT
42# include <iprt/asm-amd64-x86.h>
43#endif
44
45#include "internal/magics.h"
46
47
48/*******************************************************************************
49* Structures and Typedefs *
50*******************************************************************************/
51/**
52 * Wrapper for the SpinLock_t type.
53 */
54typedef struct RTSPINLOCKINTERNAL
55{
56 /** Spinlock magic value (RTSPINLOCK_MAGIC). */
57 uint32_t volatile u32Magic;
58 /** Spinlock creation flags. */
59 uint32_t fFlags;
60 /** The OS/2 spinlock structure. */
61 SpinLock_t Spinlock;
62} RTSPINLOCKINTERNAL, *PRTSPINLOCKINTERNAL;
63
64
65RTDECL(int) RTSpinlockCreate(PRTSPINLOCK pSpinlock, uint32_t fFlags, const char *pszName)
66{
67 AssertReturn(fFlags == RTSPINLOCK_FLAGS_INTERRUPT_SAFE || fFlags == RTSPINLOCK_FLAGS_INTERRUPT_UNSAFE, VERR_INVALID_PARAMETER);
68
69 /*
70 * Allocate.
71 */
72 AssertCompile(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *));
73 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)RTMemAlloc(sizeof(*pThis));
74 if (!pThis)
75 return VERR_NO_MEMORY;
76
77 /*
78 * Initialize & return.
79 */
80 pThis->u32Magic = RTSPINLOCK_MAGIC;
81 pThis->fFlags = fFlags;
82 KernAllocSpinLock(&pThis->Spinlock);
83 *pSpinlock = pThis;
84 return VINF_SUCCESS;
85}
86
87
88RTDECL(int) RTSpinlockDestroy(RTSPINLOCK Spinlock)
89{
90 /*
91 * Validate input.
92 */
93 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
94 if (!pThis)
95 return VERR_INVALID_PARAMETER;
96 AssertMsgReturn(pThis->u32Magic == RTSPINLOCK_MAGIC,
97 ("Invalid spinlock %p magic=%#x\n", pThis, pThis->u32Magic),
98 VERR_INVALID_PARAMETER);
99
100 /*
101 * Make the lock invalid and release the memory.
102 */
103 ASMAtomicIncU32(&pThis->u32Magic);
104 KernFreeSpinLock(&pThis->Spinlock);
105 RTMemFree(pThis);
106 return VINF_SUCCESS;
107}
108
109
110RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock)
111{
112 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
113 AssertPtr(pThis);
114 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
115
116 KernAcquireSpinLock(&pThis->Spinlock);
117 Assert(!ASMIntAreEnabled()); /** @todo verify that interrupts are disabled. */
118}
119
120
121RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock)
122{
123 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
124 AssertPtr(pThis);
125 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
126
127 KernReleaseSpinLock(&pThis->Spinlock);
128}
129
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