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