semfastmutex-r0drv-darwin.cpp revision 05afe08870681beb0792f384475077c988916762
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * IPRT - Fast Mutex Semaphores, Ring-0 Driver, Darwin.
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * Copyright (C) 2006-2010 Sun Microsystems, Inc.
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * This file is part of VirtualBox Open Source Edition (OSE), as
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * available from http://www.virtualbox.org. This file is free software;
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * you can redistribute it and/or modify it under the terms of the GNU
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * General Public License (GPL) as published by the Free Software
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * Foundation, in version 2 as it comes in the "COPYING" file of the
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * The contents of this file may alternatively be used under the terms
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * of the Common Development and Distribution License Version 1.0
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * VirtualBox OSE distribution, in which case the provisions of the
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * CDDL are applicable instead of those of the GPL.
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * You may elect to license modified versions of this file under the
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * terms and conditions of either the GPL or the CDDL or both.
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * Clara, CA 95054 USA or visit http://www.sun.com if you need
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * additional information or have any questions.
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden/*******************************************************************************
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden* Header Files *
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden*******************************************************************************/
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden/*******************************************************************************
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden* Structures and Typedefs *
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden*******************************************************************************/
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden * Wrapper for the darwin semaphore structure.
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden /** Magic value (RTSEMFASTMUTEX_MAGIC). */
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden /** The mutex. */
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden} RTSEMFASTMUTEXINTERNAL, *PRTSEMFASTMUTEXINTERNAL;
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil MaddenRTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx)
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *));
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden AssertPtrReturn(phFastMtx, VERR_INVALID_POINTER);
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden PRTSEMFASTMUTEXINTERNAL pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pThis));
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden pThis->pMtx = lck_mtx_alloc_init(g_pDarwinLockGroup, LCK_ATTR_NULL);
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil MaddenRTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx)
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden ASMAtomicWriteU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil MaddenRTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx)
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil MaddenRTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx)
971de91bce73bb05574a64c4304daf9f60e2b5b8Neil Madden AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);