VirtualBox

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

Last change on this file since 78120 was 77120, checked in by vboxsync, 6 years ago

IPRT: Some license header cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 5.5 KB
Line 
1/* $Id: spinlock-r0drv-os2.cpp 77120 2019-02-01 15:08:46Z vboxsync $ */
2/** @file
3 * IPRT - Spinlocks, Ring-0 Driver, OS/2.
4 */
5
6/*
7 * Contributed by knut st. osmundsen.
8 *
9 * Copyright (C) 2007-2019 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * The contents of this file may alternatively be used under the terms
20 * of the Common Development and Distribution License Version 1.0
21 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
22 * VirtualBox OSE distribution, in which case the provisions of the
23 * CDDL are applicable instead of those of the GPL.
24 *
25 * You may elect to license modified versions of this file under the
26 * terms and conditions of either the GPL or the CDDL or both.
27 *
28 * --------------------------------------------------------------------
29 *
30 * This code is based on:
31 *
32 * Copyright (c) 2007 knut st. osmundsen <[email protected]>
33 *
34 * Permission is hereby granted, free of charge, to any person
35 * obtaining a copy of this software and associated documentation
36 * files (the "Software"), to deal in the Software without
37 * restriction, including without limitation the rights to use,
38 * copy, modify, merge, publish, distribute, sublicense, and/or sell
39 * copies of the Software, and to permit persons to whom the
40 * Software is furnished to do so, subject to the following
41 * conditions:
42 *
43 * The above copyright notice and this permission notice shall be
44 * included in all copies or substantial portions of the Software.
45 *
46 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
47 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
48 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
49 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
50 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
51 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
52 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
53 * OTHER DEALINGS IN THE SOFTWARE.
54 */
55
56
57/*********************************************************************************************************************************
58* Header Files *
59*********************************************************************************************************************************/
60#include "the-os2-kernel.h"
61
62#include <iprt/spinlock.h>
63#include <iprt/errcore.h>
64#include <iprt/alloc.h>
65#include <iprt/assert.h>
66#include <iprt/asm.h>
67#ifdef RT_STRICT
68# include <iprt/asm-amd64-x86.h>
69#endif
70
71#include "internal/magics.h"
72
73
74/*********************************************************************************************************************************
75* Structures and Typedefs *
76*********************************************************************************************************************************/
77/**
78 * Wrapper for the SpinLock_t type.
79 */
80typedef struct RTSPINLOCKINTERNAL
81{
82 /** Spinlock magic value (RTSPINLOCK_MAGIC). */
83 uint32_t volatile u32Magic;
84 /** Spinlock creation flags. */
85 uint32_t fFlags;
86 /** The OS/2 spinlock structure. */
87 SpinLock_t Spinlock;
88} RTSPINLOCKINTERNAL, *PRTSPINLOCKINTERNAL;
89
90
91RTDECL(int) RTSpinlockCreate(PRTSPINLOCK pSpinlock, uint32_t fFlags, const char *pszName)
92{
93 AssertReturn(fFlags == RTSPINLOCK_FLAGS_INTERRUPT_SAFE || fFlags == RTSPINLOCK_FLAGS_INTERRUPT_UNSAFE, VERR_INVALID_PARAMETER);
94 RT_NOREF(pszName);
95
96 /*
97 * Allocate.
98 */
99 AssertCompile(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *));
100 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)RTMemAlloc(sizeof(*pThis));
101 if (!pThis)
102 return VERR_NO_MEMORY;
103
104 /*
105 * Initialize & return.
106 */
107 pThis->u32Magic = RTSPINLOCK_MAGIC;
108 pThis->fFlags = fFlags;
109 KernAllocSpinLock(&pThis->Spinlock);
110 *pSpinlock = pThis;
111 return VINF_SUCCESS;
112}
113
114
115RTDECL(int) RTSpinlockDestroy(RTSPINLOCK Spinlock)
116{
117 /*
118 * Validate input.
119 */
120 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
121 if (!pThis)
122 return VERR_INVALID_PARAMETER;
123 AssertMsgReturn(pThis->u32Magic == RTSPINLOCK_MAGIC,
124 ("Invalid spinlock %p magic=%#x\n", pThis, pThis->u32Magic),
125 VERR_INVALID_PARAMETER);
126
127 /*
128 * Make the lock invalid and release the memory.
129 */
130 ASMAtomicIncU32(&pThis->u32Magic);
131 KernFreeSpinLock(&pThis->Spinlock);
132 RTMemFree(pThis);
133 return VINF_SUCCESS;
134}
135
136
137RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock)
138{
139 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
140 AssertPtr(pThis);
141 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
142
143 KernAcquireSpinLock(&pThis->Spinlock);
144 Assert(!ASMIntAreEnabled()); /** @todo verify that interrupts are disabled. */
145}
146
147
148RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock)
149{
150 PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
151 AssertPtr(pThis);
152 Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
153
154 KernReleaseSpinLock(&pThis->Spinlock);
155}
156
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