PDMAllCritSect.cpp revision 3857503560316b1952243b559dec05f87c561404
/* $Id$ */
/** @file
* PDM - Critical Sections, All Contexts.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "PDMInternal.h"
#ifdef IN_RING3
# include <iprt/semaphore.h>
#endif
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** The number loops to spin for in ring-3. */
#define PDMCRITSECT_SPIN_COUNT_R3 20
/** The number loops to spin for in ring-0. */
#define PDMCRITSECT_SPIN_COUNT_R0 256
/** The number loops to spin for in the raw-mode context. */
#define PDMCRITSECT_SPIN_COUNT_RC 256
/** @def PDMCRITSECT_STRICT
#if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
# define PDMCRITSECT_STRICT
#endif
/**
* Gets the ring-3 native thread handle of the calling thread.
*
* @returns native thread handle (ring-3).
* @param pCritSect The critical section. This is used in R0 and RC.
*/
{
#ifdef IN_RING3
#else
AssertMsgReturn(pCritSect->s.Core.u32Magic == RTCRITSECT_MAGIC, ("%RX32\n", pCritSect->s.Core.u32Magic),
#endif
return hNativeSelf;
}
/**
* Tail code called when we've wont the battle for the lock.
*
* @returns VINF_SUCCESS.
*
* @param pCritSect The critical section.
* @param hNativeSelf The native handle of this thread.
*/
{
AssertMsg(pCritSect->s.Core.NativeThreadOwner == NIL_RTNATIVETHREAD, ("NativeThreadOwner=%p\n", pCritSect->s.Core.NativeThreadOwner));
# if defined(PDMCRITSECT_STRICT) && defined(IN_RING3)
# endif
return VINF_SUCCESS;
}
#ifdef IN_RING3
/**
* Deals with the contended case in ring-3.
*
* @returns VINF_SUCCESS or VERR_SEM_DESTROYED.
* @param pCritSect The critsect.
* @param hNativeSelf The native thread handle.
*/
{
/*
* Start waiting.
*/
/*
* The wait loop.
*/
# ifdef PDMCRITSECT_STRICT
if (hSelf == NIL_RTTHREAD)
# endif
for (;;)
{
# ifdef PDMCRITSECT_STRICT
# endif
# ifdef PDMCRITSECT_STRICT
# endif
return VERR_SEM_DESTROYED;
if (rc == VINF_SUCCESS)
}
/* won't get here */
}
#endif /* IN_RING3 */
/**
* Enters a PDM critical section.
*
* @returns VINF_SUCCESS if entered successfully.
* @returns VERR_SEM_DESTROYED if the critical section is dead.
*
* @param pCritSect The PDM critical section to enter.
* @param rcBusy The status code to return when we're in GC or R0
* and the section is busy.
*/
{
/*
* If the critical section has already been destroyed, then inform the caller.
*/
/*
* See if we're lucky.
*/
/* Not owned ... */
/* ... or nested. */
{
return VINF_SUCCESS;
}
/*
* Spin for a bit without incrementing the counter.
*/
/** @todo Move this to cfgm variables since it doesn't make sense to spin on UNI
* cpu systems. */
while (cSpinsLeft-- > 0)
{
}
#ifdef IN_RING3
/*
* Take the slow path.
*/
#else
/*
* Return busy.
*/
return rcBusy;
#endif
}
/**
* Try enter a critical section.
*
* @retval VINF_SUCCESS on success.
* @retval VERR_SEM_BUSY if the critsect was owned.
* @retval VERR_SEM_NESTED if nested enter on a no nesting section. (Asserted.)
* @retval VERR_SEM_DESTROYED if RTCritSectDelete was called while waiting.
*
* @param pCritSect The critical section.
*/
{
/*
* If the critical section has already been destroyed, then inform the caller.
*/
/*
* See if we're lucky.
*/
/* Not owned ... */
/* ... or nested. */
{
return VINF_SUCCESS;
}
/* no spinning */
/*
* Return busy.
*/
#ifdef IN_RING3
#else
#endif
LogFlow(("PDMCritSectTryEnter: locked\n"));
return VERR_SEM_BUSY;
}
#ifdef IN_RING3
/**
* Enters a PDM critical section.
*
* @returns VINF_SUCCESS if entered successfully.
* @returns VERR_SEM_DESTROYED if the critical section is dead.
*
* @param pCritSect The PDM critical section to enter.
* @param fCallHost Whether this is a VMMGCCallHost() or VMMR0CallHost() request.
*/
{
if ( rc == VINF_SUCCESS
&& fCallHost
{
}
return rc;
}
#endif /* IN_RING3 */
/**
* Leaves a critical section entered with PDMCritSectEnter().
*
* @param pCritSect The PDM critical section to leave.
*/
{
/*
* Nested leave.
*/
{
return;
}
#if defined(IN_RING3) /// @todo enable this later - || defined(IN_RING0)
/*
* Leave for real.
*/
/* update members. */
# ifdef IN_RING3
# if defined(PDMCRITSECT_STRICT)
# endif
# endif
/* stop and decrement lockers. */
{
/* Someone is waiting, wake up one of them. */
}
# ifdef IN_RING3
/* Signal exit event. */
if (hEventToSignal != NIL_RTSEMEVENT)
{
}
# endif
#else /* IN_RC */
/*
* Try leave it.
*/
{
return;
/* darn, someone raced in on us. */
}
/*
* Queue the request.
*/
#endif /* IN_RC */
}
/**
* Process the critical sections queued for ring-3 'leave'.
*
* @param pVCpu The VMCPU handle.
*/
{
for (RTUINT i = 0; i < c; i++)
{
# ifdef IN_RING3
# else
PPDMCRITSECT pCritSect = (PPDMCRITSECT)MMHyperR3ToCC(pVCpu->CTX_SUFF(pVM), pVCpu->pdm.s.apQueuedCritSectsLeaves[i]);
# endif
}
}
#endif /* IN_RING3 || IN_RING0 */
/**
* Checks the caller is the owner of the critical section.
*
* @returns true if owner.
* @returns false if not owner.
* @param pCritSect The critical section.
*/
{
#ifdef IN_RING3
#else
return false;
#endif
}
/**
* Checks the specified VCPU is the owner of the critical section.
*
* @returns true if owner.
* @returns false if not owner.
* @param pCritSect The critical section.
* @param idCpu VCPU id
*/
{
#ifdef IN_RING3
#else
#endif
}
/**
* Checks if somebody currently owns the critical section.
*
* @returns true if locked.
* @returns false if not locked.
*
* @param pCritSect The critical section.
*
* @remarks This doesn't prove that no deadlocks will occur later on; it's
* just a debugging tool
*/
{
}
/**
* Checks if a critical section is initialized or not.
*
* @returns true if initialized.
* @returns false if not initialized.
* @param pCritSect The critical section.
*/
{
}
/**
* Gets the recursion depth.
*
* @returns The recursion depth.
* @param pCritSect The critical section.
*/
{
}