semmutex-r0drv-solaris.c revision 760446f710619a9daa6cedc7f0601f49e4ea3442
/* $Id$ */
/** @file
* IPRT - Mutex Semaphores, Ring-0 Driver, Solaris.
*/
/*
* Copyright (C) 2006-2010 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-solaris-kernel.h"
#include <iprt/semaphore.h>
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
# include <iprt/asm-amd64-x86.h>
#endif
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Wrapper for the solaris semaphore structure.
*/
typedef struct RTSEMMUTEXINTERNAL
{
/** Magic value (RTSEMMUTEX_MAGIC). */
/** The number of recursions. */
/** The number of threads waiting for the mutex. */
/** The number of threads referencing us. */
/** The owner thread, NIL_RTNATIVETHREAD if none. */
/** The mutex object for synchronization. */
/** The condition variable for synchronization. */
{
/*
* Allocate.
*/
if (RT_UNLIKELY(!pThis))
return VERR_NO_MEMORY;
/*
* Initialize.
*/
pThis->cRecursions = 0;
return VINF_SUCCESS;
}
{
/*
* Validate.
*/
if (pThis == NIL_RTSEMMUTEX)
return VINF_SUCCESS;
AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
/*
* Invalidate the magic to indicate the mutex is being destroyed.
*/
{
/*
* Wake up all waiters, last waiter thread cleans up.
*/
}
{
/*
* We're the last waiter, destroy.
*/
}
else
{
/*
* We're not the last waiting thread to be woken up. Just relinquish & bail.
*/
}
return VINF_SUCCESS;
}
/**
* Worker for rtSemMutexSolarisRequest that handles the case where we go to sleep.
*
* @returns VINF_SUCCESS, VERR_INTERRUPTED, or VERR_SEM_DESTROYED.
* Returns without owning the mutex.
* @param pThis The mutex instance.
* @param cMillies The timeout, must be > 0 or RT_INDEFINITE_WAIT.
* @param fInterruptible The wait type.
*
* @remarks This needs to be called with the mutex object held!
*/
bool fInterruptible)
{
int rc = VERR_GENERAL_FAILURE;
/*
* Now we wait (sleep; although might spin and then sleep) & reference the mutex.
*/
if (cMillies != RT_INDEFINITE_WAIT)
{
if (fInterruptible)
else
}
else
{
if (fInterruptible)
else
{
rc = 1;
}
}
if (rc > 0)
{
{
{
/*
* Woken up by a release from another thread.
*/
rc = VINF_SUCCESS;
}
else
{
/*
* Interrupted by some signal.
*/
}
}
else
{
/*
* Awakened due to the destruction-in-progress broadcast.
* We will cleanup if we're the last waiter.
*/
}
}
else if (rc == -1)
{
/*
* Timed out.
*/
rc = VERR_TIMEOUT;
}
else
{
/*
* Condition may not have been met, returned due to pending signal.
*/
}
{
return rc;
}
return rc;
}
/**
* Internal worker.
*/
DECLINLINE(int) rtSemMutexSolarisRequest(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies, bool fInterruptible)
{
int rc = VERR_GENERAL_FAILURE;
/*
* Validate.
*/
AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
/*
* Lock it and check if it's a recursion.
*/
{
pThis->cRecursions++;
rc = VINF_SUCCESS;
}
/*
* Not a recursion, claim the unowned mutex if we're there are no waiters.
*/
{
rc = VINF_SUCCESS;
}
/*
* A polling call?
*/
else if (cMillies == 0)
rc = VERR_TIMEOUT;
/*
* No, we really need to get to sleep.
*/
else
return rc;
}
{
}
RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
{
}
{
}
RTDECL(int) RTSemMutexRequestNoResumeDebug(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
{
}
{
int rc;
/*
* Validate.
*/
AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
/*
* Take the lock and release one recursion.
*/
{
if (--pThis->cRecursions == 0)
{
/*
* If there are any waiters, signal one of them.
*/
}
rc = VINF_SUCCESS;
}
else
rc = VERR_NOT_OWNER;
return rc;
}
{
bool fOwned = false;
/*
* Validate.
*/
AssertPtrReturn(pThis, false);
AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), false);
/*
* Check if this is the owner.
*/
return fOwned;
}