spinlock-r0drv-solaris.c revision f85630691753e2acd5099c3079b3e6d40c049a62
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * IPRT - Spinlocks, Ring-0 Driver, Solaris.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * available from http://www.virtualbox.org. This file is free software;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * General Public License (GPL) as published by the Free Software
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * The contents of this file may alternatively be used under the terms
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * of the Common Development and Distribution License Version 1.0
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * VirtualBox OSE distribution, in which case the provisions of the
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * CDDL are applicable instead of those of the GPL.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * You may elect to license modified versions of this file under the
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync * terms and conditions of either the GPL or the CDDL or both.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * additional information or have any questions.
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync/*******************************************************************************
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync* Header Files *
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync*******************************************************************************/
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync/*******************************************************************************
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync* Structures and Typedefs *
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync*******************************************************************************/
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Wrapper for the struct mutex type.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /** Spinlock magic value (RTSPINLOCK_MAGIC). */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /** A Solaris spinlock. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync * Allocate.
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync AssertCompile(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *));
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)RTMemAlloc(sizeof(*pSpinlockInt));
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync * Initialize & return.
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync mutex_init(&pSpinlockInt->Mtx, "IPRT Spinlock", MUTEX_SPIN, (void *)ipltospl(DISP_LEVEL));
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync * Validate input.
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync AssertMsgReturn(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC,
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync ("Invalid spinlock %p magic=%#x\n", pSpinlockInt, pSpinlockInt->u32Magic),
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync * Make the lock invalid and release the memory.
8bc8d66f188d5357155b8340e2d489573be2b607vboxsyncRTDECL(void) RTSpinlockAcquireNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncRTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncRTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync Assert(pSpinlockInt->u32Magic == RTSPINLOCK_MAGIC);
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync /* Spinlocks are not preemptible, so we cannot be rescheduled. */
2f3883b126a405f92b19e829472f614c7352b4f9vboxsync pTmp->uFlags = idAssertCpu != NIL_RTCPUID ? idAssertCpu : RTMpCpuId();
2f3883b126a405f92b19e829472f614c7352b4f9vboxsyncRTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock, PRTSPINLOCKTMP pTmp)
8bc8d66f188d5357155b8340e2d489573be2b607vboxsync PRTSPINLOCKINTERNAL pSpinlockInt = (PRTSPINLOCKINTERNAL)Spinlock;