VirtualBox

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

Last change on this file since 76734 was 76452, checked in by vboxsync, 6 years ago

IPRT: Ran scm --fix-err-h. bugref:9344

  • 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 76452 2018-12-25 01:41:25Z 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/*********************************************************************************************************************************
33* Header Files *
34*********************************************************************************************************************************/
35#include "the-os2-kernel.h"
36
37#include <iprt/spinlock.h>
38#include <iprt/errcore.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 RT_NOREF(pszName);
70
71 /*
72 * Allocate.
73 */
74 AssertCompile(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *));
75 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)RTMemAlloc(sizeof(*pThis));
76 if (!pThis)
77 return VERR_NO_MEMORY;
78
79 /*
80 * Initialize & return.
81 */
82 pThis->u32Magic = RTSPINLOCK_MAGIC;
83 pThis->fFlags = fFlags;
84 KernAllocSpinLock(&pThis->Spinlock);
85 *pSpinlock = pThis;
86 return VINF_SUCCESS;
87}
88
89
90RTDECL(int) RTSpinlockDestroy(RTSPINLOCK Spinlock)
91{
92 /*
93 * Validate input.
94 */
95 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
96 if (!pThis)
97 return VERR_INVALID_PARAMETER;
98 AssertMsgReturn(pThis->u32Magic == RTSPINLOCK_MAGIC,
99 ("Invalid spinlock %p magic=%#x\n", pThis, pThis->u32Magic),
100 VERR_INVALID_PARAMETER);
101
102 /*
103 * Make the lock invalid and release the memory.
104 */
105 ASMAtomicIncU32(&pThis->u32Magic);
106 KernFreeSpinLock(&pThis->Spinlock);
107 RTMemFree(pThis);
108 return VINF_SUCCESS;
109}
110
111
112RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock)
113{
114 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
115 AssertPtr(pThis);
116 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
117
118 KernAcquireSpinLock(&pThis->Spinlock);
119 Assert(!ASMIntAreEnabled()); /** @todo verify that interrupts are disabled. */
120}
121
122
123RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock)
124{
125 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
126 AssertPtr(pThis);
127 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
128
129 KernReleaseSpinLock(&pThis->Spinlock);
130}
131
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