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