本文整理汇总了C++中RTThreadWait函数的典型用法代码示例。如果您正苦于以下问题:C++ RTThreadWait函数的具体用法?C++ RTThreadWait怎么用?C++ RTThreadWait使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTThreadWait函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test1
static void test1(void)
{
RTTestISub("Three threads");
/*
* Create the threads and let them block on the event multi semaphore.
*/
RTSEMEVENTMULTI hSem;
RTTESTI_CHECK_RC_RETV(RTSemEventMultiCreate(&hSem), VINF_SUCCESS);
RTTHREAD hThread2;
RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread2, test1Thread2, &hSem, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "test2"), VINF_SUCCESS);
RTThreadSleep(100);
RTTHREAD hThread1;
RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread1, test1Thread1, &hSem, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "test1"), VINF_SUCCESS);
/* Force first thread (which has a timeout of 1 second) to timeout in the
* first wait, and the second wait will succeed. */
RTTESTI_CHECK_RC(RTThreadSleep(1500), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTSemEventMultiSignal(hSem), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTThreadWait(hThread1, 5000, NULL), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTThreadWait(hThread2, 5000, NULL), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTSemEventMultiDestroy(hSem), VINF_SUCCESS);
}
示例2: txsTcpConnectWaitOnThreads
/**
* Wait on the threads to complete.
*
* @returns Thread status (if collected), otherwise VINF_SUCCESS.
* @param cMillies The period to wait on each thread.
*/
static int txsTcpConnectWaitOnThreads(RTMSINTERVAL cMillies)
{
int rcRet = VINF_SUCCESS;
if (g_hThreadTcpConnect != NIL_RTTHREAD)
{
int rcThread;
int rc2 = RTThreadWait(g_hThreadTcpConnect, cMillies, &rcThread);
if (RT_SUCCESS(rc2))
{
g_hThreadTcpConnect = NIL_RTTHREAD;
rcRet = rcThread;
}
}
if (g_hThreadTcpServer != NIL_RTTHREAD)
{
int rcThread;
int rc2 = RTThreadWait(g_hThreadTcpServer, cMillies, &rcThread);
if (RT_SUCCESS(rc2))
{
g_hThreadTcpServer = NIL_RTTHREAD;
if (RT_SUCCESS(rc2))
rcRet = rcThread;
}
}
return rcRet;
}
示例3: syncEnter
void VBoxNetBaseService::shutdown(void)
{
syncEnter();
if (!m->fShutdown)
{
m->fShutdown = true;
if (m->m_hThrRecv != NIL_RTTHREAD)
{
int rc = abortWait();
AssertRC(rc == VINF_SUCCESS || rc == VERR_SEM_DESTROYED);
rc = m->m_EventQ->interruptEventQueueProcessing();
if (RT_SUCCESS(rc))
{
rc = RTThreadWait(m->m_hThrRecv, 60000, NULL);
if (RT_FAILURE(rc))
Log1WarningFunc(("RTThreadWait(%RTthrd) -> %Rrc\n", m->m_hThrRecv, rc));
}
else
{
AssertMsgFailed(("interruptEventQueueProcessing() failed\n"));
RTThreadWait(m->m_hThrRecv , 0, NULL);
}
}
}
syncLeave();
}
示例4: test2
/**
* Does a multi-threading list test. Several list additions, reading, replacing
* and erasing are done simultaneous.
*
*/
static void test2()
{
RTTestISubF("MT test with 6 threads (%u tests per thread).", MTTESTITEMS);
int rc;
MTTESTLISTTYPE<MTTESTTYPE> testList;
RTTHREAD ahThreads[6];
static PFNRTTHREAD apfnThreads[6] =
{
MtTest1ThreadProc, MtTest2ThreadProc, MtTest3ThreadProc, MtTest4ThreadProc, MtTest5ThreadProc, MtTest6ThreadProc
};
for (unsigned i = 0; i < RT_ELEMENTS(ahThreads); i++)
{
RTTESTI_CHECK_RC_RETV(RTThreadCreateF(&ahThreads[i], apfnThreads[i], &testList, 0,
RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "mttest%u", i), VINF_SUCCESS);
}
uint64_t tsMsDeadline = RTTimeMilliTS() + 60000;
for (unsigned i = 0; i < RT_ELEMENTS(ahThreads); i++)
{
uint64_t tsNow = RTTimeMilliTS();
uint32_t cWait = tsNow > tsMsDeadline ? 5000 : tsMsDeadline - tsNow;
RTTESTI_CHECK_RC(RTThreadWait(ahThreads[i], tsNow, NULL), VINF_SUCCESS);
}
RTTESTI_CHECK_RETV(testList.size() == MTTESTITEMS * 2);
for (size_t i = 0; i < testList.size(); ++i)
{
uint32_t a = testList.at(i);
RTTESTI_CHECK(a == 0x0 || a == 0xFFFFFFFF || a == 0xF0F0F0F0 || a == 0xFF00FF00);
}
}
示例5: update
VirtualBox::ClientWatcher::~ClientWatcher()
{
if (mThread != NIL_RTTHREAD)
{
/* signal the client watcher thread, should be exiting now */
update();
/* wait for termination */
RTThreadWait(mThread, RT_INDEFINITE_WAIT, NULL);
mThread = NIL_RTTHREAD;
}
mProcesses.clear();
#if defined(RT_OS_WINDOWS)
if (mUpdateReq != NULL)
{
::CloseHandle(mUpdateReq);
mUpdateReq = NULL;
}
#elif defined(RT_OS_OS2) || defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER) || defined(VBOX_WITH_GENERIC_SESSION_WATCHER)
if (mUpdateReq != NIL_RTSEMEVENT)
{
RTSemEventDestroy(mUpdateReq);
mUpdateReq = NIL_RTSEMEVENT;
}
#else
# error "Port me!"
#endif
}
示例6: LogRel
/**
* Shutdowns all the watchers.
*/
void VirtualBoxSDS::i_shutdownAllWatchers(void)
{
LogRel(("i_shutdownAllWatchers: %u watchers\n", m_cWatchers));
/* Notify them all. */
uint32_t i = m_cWatchers;
while (i-- > 0)
{
ASMAtomicWriteBool(&m_papWatchers[i]->fShutdown, true);
SetEvent(m_papWatchers[i]->aHandles[0]);
}
/* Wait for them to complete and destroy their data. */
i = m_cWatchers;
m_cWatchers = 0;
while (i-- > 0)
{
VBoxSDSWatcher *pWatcher = m_papWatchers[i];
if (pWatcher)
{
m_papWatchers[i] = NULL;
int rc = RTThreadWait(pWatcher->hThread, RT_MS_1MIN / 2, NULL);
if (RT_SUCCESS(rc))
pWatcher->hThread = NIL_RTTHREAD;
else
LogRel(("i_shutdownAllWatchers: RTThreadWait failed on #%u: %Rrc\n", i, rc));
if (ASMAtomicDecU32(&pWatcher->cRefs) == 0)
RTMemFree(pWatcher);
}
}
}
示例7: VBoxCredProvVerbose
int
VBoxCredProvPoller::Shutdown(void)
{
VBoxCredProvVerbose(0, "VBoxCredProvPoller: Shutdown\n");
if (m_hThreadPoller == NIL_RTTHREAD)
return VINF_SUCCESS;
/* Post termination event semaphore. */
int rc = RTThreadUserSignal(m_hThreadPoller);
if (RT_SUCCESS(rc))
{
VBoxCredProvVerbose(0, "VBoxCredProvPoller: Waiting for thread to terminate\n");
/* Wait until the thread has terminated. */
rc = RTThreadWait(m_hThreadPoller, RT_INDEFINITE_WAIT, NULL);
if (RT_FAILURE(rc))
VBoxCredProvVerbose(0, "VBoxCredProvPoller: Wait returned error rc=%Rrc\n", rc);
}
else
VBoxCredProvVerbose(0, "VBoxCredProvPoller: Error waiting for thread shutdown, rc=%Rrc\n", rc);
m_pProv = NULL;
m_hThreadPoller = NIL_RTTHREAD;
VBoxCredProvVerbose(0, "VBoxCredProvPoller: Shutdown returned with rc=%Rrc\n", rc);
return rc;
}
示例8: LogFlowThisFunc
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
void VirtualBoxClient::uninit()
{
LogFlowThisFunc(("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
if (mData.m_ThreadWatcher != NIL_RTTHREAD)
{
/* Signal the event semaphore and wait for the thread to terminate.
* if it hangs for some reason exit anyway, this can cause a crash
* though as the object will no longer be available. */
RTSemEventSignal(mData.m_SemEvWatcher);
RTThreadWait(mData.m_ThreadWatcher, 30000, NULL);
mData.m_ThreadWatcher = NIL_RTTHREAD;
RTSemEventDestroy(mData.m_SemEvWatcher);
mData.m_SemEvWatcher = NIL_RTSEMEVENT;
}
mData.m_pVirtualBox.setNull();
ASMAtomicDecU32(&g_cInstances);
}
示例9: VBoxGINACredentialsPollerTerminate
int VBoxGINACredentialsPollerTerminate(void)
{
if (gThreadPoller == NIL_RTTHREAD)
return VINF_SUCCESS;
VBoxGINAVerbose(0, "VBoxGINA::credentialsPollerTerminate\n");
/* post termination event semaphore */
int rc = RTThreadUserSignal(gThreadPoller);
if (RT_SUCCESS(rc))
{
VBoxGINAVerbose(0, "VBoxGINA::credentialsPollerTerminate: waiting for thread to terminate\n");
rc = RTThreadWait(gThreadPoller, RT_INDEFINITE_WAIT, NULL);
}
else
VBoxGINAVerbose(0, "VBoxGINA::credentialsPollerTerminate: thread has terminated? wait rc = %Rrc\n", rc);
if (RT_SUCCESS(rc))
{
gThreadPoller = NIL_RTTHREAD;
}
VBoxGINAVerbose(0, "VBoxGINA::credentialsPollerTerminate: returned with rc=%Rrc)\n", rc);
return rc;
}
示例10: DECLCALLBACK
/**
* Destruct a char driver instance.
*
* Most VM resources are freed by the VM. This callback is provided so that
* any non-VM resources can be freed correctly.
*
* @param pDrvIns The driver instance data.
*/
static DECLCALLBACK(void) drvCharDestruct(PPDMDRVINS pDrvIns)
{
PDRVCHAR pThis = PDMINS_2_DATA(pDrvIns, PDRVCHAR);
LogFlow(("%s: iInstance=%d\n", __FUNCTION__, pDrvIns->iInstance));
PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
/*
* Tell the threads to shut down.
*/
pThis->fShutdown = true;
if (pThis->SendSem != NIL_RTSEMEVENT)
{
RTSemEventSignal(pThis->SendSem);
pThis->SendSem = NIL_RTSEMEVENT;
}
/*
* Wait for the threads.
* ASSUMES that PDM destroys the driver chain from the bottom and up.
*/
if (pThis->ReceiveThread != NIL_RTTHREAD)
{
int rc = RTThreadWait(pThis->ReceiveThread, 30000, NULL);
if (RT_SUCCESS(rc))
pThis->ReceiveThread = NIL_RTTHREAD;
else
LogRel(("Char%d: receive thread did not terminate (%Rrc)\n", pDrvIns->iInstance, rc));
}
if (pThis->SendThread != NIL_RTTHREAD)
{
int rc = RTThreadWait(pThis->SendThread, 30000, NULL);
if (RT_SUCCESS(rc))
pThis->SendThread = NIL_RTTHREAD;
else
LogRel(("Char%d: send thread did not terminate (%Rrc)\n", pDrvIns->iInstance, rc));
}
if (pThis->SendSem != NIL_RTSEMEVENT)
{
RTSemEventDestroy(pThis->SendSem);
pThis->SendSem = NIL_RTSEMEVENT;
}
}
示例11: DECLEXPORT
/**
* Entry point.
*/
extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv)
{
/*
* Instantiate the DHCP server and hand it the options.
*/
VBoxNetDhcp *pDhcp = new VBoxNetDhcp();
if (!pDhcp)
{
RTStrmPrintf(g_pStdErr, "VBoxNetDHCP: new VBoxNetDhcp failed!\n");
return 1;
}
RTEXITCODE rcExit = (RTEXITCODE)pDhcp->parseArgs(argc - 1, argv + 1);
if (rcExit != RTEXITCODE_SUCCESS)
return rcExit;
#ifdef RT_OS_WINDOWS
/* DIFx hack. */
RTTHREAD hMakeUseKillableThread = NIL_RTTHREAD;
int rc2 = RTThreadCreate(&hMakeUseKillableThread, DIFxKillableProcessThreadProc, NULL, 0,
RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "DIFxKill");
if (RT_FAILURE(rc2))
hMakeUseKillableThread = NIL_RTTHREAD;
#endif
pDhcp->init();
/*
* Try connect the server to the network.
*/
int rc = pDhcp->tryGoOnline();
if (RT_SUCCESS(rc))
{
/*
* Process requests.
*/
g_pDhcp = pDhcp;
rc = pDhcp->run();
pDhcp->done();
g_pDhcp = NULL;
}
delete pDhcp;
#ifdef RT_OS_WINDOWS
/* Kill DIFx hack. */
if (hMakeUseKillableThread != NIL_RTTHREAD)
{
g_fExitProcessOnQuit = false;
PostThreadMessage((DWORD)RTThreadGetNative(hMakeUseKillableThread), WM_QUIT, 0, 0);
RTThreadWait(hMakeUseKillableThread, RT_MS_1SEC * 5U, NULL);
}
#endif
return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
}
示例12: test1
static void test1(void)
{
RTTestSub(g_hTest, "Interrupt RTThreadSleep");
RTTHREAD hThread;
RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread, test1Thread, NULL, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "test1"),
VINF_SUCCESS);
RTThreadSleep(500); RTThreadSleep(1500); /* fudge */
RTTESTI_CHECK_RC(RTThreadPoke(hThread), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTThreadWait(hThread, RT_INDEFINITE_WAIT, NULL), VINF_SUCCESS);
}
示例13: VDIoBackendMemDestroy
int VDIoBackendMemDestroy(PVDIOBACKENDMEM pIoBackend)
{
ASMAtomicXchgBool(&pIoBackend->fRunning, false);
vdIoBackendMemThreadPoke(pIoBackend);
RTThreadWait(pIoBackend->hThreadIo, RT_INDEFINITE_WAIT, NULL);
RTSemEventDestroy(pIoBackend->EventSem);
RTCircBufDestroy(pIoBackend->pRequestRing);
RTMemFree(pIoBackend);
return VINF_SUCCESS;
}
示例14: Log
bool VBoxCredPoller::Shutdown(void)
{
Log(("VBoxCredPoller::Shutdown\n"));
if (m_hThreadPoller == NIL_RTTHREAD)
{
Log(("VBoxCredPoller::Shutdown: Either thread or exit sem is NULL!\n"));
return false;
}
/* Post termination event semaphore. */
int rc = RTThreadUserSignal(m_hThreadPoller);
if (RT_SUCCESS(rc))
{
Log(("VBoxCredPoller::Shutdown: Waiting for thread to terminate\n"));
/* Wait until the thread has terminated. */
rc = RTThreadWait(m_hThreadPoller, RT_INDEFINITE_WAIT, NULL);
Log(("VBoxCredPoller::Shutdown: Thread has (probably) terminated (rc = %Rrc)\n", rc));
}
else
{
/* Failed to signal the thread - very unlikely - so no point in waiting long. */
Log(("VBoxCredPoller::Shutdown: Failed to signal semaphore, rc = %Rrc\n", rc));
rc = RTThreadWait(m_hThreadPoller, 100, NULL);
Log(("VBoxCredPoller::Shutdown: Thread has terminated? wait rc = %Rrc\n", rc));
}
if (m_pProv != NULL)
{
m_pProv->Release();
m_pProv = NULL;
}
credentialsReset();
RTCritSectDelete(&m_csCredUpate);
m_hThreadPoller = NIL_RTTHREAD;
return true;
}
示例15: Log
HostPowerServiceWin::~HostPowerServiceWin()
{
if (mHwnd)
{
Log(("HostPowerServiceWin::!HostPowerServiceWin: destroy window %x\n", mHwnd));
/* Is this allowed from another thread? */
SetWindowLongPtr(mHwnd, 0, 0);
/* Poke the thread out of the event loop and wait for it to clean up. */
PostMessage(mHwnd, WM_QUIT, 0, 0);
RTThreadWait(mThread, 5000, NULL);
mThread = NIL_RTTHREAD;
}
}