本文整理汇总了C++中RTCritSectEnter函数的典型用法代码示例。如果您正苦于以下问题:C++ RTCritSectEnter函数的具体用法?C++ RTCritSectEnter怎么用?C++ RTCritSectEnter使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTCritSectEnter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: usbProxySolarisUrbAlloc
/**
* Allocates a Solaris URB request structure.
*
* @returns Pointer to an active URB request.
* @returns NULL on failure.
*
* @param pDevSol The solaris USB device.
*/
static PUSBPROXYURBSOL usbProxySolarisUrbAlloc(PUSBPROXYDEVSOL pDevSol)
{
PUSBPROXYURBSOL pUrbSol;
RTCritSectEnter(&pDevSol->CritSect);
/*
* Try remove a Solaris URB from the free list, if none there allocate a new one.
*/
pUrbSol = pDevSol->pFreeHead;
if (pUrbSol)
pDevSol->pFreeHead = pUrbSol->pNext;
else
{
RTCritSectLeave(&pDevSol->CritSect);
pUrbSol = (PUSBPROXYURBSOL)RTMemAlloc(sizeof(*pUrbSol));
if (!pUrbSol)
return NULL;
RTCritSectEnter(&pDevSol->CritSect);
}
pUrbSol->pVUsbUrb = NULL;
pUrbSol->pDevSol = pDevSol;
/*
* Link it into the active list
*/
pUrbSol->pPrev = NULL;
pUrbSol->pNext = pDevSol->pInFlightHead;
if (pUrbSol->pNext)
pUrbSol->pNext->pPrev = pUrbSol;
pDevSol->pInFlightHead = pUrbSol;
RTCritSectLeave(&pDevSol->CritSect);
return pUrbSol;
}
示例2: pdmR3ThreadSuspendAll
/**
* Suspend all running threads.
*
* This is called by PDMR3Suspend() and PDMR3PowerOff() after all the devices
* and drivers have been notified about the suspend / power off.
*
* @return VBox status code.
* @param pVM Pointer to the VM.
*/
int pdmR3ThreadSuspendAll(PVM pVM)
{
PUVM pUVM = pVM->pUVM;
RTCritSectEnter(&pUVM->pdm.s.ListCritSect); /* This may cause deadlocks later... */
for (PPDMTHREAD pThread = pUVM->pdm.s.pThreads; pThread; pThread = pThread->Internal.s.pNext)
switch (pThread->enmState)
{
case PDMTHREADSTATE_RUNNING:
{
int rc = PDMR3ThreadSuspend(pThread);
AssertRCReturn(rc, rc);
break;
}
/* suspend -> power off; voluntary suspend. */
case PDMTHREADSTATE_SUSPENDED:
break;
default:
AssertMsgFailed(("pThread=%p enmState=%d\n", pThread, pThread->enmState));
break;
}
RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
return VINF_SUCCESS;
}
示例3: VMMR3DECL
/**
* Deletes the critical section.
*
* @returns VBox status code.
* @param pCritSect The PDM critical section to destroy.
*/
VMMR3DECL(int) PDMR3CritSectDelete(PPDMCRITSECT pCritSect)
{
if (!RTCritSectIsInitialized(&pCritSect->s.Core))
return VINF_SUCCESS;
/*
* Find and unlink it.
*/
PVM pVM = pCritSect->s.pVMR3;
PUVM pUVM = pVM->pUVM;
AssertReleaseReturn(pVM, VERR_PDM_CRITSECT_IPE);
PPDMCRITSECTINT pPrev = NULL;
RTCritSectEnter(&pUVM->pdm.s.ListCritSect);
PPDMCRITSECTINT pCur = pUVM->pdm.s.pCritSects;
while (pCur)
{
if (pCur == &pCritSect->s)
{
int rc = pdmR3CritSectDeleteOne(pVM, pUVM, pCur, pPrev, false /* not final */);
RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
return rc;
}
/* next */
pPrev = pCur;
pCur = pCur->pNext;
}
RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
AssertReleaseMsgFailed(("pCritSect=%p wasn't found!\n", pCritSect));
return VERR_PDM_CRITSECT_NOT_FOUND;
}
示例4: pdmR3CritSectDeleteByKey
/**
* Deletes all critical sections with a give initializer key.
*
* @returns VBox status code.
* The entire list is processed on failure, so we'll only
* return the first error code. This shouldn't be a problem
* since errors really shouldn't happen here.
* @param pVM Pointer to the VM.
* @param pvKey The initializer key.
*/
static int pdmR3CritSectDeleteByKey(PVM pVM, void *pvKey)
{
/*
* Iterate the list and match key.
*/
PUVM pUVM = pVM->pUVM;
int rc = VINF_SUCCESS;
PPDMCRITSECTINT pPrev = NULL;
RTCritSectEnter(&pUVM->pdm.s.ListCritSect);
PPDMCRITSECTINT pCur = pUVM->pdm.s.pCritSects;
while (pCur)
{
if (pCur->pvKey == pvKey)
{
int rc2 = pdmR3CritSectDeleteOne(pVM, pUVM, pCur, pPrev, false /* not final */);
AssertRC(rc2);
if (RT_FAILURE(rc2) && RT_SUCCESS(rc))
rc = rc2;
}
/* next */
pPrev = pCur;
pCur = pCur->pNext;
}
RTCritSectLeave(&pUVM->pdm.s.ListCritSect);
return rc;
}
示例5: credentialsReset
int VBoxCredPoller::credentialsRetrieve(void)
{
credentialsReset();
/* Get credentials. */
RTCritSectEnter(&m_csCredUpate);
int rc = VbglR3CredentialsRetrieve(&m_pszUser, &m_pszPw, &m_pszDomain);
if (RT_SUCCESS(rc))
{
/* NULL/free domain if it's empty (""). */
if (m_pszDomain && strlen(m_pszDomain) == 0)
{
RTStrFree(m_pszDomain);
m_pszDomain = NULL;
}
Log(("VBoxCredPoller::credentialsRetrieve: Credentials retrieved (User=%s, Password=%s, Domain=%s)\n",
m_pszUser ? m_pszUser : "<empty>",
m_pszPw ? m_pszPw : "<empty>",
m_pszDomain ? m_pszDomain : "NULL"));
AssertPtr(m_pProv);
m_pProv->OnCredentialsProvided();
}
RTCritSectLeave(&m_csCredUpate);
return rc;
}
示例6: pdmacFileAioMgrDestroy
/**
* Destroys a async I/O manager.
*
* @returns nothing.
* @param pAioMgr The async I/O manager to destroy.
*/
static void pdmacFileAioMgrDestroy(PPDMASYNCCOMPLETIONEPCLASSFILE pEpClassFile, PPDMACEPFILEMGR pAioMgr)
{
int rc = pdmacFileAioMgrShutdown(pAioMgr);
AssertRC(rc);
/* Unlink from the list. */
rc = RTCritSectEnter(&pEpClassFile->CritSect);
AssertRC(rc);
PPDMACEPFILEMGR pPrev = pAioMgr->pPrev;
PPDMACEPFILEMGR pNext = pAioMgr->pNext;
if (pPrev)
pPrev->pNext = pNext;
else
pEpClassFile->pAioMgrHead = pNext;
if (pNext)
pNext->pPrev = pPrev;
pEpClassFile->cAioMgrs--;
rc = RTCritSectLeave(&pEpClassFile->CritSect);
AssertRC(rc);
/* Free the resources. */
RTCritSectDelete(&pAioMgr->CritSectBlockingEvent);
RTSemEventDestroy(pAioMgr->EventSem);
if (pAioMgr->enmMgrType != PDMACEPFILEMGRTYPE_SIMPLE)
pdmacFileAioMgrNormalDestroy(pAioMgr);
MMR3HeapFree(pAioMgr);
}
示例7: sys_arch_protect
/**
* Start a short critical section.
*/
sys_prot_t sys_arch_protect(void)
{
int rc;
rc = RTCritSectEnter(&g_ProtCritSect);
AssertRC(rc);
return NULL;
}
示例8: DECLCALLBACK
/**
* @interface_method_impl{TXSTRANSPORT,pfnTerm}
*/
static DECLCALLBACK(void) txsTcpTerm(void)
{
/* Signal thread */
if (RTCritSectIsInitialized(&g_TcpCritSect))
{
RTCritSectEnter(&g_TcpCritSect);
g_fTcpStopConnecting = true;
RTCritSectLeave(&g_TcpCritSect);
}
if (g_hThreadTcpConnect != NIL_RTTHREAD)
{
RTThreadUserSignal(g_hThreadTcpConnect);
RTTcpClientCancelConnect(&g_pTcpConnectCancelCookie);
}
/* Shut down the server (will wake up thread). */
if (g_pTcpServer)
{
Log(("txsTcpTerm: Destroying server...\n"));
int rc = RTTcpServerDestroy(g_pTcpServer);
if (RT_FAILURE(rc))
RTMsgInfo("RTTcpServerDestroy failed in txsTcpTerm: %Rrc", rc);
g_pTcpServer = NULL;
}
/* Shut down client */
if (g_hTcpClient != NIL_RTSOCKET)
{
if (g_fTcpClientFromServer)
{
Log(("txsTcpTerm: Disconnecting client...\n"));
int rc = RTTcpServerDisconnectClient2(g_hTcpClient);
if (RT_FAILURE(rc))
RTMsgInfo("RTTcpServerDisconnectClient2(%RTsock) failed in txsTcpTerm: %Rrc", g_hTcpClient, rc);
}
else
{
int rc = RTTcpClientClose(g_hTcpClient);
if (RT_FAILURE(rc))
RTMsgInfo("RTTcpClientClose(%RTsock) failed in txsTcpTerm: %Rrc", g_hTcpClient, rc);
}
g_hTcpClient = NIL_RTSOCKET;
}
/* Clean up stashing. */
RTMemFree(g_pbTcpStashed);
g_pbTcpStashed = NULL;
g_cbTcpStashed = 0;
g_cbTcpStashedAlloced = 0;
/* Wait for the thread (they should've had some time to quit by now). */
txsTcpConnectWaitOnThreads(15000);
/* Finally, clean up the critical section. */
if (RTCritSectIsInitialized(&g_TcpCritSect))
RTCritSectDelete(&g_TcpCritSect);
Log(("txsTcpTerm: done\n"));
}
示例9: usbProxySolarisUrbFree
/**
* Frees a Solaris URB request structure.
*
* @param pDevSol The Solaris USB device.
* @param pUrbSol The Solaris URB to free.
*/
static void usbProxySolarisUrbFree(PUSBPROXYDEVSOL pDevSol, PUSBPROXYURBSOL pUrbSol)
{
RTCritSectEnter(&pDevSol->CritSect);
/*
* Remove from the active or taxing list.
*/
if (pUrbSol->pNext)
pUrbSol->pNext->pPrev = pUrbSol->pPrev;
else if (pDevSol->pTaxingTail == pUrbSol)
pDevSol->pTaxingTail = pUrbSol->pPrev;
if (pUrbSol->pPrev)
pUrbSol->pPrev->pNext = pUrbSol->pNext;
else if (pDevSol->pTaxingHead == pUrbSol)
pDevSol->pTaxingHead = pUrbSol->pNext;
else if (pDevSol->pInFlightHead == pUrbSol)
pDevSol->pInFlightHead = pUrbSol->pNext;
else
AssertFailed();
/*
* Link it into the free list.
*/
pUrbSol->pPrev = NULL;
pUrbSol->pNext = pDevSol->pFreeHead;
pDevSol->pFreeHead = pUrbSol;
pUrbSol->pVUsbUrb = NULL;
pUrbSol->pDevSol = NULL;
RTCritSectLeave(&pDevSol->CritSect);
}
示例10: RTDECL
RTDECL(int) RTPipeClose(RTPIPE hPipe)
{
RTPIPEINTERNAL *pThis = hPipe;
if (pThis == NIL_RTPIPE)
return VINF_SUCCESS;
AssertPtrReturn(pThis, VERR_INVALID_PARAMETER);
AssertReturn(pThis->u32Magic == RTPIPE_MAGIC, VERR_INVALID_HANDLE);
/*
* Do the cleanup.
*/
AssertReturn(ASMAtomicCmpXchgU32(&pThis->u32Magic, ~RTPIPE_MAGIC, RTPIPE_MAGIC), VERR_INVALID_HANDLE);
RTCritSectEnter(&pThis->CritSect);
Assert(pThis->cUsers == 0);
if (!pThis->fRead && pThis->fIOPending)
rtPipeWriteCheckCompletion(pThis);
CloseHandle(pThis->hPipe);
pThis->hPipe = INVALID_HANDLE_VALUE;
CloseHandle(pThis->Overlapped.hEvent);
pThis->Overlapped.hEvent = NULL;
RTMemFree(pThis->pbBounceBuf);
pThis->pbBounceBuf = NULL;
RTCritSectLeave(&pThis->CritSect);
RTCritSectDelete(&pThis->CritSect);
RTMemFree(pThis);
return VINF_SUCCESS;
}
示例11: RTDECL
RTDECL(int) RTLocalIpcSessionClose(RTLOCALIPCSESSION hSession)
{
/*
* Validate input.
*/
if (hSession == NIL_RTLOCALIPCSESSION)
return VINF_SUCCESS;
PRTLOCALIPCSESSIONINT pThis = (PRTLOCALIPCSESSIONINT)hSession;
AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
AssertReturn(pThis->u32Magic == RTLOCALIPCSESSION_MAGIC, VERR_INVALID_MAGIC);
/*
* Cancel any thread currently busy using the session,
* leaving the cleanup to it.
*/
RTCritSectEnter(&pThis->CritSect);
ASMAtomicUoWriteU32(&pThis->u32Magic, ~RTLOCALIPCSESSION_MAGIC);
ASMAtomicUoWriteBool(&pThis->fCancelled, true);
pThis->cRefs--;
if (pThis->cRefs > 0)
{
BOOL fRc = SetEvent(pThis->hEvent);
AssertMsg(fRc, ("%d\n", GetLastError())); NOREF(fRc);
RTCritSectLeave(&pThis->CritSect);
}
else
rtLocalIpcSessionWinDestroy(pThis);
return VINF_SUCCESS;
}
示例12: VBoxServiceVerbose
/**
* Displays a verbose message.
*
* @param iLevel Minimum log level required to display this message.
* @param pszFormat The message text.
* @param ... Format arguments.
*/
void VBoxServiceVerbose(int iLevel, const char *pszFormat, ...)
{
if (iLevel <= g_cVerbosity)
{
#ifdef DEBUG
int rc = RTCritSectEnter(&g_csLog);
if (RT_SUCCESS(rc))
{
#endif
va_list args;
va_start(args, pszFormat);
char *psz = NULL;
RTStrAPrintfV(&psz, pszFormat, args);
va_end(args);
AssertPtr(psz);
LogRel(("%s", psz));
RTStrFree(psz);
#ifdef DEBUG
RTCritSectLeave(&g_csLog);
}
#endif
}
}
示例13: rtDbgModDestroy
/**
* Destroys an module after the reference count has reached zero.
*
* @param pDbgMod The module instance.
*/
static void rtDbgModDestroy(PRTDBGMODINT pDbgMod)
{
/*
* Close the debug info interpreter first, then the image interpret.
*/
RTCritSectEnter(&pDbgMod->CritSect); /* paranoia */
if (pDbgMod->pDbgVt)
{
pDbgMod->pDbgVt->pfnClose(pDbgMod);
pDbgMod->pDbgVt = NULL;
pDbgMod->pvDbgPriv = NULL;
}
if (pDbgMod->pImgVt)
{
pDbgMod->pImgVt->pfnClose(pDbgMod);
pDbgMod->pImgVt = NULL;
pDbgMod->pvImgPriv = NULL;
}
/*
* Free the resources.
*/
ASMAtomicWriteU32(&pDbgMod->u32Magic, ~RTDBGMOD_MAGIC);
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszName);
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszImgFile);
RTStrCacheRelease(g_hDbgModStrCache, pDbgMod->pszDbgFile);
RTCritSectLeave(&pDbgMod->CritSect); /* paranoia */
RTCritSectDelete(&pDbgMod->CritSect);
RTMemFree(pDbgMod);
}
示例14: DECLCALLBACK
/**
* @callback_method_impl{FNDBGCCMD, The '.injecterror' command.}
*/
static DECLCALLBACK(int) pdmacEpFileErrorInject(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR pArgs, unsigned cArgs)
{
/*
* Validate input.
*/
DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, -1, cArgs == 3);
DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, pArgs[0].enmType == DBGCVAR_TYPE_STRING);
DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 1, pArgs[1].enmType == DBGCVAR_TYPE_STRING);
DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 2, pArgs[2].enmType == DBGCVAR_TYPE_NUMBER);
PPDMASYNCCOMPLETIONEPCLASSFILE pEpClassFile;
pEpClassFile = (PPDMASYNCCOMPLETIONEPCLASSFILE)pUVM->pdm.s.apAsyncCompletionEndpointClass[PDMASYNCCOMPLETIONEPCLASSTYPE_FILE];
/* Syntax is "read|write <filename> <status code>" */
bool fWrite;
if (!RTStrCmp(pArgs[0].u.pszString, "read"))
fWrite = false;
else if (!RTStrCmp(pArgs[0].u.pszString, "write"))
fWrite = true;
else
return DBGCCmdHlpFail(pCmdHlp, pCmd, "invalid transfer direction '%s'", pArgs[0].u.pszString);
int32_t rcToInject = (int32_t)pArgs[2].u.u64Number;
if ((uint64_t)rcToInject != pArgs[2].u.u64Number)
return DBGCCmdHlpFail(pCmdHlp, pCmd, "The status code '%lld' is out of range", pArgs[0].u.u64Number);
/*
* Search for the matching endpoint.
*/
RTCritSectEnter(&pEpClassFile->Core.CritSect);
PPDMASYNCCOMPLETIONENDPOINTFILE pEpFile = (PPDMASYNCCOMPLETIONENDPOINTFILE)pEpClassFile->Core.pEndpointsHead;
while (pEpFile)
{
if (!RTStrCmp(pArgs[1].u.pszString, RTPathFilename(pEpFile->Core.pszUri)))
break;
pEpFile = (PPDMASYNCCOMPLETIONENDPOINTFILE)pEpFile->Core.pNext;
}
if (pEpFile)
{
/*
* Do the job.
*/
if (fWrite)
ASMAtomicXchgS32(&pEpFile->rcReqWrite, rcToInject);
else
ASMAtomicXchgS32(&pEpFile->rcReqRead, rcToInject);
DBGCCmdHlpPrintf(pCmdHlp, "Injected %Rrc into '%s' for %s\n",
(int)rcToInject, pArgs[1].u.pszString, pArgs[0].u.pszString);
}
RTCritSectLeave(&pEpClassFile->Core.CritSect);
if (!pEpFile)
return DBGCCmdHlpFail(pCmdHlp, pCmd, "No file with name '%s' found", pArgs[1].u.pszString);
return VINF_SUCCESS;
}
示例15: DECLCALLBACK
/**
* Delay inject callback.
*/
static DECLCALLBACK(int) pdmacEpFileDelayInject(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR pArgs, unsigned cArgs)
{
/*
* Validate input.
*/
DBGC_CMDHLP_REQ_VM_RET(pCmdHlp, pCmd, pVM);
DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, -1, cArgs == 3);
DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, pArgs[0].enmType == DBGCVAR_TYPE_STRING);
DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 1, pArgs[1].enmType == DBGCVAR_TYPE_STRING);
DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 2, pArgs[2].enmType == DBGCVAR_TYPE_NUMBER);
PPDMASYNCCOMPLETIONEPCLASSFILE pEpClassFile;
pEpClassFile = (PPDMASYNCCOMPLETIONEPCLASSFILE)pVM->pUVM->pdm.s.apAsyncCompletionEndpointClass[PDMASYNCCOMPLETIONEPCLASSTYPE_FILE];
/* Syntax is "read|write <filename> <status code>" */
bool fWrite;
if (!RTStrCmp(pArgs[0].u.pszString, "read"))
fWrite = false;
else if (!RTStrCmp(pArgs[0].u.pszString, "write"))
fWrite = true;
else
return DBGCCmdHlpFail(pCmdHlp, pCmd, "invalid transfer direction '%s'", pArgs[0].u.pszString);
uint32_t msDelay = (uint32_t)pArgs[2].u.u64Number;
if ((uint64_t)msDelay != pArgs[2].u.u64Number)
return DBGCCmdHlpFail(pCmdHlp, pCmd, "The delay '%lld' is out of range", pArgs[0].u.u64Number);
/*
* Search for the matching endpoint.
*/
RTCritSectEnter(&pEpClassFile->Core.CritSect);
PPDMASYNCCOMPLETIONENDPOINTFILE pEpFile = (PPDMASYNCCOMPLETIONENDPOINTFILE)pEpClassFile->Core.pEndpointsHead;
while (pEpFile)
{
if (!RTStrCmp(pArgs[1].u.pszString, RTPathFilename(pEpFile->Core.pszUri)))
break;
pEpFile = (PPDMASYNCCOMPLETIONENDPOINTFILE)pEpFile->Core.pNext;
}
if (pEpFile)
{
bool fXchg = ASMAtomicCmpXchgU32(&pEpFile->msDelay, msDelay, 0);
if (fXchg)
DBGCCmdHlpPrintf(pCmdHlp, "Injected delay of %u ms into '%s' for %s\n",
msDelay, pArgs[1].u.pszString, pArgs[0].u.pszString);
else
DBGCCmdHlpPrintf(pCmdHlp, "Another delay for '%s' is still active, ignoring\n",
pArgs[1].u.pszString);
}
RTCritSectLeave(&pEpClassFile->Core.CritSect);
if (!pEpFile)
return DBGCCmdHlpFail(pCmdHlp, pCmd, "No file with name '%s' found", pArgs[1].u.pszString);
return VINF_SUCCESS;
}