本文整理汇总了C++中RTSemEventWait函数的典型用法代码示例。如果您正苦于以下问题:C++ RTSemEventWait函数的具体用法?C++ RTSemEventWait怎么用?C++ RTSemEventWait使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTSemEventWait函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AssertReturn
int GuestWaitEventBase::Wait(RTMSINTERVAL uTimeoutMS)
{
int rc = VINF_SUCCESS;
if (ASMAtomicReadBool(&mfAborted))
rc = VERR_CANCELLED;
if (RT_SUCCESS(rc))
{
AssertReturn(mEventSem != NIL_RTSEMEVENT, VERR_CANCELLED);
RTMSINTERVAL msInterval = uTimeoutMS;
if (!uTimeoutMS)
msInterval = RT_INDEFINITE_WAIT;
rc = RTSemEventWait(mEventSem, msInterval);
if (ASMAtomicReadBool(&mfAborted))
rc = VERR_CANCELLED;
if (RT_SUCCESS(rc))
{
/* If waiting succeeded, return the overall
* result code. */
rc = mRc;
}
}
return rc;
}
示例2: vboxNetAdpOsDestroy
void vboxNetAdpOsDestroy(PVBOXNETADP pThis)
{
u_int32_t i;
/* Bring down the interface */
int rc = VINF_SUCCESS;
errno_t err;
AssertPtr(pThis->u.s.pIface);
Assert(pThis->u.s.hEvtDetached != NIL_RTSEMEVENT);
err = ifnet_set_flags(pThis->u.s.pIface, 0, IFF_UP | IFF_RUNNING);
if (err)
Log(("vboxNetAdpDarwinUnregisterDevice: Failed to bring down interface "
"(err=%d).\n", err));
/* Detach all protocols. */
for (i = 0; i < VBOXNETADP_MAX_FAMILIES; i++)
if (pThis->u.s.aAttachedFamilies[i])
ifnet_detach_protocol(pThis->u.s.pIface, pThis->u.s.aAttachedFamilies[i]);
err = ifnet_detach(pThis->u.s.pIface);
if (err)
Log(("vboxNetAdpDarwinUnregisterDevice: Failed to detach interface "
"(err=%d).\n", err));
Log2(("vboxNetAdpDarwinUnregisterDevice: Waiting for 'detached' event...\n"));
/* Wait until we get a signal from detach callback. */
rc = RTSemEventWait(pThis->u.s.hEvtDetached, VBOXNETADP_DETACH_TIMEOUT);
if (rc == VERR_TIMEOUT)
LogRel(("VBoxAdpDrv: Failed to detach interface %s%d\n.",
VBOXNETADP_NAME, pThis->iUnit));
err = ifnet_release(pThis->u.s.pIface);
if (err)
Log(("vboxNetAdpUnregisterDevice: Failed to release interface (err=%d).\n", err));
RTSemEventDestroy(pThis->u.s.hEvtDetached);
pThis->u.s.hEvtDetached = NIL_RTSEMEVENT;
}
示例3: DECLCALLBACK
/**
* @copydoc INTNETTRUNKIFPORT::pfnWaitForIdle
*/
static DECLCALLBACK(int) vboxNetAdpPortWaitForIdle(PINTNETTRUNKIFPORT pIfPort, uint32_t cMillies)
{
int rc;
PVBOXNETADP pThis = IFPORT_2_VBOXNETADP(pIfPort);
/*
* Input validation.
*/
AssertPtr(pThis);
Assert(pThis->MyPort.u32Version == INTNETTRUNKIFPORT_VERSION);
AssertReturn(vboxNetAdpGetStateWithLock(pThis) >= kVBoxNetAdpState_Connected, VERR_INVALID_STATE);
/*
* Go to sleep on the semaphore after checking the busy count.
*/
vboxNetAdpRetain(pThis);
rc = VINF_SUCCESS;
while (pThis->cBusy && RT_SUCCESS(rc))
rc = RTSemEventWait(pThis->hEventIdle, cMillies); /** @todo make interruptible? */
vboxNetAdpRelease(pThis);
return rc;
}
示例4: drvdiskIntIoReqExpiredCheck
/**
* Thread checking for expired requests.
*
* @returns IPRT status code.
* @param pThread Thread handle.
* @param pvUser Opaque user data.
*/
static int drvdiskIntIoReqExpiredCheck(RTTHREAD pThread, void *pvUser)
{
PDRVDISKINTEGRITY pThis = (PDRVDISKINTEGRITY)pvUser;
while (pThis->fRunning)
{
int rc = RTSemEventWait(pThis->SemEvent, pThis->uCheckIntervalMs);
if (!pThis->fRunning)
break;
Assert(rc == VERR_TIMEOUT);
/* Get current timestamp for comparison. */
uint64_t tsCurr = RTTimeSystemMilliTS();
/* Go through the array and check for expired requests. */
for (unsigned i = 0; i < RT_ELEMENTS(pThis->apReqActive); i++)
{
PDRVDISKAIOREQACTIVE pReqActive = &pThis->apReqActive[i];
PDRVDISKAIOREQ pIoReq = ASMAtomicReadPtrT(&pReqActive->pIoReq, PDRVDISKAIOREQ);
if ( pIoReq
&& (tsCurr > pReqActive->tsStart)
&& (tsCurr - pReqActive->tsStart) >= pThis->uExpireIntervalMs)
{
RTMsgError("Request %#p expired (active for %llu ms already)\n",
pIoReq, tsCurr - pReqActive->tsStart);
RTAssertDebugBreak();
}
}
}
return VINF_SUCCESS;
}
示例5: DECLCALLBACK
/**
* Default VMR3Wait() worker.
*
* @returns VBox status code.
* @param pUVMCPU Pointer to the user mode VMCPU structure.
*/
static DECLCALLBACK(int) vmR3DefaultWait(PUVMCPU pUVCpu)
{
ASMAtomicWriteBool(&pUVCpu->vm.s.fWait, true);
PVM pVM = pUVCpu->pVM;
PVMCPU pVCpu = pUVCpu->pVCpu;
int rc = VINF_SUCCESS;
for (;;)
{
/*
* Check Relevant FFs.
*/
if ( VM_FF_ISPENDING(pVM, VM_FF_EXTERNAL_SUSPENDED_MASK)
|| VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_EXTERNAL_SUSPENDED_MASK))
break;
/*
* Wait for a while. Someone will wake us up or interrupt the call if
* anything needs our attention.
*/
rc = RTSemEventWait(pUVCpu->vm.s.EventSemWait, 1000);
if (rc == VERR_TIMEOUT)
rc = VINF_SUCCESS;
else if (RT_FAILURE(rc))
{
rc = vmR3FatalWaitError(pUVCpu, "RTSemEventWait->%Rrc", rc);
break;
}
}
ASMAtomicUoWriteBool(&pUVCpu->vm.s.fWait, false);
return rc;
}
示例6: RTDECL
RTDECL(int) RTReqWait(PRTREQ hReq, RTMSINTERVAL cMillies)
{
LogFlow(("RTReqWait: hReq=%p cMillies=%d\n", hReq, cMillies));
/*
* Verify the supplied package.
*/
PRTREQINT pReq = hReq;
AssertPtrReturn(pReq, VERR_INVALID_HANDLE);
AssertReturn(pReq->u32Magic == RTREQ_MAGIC, VERR_INVALID_HANDLE);
AssertMsgReturn( pReq->enmState != RTREQSTATE_QUEUED
|| pReq->enmState != RTREQSTATE_PROCESSING
|| pReq->enmState != RTREQSTATE_COMPLETED,
("Invalid state %d\n", pReq->enmState),
VERR_RT_REQUEST_STATE);
AssertMsgReturn(pReq->uOwner.hQueue && pReq->EventSem != NIL_RTSEMEVENT,
("Invalid request package! Anyone cooking their own packages???\n"),
VERR_RT_REQUEST_INVALID_PACKAGE);
AssertMsgReturn(pReq->enmType > RTREQTYPE_INVALID && pReq->enmType < RTREQTYPE_MAX,
("Invalid package type %d valid range %d-%d inclusively. This was verified on alloc too...\n",
pReq->enmType, RTREQTYPE_INVALID + 1, RTREQTYPE_MAX - 1),
VERR_RT_REQUEST_INVALID_TYPE);
/*
* Wait on the package.
*/
int rc;
if (cMillies != RT_INDEFINITE_WAIT)
rc = RTSemEventWait(pReq->EventSem, cMillies);
else
{
do
{
rc = RTSemEventWait(pReq->EventSem, RT_INDEFINITE_WAIT);
Assert(rc != VERR_TIMEOUT);
} while (pReq->enmState != RTREQSTATE_COMPLETED);
}
if (rc == VINF_SUCCESS)
ASMAtomicXchgSize(&pReq->fEventSemClear, true);
if (pReq->enmState == RTREQSTATE_COMPLETED)
rc = VINF_SUCCESS;
LogFlow(("RTReqWait: returns %Rrc\n", rc));
Assert(rc != VERR_INTERRUPTED);
Assert(pReq->cRefs >= 1);
return rc;
}
示例7: DECLHIDDEN
/**
* Re-initializes a request when it's being recycled.
*
* @returns IRPT status code, the request is freed on failure.
* @param pReq The request.
* @param enmType The request type.
*/
DECLHIDDEN(int) rtReqReInit(PRTREQINT pReq, RTREQTYPE enmType)
{
Assert(pReq->u32Magic == RTREQ_MAGIC);
Assert(pReq->enmType == RTREQTYPE_INVALID);
Assert(pReq->enmState == RTREQSTATE_FREE);
Assert(pReq->cRefs == 0);
/*
* Make sure the event sem is not signaled.
*/
if (!pReq->fEventSemClear)
{
int rc = RTSemEventWait(pReq->EventSem, 0);
if (rc != VINF_SUCCESS && rc != VERR_TIMEOUT)
{
/*
* This shall not happen, but if it does we'll just destroy
* the semaphore and create a new one.
*/
AssertMsgFailed(("rc=%Rrc from RTSemEventWait(%#x).\n", rc, pReq->EventSem));
RTSemEventDestroy(pReq->EventSem);
rc = RTSemEventCreate(&pReq->EventSem);
if (RT_FAILURE(rc))
{
AssertRC(rc);
pReq->EventSem = NIL_RTSEMEVENT;
rtReqFreeIt(pReq);
return rc;
}
}
pReq->fEventSemClear = true;
}
else
Assert(RTSemEventWait(pReq->EventSem, 0) == VERR_TIMEOUT);
/*
* Initialize the packet and return it.
*/
ASMAtomicWriteNullPtr(&pReq->pNext);
pReq->iStatusX = VERR_RT_REQUEST_STATUS_STILL_PENDING;
pReq->enmState = RTREQSTATE_ALLOCATED;
pReq->fFlags = RTREQFLAGS_IPRT_STATUS;
pReq->enmType = enmType;
pReq->cRefs = 1;
return VINF_SUCCESS;
}
示例8: RTSemEventWait
int GuestDnDResponse::waitForGuestResponse(RTMSINTERVAL msTimeout /*= 500 */) const
{
int rc = RTSemEventWait(m_EventSem, msTimeout);
#ifdef DEBUG_andy
LogFlowFunc(("msTimeout=%RU32, rc=%Rrc\n", msTimeout, rc));
#endif
return rc;
}
示例9: vdIoBackendMemThread
/**
* I/O thread for the memory backend.
*
* @returns IPRT status code.
*
* @param hThread The thread handle.
* @param pvUser Opaque user data.
*/
static int vdIoBackendMemThread(RTTHREAD hThread, void *pvUser)
{
PVDIOBACKENDMEM pIoBackend = (PVDIOBACKENDMEM)pvUser;
while (pIoBackend->fRunning)
{
int rc = RTSemEventWait(pIoBackend->EventSem, RT_INDEFINITE_WAIT);
if (RT_FAILURE(rc) || !pIoBackend->fRunning)
break;
PVDIOBACKENDREQ pReq;
PPVDIOBACKENDREQ ppReq;
size_t cbData;
uint32_t cReqsWaiting = ASMAtomicXchgU32(&pIoBackend->cReqsWaiting, 0);
while (cReqsWaiting)
{
int rcReq = VINF_SUCCESS;
/* Do we have another request? */
RTCircBufAcquireReadBlock(pIoBackend->pRequestRing, sizeof(PVDIOBACKENDREQ), (void **)&ppReq, &cbData);
Assert(!ppReq || cbData == sizeof(PVDIOBACKENDREQ));
RTCircBufReleaseReadBlock(pIoBackend->pRequestRing, cbData);
pReq = *ppReq;
cReqsWaiting--;
LogFlowFunc(("Processing request\n"));
switch (pReq->enmTxDir)
{
case VDIOTXDIR_READ:
{
RTSGBUF SgBuf;
RTSgBufInit(&SgBuf, pReq->aSegs, pReq->cSegs);
rcReq = VDMemDiskRead(pReq->pMemDisk, pReq->off, pReq->cbTransfer, &SgBuf);
break;
}
case VDIOTXDIR_WRITE:
{
RTSGBUF SgBuf;
RTSgBufInit(&SgBuf, pReq->aSegs, pReq->cSegs);
rcReq = VDMemDiskWrite(pReq->pMemDisk, pReq->off, pReq->cbTransfer, &SgBuf);
break;
}
case VDIOTXDIR_FLUSH:
break;
default:
AssertMsgFailed(("Invalid TX direction!\n"));
}
/* Notify completion. */
pReq->pfnComplete(pReq->pvUser, rcReq);
RTMemFree(pReq);
}
}
return VINF_SUCCESS;
}
示例10: RTThreadCreate
HRESULT HostDnsServiceDarwin::start()
{
int rc = RTThreadCreate(&g_DnsMonitoringThread, hostMonitoringRoutine,
this, 128 * _1K, RTTHREADTYPE_IO, 0, "dns-monitor");
AssertRCReturn(rc, E_FAIL);
RTSemEventWait(g_DnsInitEvent, RT_INDEFINITE_WAIT);
return S_OK;
}
示例11: LogFlowFunc
int VBoxDnDDropTarget::WaitForDrop(RTMSINTERVAL msTimeout)
{
LogFlowFunc(("msTimeout=%RU32\n", msTimeout));
int rc = RTSemEventWait(hEventDrop, msTimeout);
if (RT_SUCCESS(rc))
rc = mDroppedRc;
LogFlowFuncLeaveRC(rc);
return rc;
}
示例12: l
void HostDnsServiceDarwin::monitorThreadShutdown()
{
ALock l(this);
if (!m->m_fStop)
{
CFRunLoopSourceSignal(m->m_Stopper);
CFRunLoopWakeUp(m->m_RunLoopRef);
RTSemEventWait(m->m_evtStop, RT_INDEFINITE_WAIT);
}
}
示例13: DECLCALLBACK
/** VM IPC mutex holder thread */
DECLCALLBACK(int) IPCMutexHolderThread (RTTHREAD Thread, void *pvUser)
{
LogFlowFuncEnter();
Assert (pvUser);
void **data = (void **) pvUser;
Utf8Str ipcId = (BSTR)data[0];
RTSEMEVENT finishSem = (RTSEMEVENT)data[1];
LogFlowFunc (("ipcId='%s', finishSem=%p\n", ipcId.raw(), finishSem));
HMTX ipcMutex = NULLHANDLE;
APIRET arc = ::DosOpenMutexSem ((PSZ) ipcId.raw(), &ipcMutex);
AssertMsg (arc == NO_ERROR, ("cannot open IPC mutex, arc=%ld\n", arc));
if (arc == NO_ERROR)
{
/* grab the mutex */
LogFlowFunc (("grabbing IPC mutex...\n"));
arc = ::DosRequestMutexSem (ipcMutex, SEM_IMMEDIATE_RETURN);
AssertMsg (arc == NO_ERROR, ("cannot grab IPC mutex, arc=%ld\n", arc));
if (arc == NO_ERROR)
{
/* store the answer */
data[2] = (void*)true;
/* signal we're done */
int vrc = RTThreadUserSignal (Thread);
AssertRC(vrc);
/* wait until we're signaled to release the IPC mutex */
LogFlowFunc (("waiting for termination signal..\n"));
vrc = RTSemEventWait (finishSem, RT_INDEFINITE_WAIT);
Assert (arc == ERROR_INTERRUPT || ERROR_TIMEOUT);
/* release the IPC mutex */
LogFlowFunc (("releasing IPC mutex...\n"));
arc = ::DosReleaseMutexSem (ipcMutex);
AssertMsg (arc == NO_ERROR, ("cannot release mutex, arc=%ld\n", arc));
}
::DosCloseMutexSem (ipcMutex);
}
/* store the answer */
data[1] = (void*)false;
/* signal we're done */
int vrc = RTThreadUserSignal (Thread);
AssertRC(vrc);
LogFlowFuncLeave();
return 0;
}
示例14: VBoxServiceMainWait
/**
* Block the main thread until the service shuts down.
*/
void VBoxServiceMainWait(void)
{
int rc;
VBoxServiceReportStatus(VBoxGuestFacilityStatus_Active);
#ifdef RT_OS_WINDOWS
/*
* Wait for the semaphore to be signalled.
*/
VBoxServiceVerbose(1, "Waiting in main thread\n");
rc = RTSemEventCreate(&g_hEvtWindowsService);
AssertRC(rc);
while (!ASMAtomicReadBool(&g_fWindowsServiceShutdown))
{
rc = RTSemEventWait(g_hEvtWindowsService, RT_INDEFINITE_WAIT);
AssertRC(rc);
}
RTSemEventDestroy(g_hEvtWindowsService);
g_hEvtWindowsService = NIL_RTSEMEVENT;
#else
/*
* Wait explicitly for a HUP, INT, QUIT, ABRT or TERM signal, blocking
* all important signals.
*
* The annoying EINTR/ERESTART loop is for the benefit of Solaris where
* sigwait returns when we receive a SIGCHLD. Kind of makes sense since
*/
sigset_t signalMask;
sigemptyset(&signalMask);
sigaddset(&signalMask, SIGHUP);
sigaddset(&signalMask, SIGINT);
sigaddset(&signalMask, SIGQUIT);
sigaddset(&signalMask, SIGABRT);
sigaddset(&signalMask, SIGTERM);
pthread_sigmask(SIG_BLOCK, &signalMask, NULL);
int iSignal;
do
{
iSignal = -1;
rc = sigwait(&signalMask, &iSignal);
}
while ( rc == EINTR
# ifdef ERESTART
|| rc == ERESTART
# endif
);
VBoxServiceVerbose(3, "VBoxServiceMainWait: Received signal %d (rc=%d)\n", iSignal, rc);
#endif /* !RT_OS_WINDOWS */
}
示例15: vmsvga3dSendThreadMessage
/**
* Send a message to the async window thread and wait for a reply
*
* @returns VBox status code.
* @param pWindowThread Thread handle
* @param WndRequestSem Semaphore handle for waiting
* @param msg Message id
* @param wParam First parameter
* @param lParam Second parameter
*/
int vmsvga3dSendThreadMessage(RTTHREAD pWindowThread, RTSEMEVENT WndRequestSem, UINT msg, WPARAM wParam, LPARAM lParam)
{
int rc;
BOOL ret;
ret = PostThreadMessage(RTThreadGetNative(pWindowThread), msg, wParam, lParam);
AssertMsgReturn(ret, ("PostThreadMessage %x failed with %d\n", RTThreadGetNative(pWindowThread), GetLastError()), VERR_INTERNAL_ERROR);
rc = RTSemEventWait(WndRequestSem, RT_INDEFINITE_WAIT);
Assert(RT_SUCCESS(rc));
return rc;
}