semmutex-r0drv-haiku.c revision 9fc464631dc4a68fbb5eb6419d61fbe91b6b16bd
/* $Id$ */
/** @file
* IPRT - Mutex Semaphores, Ring-0 Driver, Haiku.
*/
/*
* Copyright (C) 2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "the-haiku-kernel.h"
#include <iprt/semaphore.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Wrapper for the Haiku (sleep) mutex.
*/
/* XXX: not optimal, maybe should use the (private)
kernel recursive_lock ? (but it's not waitable) */
typedef struct RTSEMMUTEXINTERNAL
{
/** Magic value (RTSEMMUTEX_MAGIC). */
/** Kernel semaphore. */
/** Current holder */
/** Recursion count */
{
AssertCompile(sizeof(RTSEMMUTEXINTERNAL) > sizeof(void *));
if (RT_UNLIKELY(!pThis))
return VERR_NO_MEMORY;
{
pThis->cRecursion = 0;
*phMutexSem = pThis;
return VINF_SUCCESS;
}
return VERR_TOO_MANY_SEMAPHORES; /** @todo r=ramshankar: use RTErrConvertFromHaikuKernReturn */
}
{
if (pThis == NIL_RTSEMMUTEX)
return VINF_SUCCESS;
AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
AssertReturn(ASMAtomicCmpXchgU32(&pThis->u32Magic, RTSEMMUTEX_MAGIC_DEAD, RTSEMMUTEX_MAGIC), VERR_INVALID_HANDLE);
return VINF_SUCCESS;
}
/** @todo doxygen */
{
int rc;
AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
{
return VINF_SUCCESS;
}
if (fFlags & RTSEMWAIT_FLAGS_INDEFINITE)
else
{
if (fFlags & RTSEMWAIT_FLAGS_NANOSECS)
else if (fFlags & RTSEMWAIT_FLAGS_MILLISECS)
else
return VERR_INVALID_PARAMETER;
if (fFlags & RTSEMWAIT_FLAGS_RELATIVE)
else if (fFlags & RTSEMWAIT_FLAGS_ABSOLUTE)
else
return VERR_INVALID_PARAMETER;
}
flags |= B_CAN_INTERRUPT;
switch (status)
{
case B_OK:
rc = VINF_SUCCESS;
break;
case B_BAD_SEM_ID:
break;
case B_INTERRUPTED:
break;
case B_WOULD_BLOCK:
/* fallthrough? */
case B_TIMED_OUT:
rc = VERR_TIMEOUT;
break;
default:
break;
}
return rc;
}
{
return rtSemMutexRequestEx(hMutexSem, RTSEMWAIT_FLAGS_RELATIVE | RTSEMWAIT_FLAGS_RESUME | RTSEMWAIT_FLAGS_MILLISECS, cMillies);
}
RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
{
}
{
return rtSemMutexRequestEx(hMutexSem, RTSEMWAIT_FLAGS_RELATIVE | RTSEMWAIT_FLAGS_NORESUME | RTSEMWAIT_FLAGS_MILLISECS, cMillies);
}
RTDECL(int) RTSemMutexRequestNoResumeDebug(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
{
}
{
AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
return VERR_INVALID_HANDLE;
if (--pThis->cRecursion == 0)
{
}
return VINF_SUCCESS;
}
{
AssertPtrReturn(pThis, false);
AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), false);
}