PDMAllCritSect.cpp revision 052850815ca4abcf5718e1ea2dabc5a649142a4a
/* $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
/**
* 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.
*/
{
#ifdef IN_RING3
STAM_STATS({ if (pCritSect->s.Core.cNestings == 1) STAM_PROFILE_ADV_START(&pCritSect->s.StatLocked, l); });
return rc;
#else /* !IN_RING3 */
AssertMsgReturn(pCritSect->s.Core.u32Magic == RTCRITSECT_MAGIC, ("%RX32\n", pCritSect->s.Core.u32Magic),
/*
* Try to take the lock.
*/
{
return VINF_SUCCESS;
}
/*
* Nested?
*/
{
return VINF_SUCCESS;
}
/*
* Failed.
*/
return rcBusy;
#endif /* !IN_RING3 */
}
/**
* 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.
*/
{
#ifdef IN_RING3
#else /* !IN_RING3 (same code as PDMCritSectEnter except for the log statement) */
AssertMsgReturn(pCritSect->s.Core.u32Magic == RTCRITSECT_MAGIC, ("%RX32\n", pCritSect->s.Core.u32Magic),
/*
* Try to take the lock.
*/
{
return VINF_SUCCESS;
}
/*
* Nested?
*/
{
return VINF_SUCCESS;
}
/*
* Failed.
*/
LogFlow(("PDMCritSectTryEnter: locked\n"));
return VERR_SEM_BUSY;
#endif /* !IN_RING3 */
}
#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.
*/
{
#ifdef IN_RING3
# ifdef VBOX_WITH_STATISTICS
# endif
{
}
else
{
}
#else /* !IN_RING3 */
AssertMsg(pCritSect->s.Core.NativeThreadOwner == pVCpu->hNativeThread, ("Owner %RX64 emt=%RX64\n", pCritSect->s.Core.NativeThreadOwner, pVCpu->hNativeThread));
/*
* Deal with nested attempts first.
* (We're exploiting nesting to avoid queuing multiple R3 leaves for the same section.)
*/
{
return;
}
/*
* Try leave it.
*/
{
return;
/* darn, someone raced in on us. */
}
/*
* Queue the request.
*/
#endif /* !IN_RING3 */
}
/**
* 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
#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 a critical section is initialized or not.
*
* @returns true if initialized.
* @returns false if not initialized.
* @param pCritSect The critical section.
*/
{
}