spinlock-r0drv-os2.cpp revision 5b281ba489ca18f0380d7efc7a5108b606cce449
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync/* $Id$ */
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync/** @file
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * IPRT - Spinlocks, Ring-0 Driver, OS/2.
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync */
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync/*
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync *
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * Permission is hereby granted, free of charge, to any person
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * obtaining a copy of this software and associated documentation
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * files (the "Software"), to deal in the Software without
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * restriction, including without limitation the rights to use,
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * copy, modify, merge, publish, distribute, sublicense, and/or sell
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * copies of the Software, and to permit persons to whom the
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * Software is furnished to do so, subject to the following
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * conditions:
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync *
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * The above copyright notice and this permission notice shall be
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * included in all copies or substantial portions of the Software.
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync *
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * OTHER DEALINGS IN THE SOFTWARE.
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync */
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync/*******************************************************************************
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync* Header Files *
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync*******************************************************************************/
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync#include "the-os2-kernel.h"
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync#include <iprt/spinlock.h>
a8e1fc1b96d1436189fdb4530d31f20b88b70ea1vboxsync#include <iprt/err.h>
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync#include <iprt/alloc.h>
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync#include <iprt/assert.h>
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync#include <iprt/asm.h>
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync#include "internal/magics.h"
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync/*******************************************************************************
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync* Structures and Typedefs *
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync*******************************************************************************/
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync/**
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync * Wrapper for the SpinLock_t type.
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync */
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsynctypedef struct RTSPINLOCKINTERNAL
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync{
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync /** Spinlock magic value (RTSPINLOCK_MAGIC). */
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync uint32_t volatile u32Magic;
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync /** The OS/2 spinlock structure. */
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync SpinLock_t Spinlock;
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync} RTSPINLOCKINTERNAL, *PRTSPINLOCKINTERNAL;
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync
bd44be5c996657f50cadcb987ee2879f4114d249vboxsyncRTDECL(int) RTSpinlockCreate(PRTSPINLOCK pSpinlock)
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync{
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync /*
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync * Allocate.
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync */
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync AssertCompile(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *));
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)RTMemAlloc(sizeof(*pSpinlockInt));
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync if (!pSpinlockInt)
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync return VERR_NO_MEMORY;
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync /*
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync * Initialize & return.
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync */
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync pSpinlockInt->u32Magic = RTSPINLOCK_MAGIC;
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync KernAllocSpinLock(&pSpinlockInt->Spinlock);
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync *pSpinlock = pSpinlockInt;
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync return VINF_SUCCESS;
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync}
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsyncRTDECL(int) RTSpinlockDestroy(RTSPINLOCK Spinlock)
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync{
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync /*
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync * Validate input.
f5663ddc90362ab5cfe32e277fa34f2b057e8cfdvboxsync */
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync if (!pSpinlockInt)
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync return VERR_INVALID_PARAMETER;
bd44be5c996657f50cadcb987ee2879f4114d249vboxsync AssertMsgReturn(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC,
("Invalid spinlock %p magic=%#x\n", pSpinlockInt, pSpinlockInt->u32Magic),
VERR_INVALID_PARAMETER);
/*
* Make the lock invalid and release the memory.
*/
ASMAtomicIncU32(&pSpinlockInt->u32Magic);
KernFreeSpinLock(&pSpinlockInt->Spinlock);
RTMemFree(pSpinlockInt);
return VINF_SUCCESS;
}
RTDECL(void) RTSpinlockAcquireNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
{
PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
AssertPtr(pSpinlockInt);
Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
KernAcquireSpinLock(&pSpinlockInt->Spinlock);
NOREF(pTmp);
}
RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
{
PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
AssertPtr(pSpinlockInt);
Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
KernReleaseSpinLock(&pSpinlockInt->Spinlock);
NOREF(pTmp);
}
RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
{
PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
AssertPtr(pSpinlockInt);
Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
KernAcquireSpinLock(&pSpinlockInt->Spinlock);
NOREF(pTmp);
}
RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
{
PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
AssertPtr(pSpinlockInt);
Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
KernReleaseSpinLock(&pSpinlockInt->Spinlock);
NOREF(pTmp);
}