VirtualBox

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

Last change on this file since 73299 was 57358, checked in by vboxsync, 9 years ago

*: scm cleanup run.

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