semmutex-r0drv-freebsd.c revision 90e8b000bdf708e8465e9c2cd7ecf1339c27c4aa
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * IPRT - Mutex Semaphores, Ring-0 Driver, FreeBSD.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Copyright (C) 2010 Sun Microsystems, Inc.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * available from http://www.virtualbox.org. This file is free software;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * General Public License (GPL) as published by the Free Software
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * The contents of this file may alternatively be used under the terms
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * of the Common Development and Distribution License Version 1.0
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * VirtualBox OSE distribution, in which case the provisions of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * CDDL are applicable instead of those of the GPL.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * You may elect to license modified versions of this file under the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * terms and conditions of either the GPL or the CDDL or both.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * additional information or have any questions.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/*******************************************************************************
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync* Header Files *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync*******************************************************************************/
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/*******************************************************************************
40839c441cb305d84420565f7ca25403d8177413vboxsync* Structures and Typedefs *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync*******************************************************************************/
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Wrapper for the FreeBSD (sleep) mutex.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Magic value (RTSEMMUTEX_MAGIC). */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The FreeBSD shared/exclusive lock mutex. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTSemMutexCreate(PRTSEMMUTEX phMutexSem)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync AssertCompile(sizeof(RTSEMMUTEXINTERNAL) > sizeof(void *));
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)RTMemAllocZ(sizeof(*pThis));
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync sx_init_flags(&pThis->SxLock, "IPRT Mutex Semaphore", SX_LOCK_RECURSED);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync AssertReturn(ASMAtomicCmpXchgU32(&pThis->u32Magic, RTSEMMUTEX_MAGIC_DEAD, RTSEMMUTEX_MAGIC), VERR_INVALID_HANDLE);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTSemMutexRequest(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * GROSS HACK: poll implementation of timeout.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** @todo Implement timeouts in RTSemMutexRequest. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync } while (RTTimeSystemMilliTS() - StartTS < cMillies);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * GROSS HACK: poll implementation of timeout.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** @todo Implement timeouts and interrupt checks in
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * RTSemMutexRequestNoResume. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync } while (RTTimeSystemMilliTS() - StartTS < cMillies);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTSemMutexRequestNoResumeDebug(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTSemMutexRequestNoResume(hMutexSem, cMillies);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(bool) RTSemMutexIsOwned(RTSEMMUTEX hMutexSem)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), false);