本文整理汇总了C++中RTThreadCreate函数的典型用法代码示例。如果您正苦于以下问题:C++ RTThreadCreate函数的具体用法?C++ RTThreadCreate怎么用?C++ RTThreadCreate使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTThreadCreate函数的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: Log
bool VBoxCredPoller::Initialize(VBoxCredProv *pProvider)
{
Log(("VBoxCredPoller::Initialize\n"));
if (m_pProv != NULL)
m_pProv->Release();
m_pProv = pProvider;
AssertPtr(m_pProv);
m_pProv->AddRef();
/* Don't create more than one of them. */
if (m_hThreadPoller != NIL_RTTHREAD)
{
Log(("VBoxCredPoller::Initialize: Thread already running, returning!\n"));
return false;
}
int rc = RTCritSectInit(&m_csCredUpate);
if (RT_FAILURE(rc))
Log(("VBoxCredPoller: Could not init critical section! rc = %Rrc\n", rc));
/* Create the poller thread. */
rc = RTThreadCreate(&m_hThreadPoller, VBoxCredPoller::threadPoller, this, 0, RTTHREADTYPE_INFREQUENT_POLLER,
RTTHREADFLAGS_WAITABLE, "creds");
if (RT_FAILURE(rc))
{
Log(("VBoxCredPoller::Initialize: Failed to create thread, rc = %Rrc\n", rc));
return false;
}
return true;
}
示例3: vboxDispMpTstStart
HRESULT vboxDispMpTstStart()
{
HRESULT hr = E_FAIL;
g_hVBoxDispMpModule = GetModuleHandleW(L"VBoxDispD3D.dll");
Assert(g_hVBoxDispMpModule);
if (g_hVBoxDispMpModule)
{
g_pfnVBoxDispMpGetCallbacks = (PFNVBOXDISPMP_GETCALLBACKS)GetProcAddress(g_hVBoxDispMpModule, "VBoxDispMpGetCallbacks");
Assert(g_pfnVBoxDispMpGetCallbacks);
if (g_pfnVBoxDispMpGetCallbacks)
{
hr = g_pfnVBoxDispMpGetCallbacks(VBOXDISPMP_VERSION, &g_VBoxDispMpTstCallbacks);
Assert(hr == S_OK);
if (hr == S_OK)
{
int rc = RTThreadCreate(&g_VBoxDispMpTstThread, vboxDispMpTstThreadProc, NULL, 0,
RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "VBoxDispMpTst");
AssertRC(rc);
if (RT_SUCCESS(rc))
return S_OK;
hr = E_FAIL;
}
}
FreeLibrary(g_hVBoxDispMpModule);
}
return hr;
}
示例4: RTDECL
/**
* Create a new thread.
*
* Same as RTThreadCreate except the name is given in the RTStrPrintfV form.
*
* @returns iprt status code.
* @param pThread See RTThreadCreate.
* @param pfnThread See RTThreadCreate.
* @param pvUser See RTThreadCreate.
* @param cbStack See RTThreadCreate.
* @param enmType See RTThreadCreate.
* @param fFlags See RTThreadCreate.
* @param pszNameFmt Thread name format.
* @param va Format arguments.
*/
RTDECL(int) RTThreadCreateV(PRTTHREAD pThread, PFNRTTHREAD pfnThread, void *pvUser, size_t cbStack,
RTTHREADTYPE enmType, uint32_t fFlags, const char *pszNameFmt, va_list va)
{
char szName[RTTHREAD_NAME_LEN * 2];
RTStrPrintfV(szName, sizeof(szName), pszNameFmt, va);
return RTThreadCreate(pThread, pfnThread, pvUser, cbStack, enmType, fFlags, szName);
}
示例5: mVirtualBox
VirtualBox::ClientWatcher::ClientWatcher(const ComObjPtr<VirtualBox> &pVirtualBox) :
mVirtualBox(pVirtualBox),
mThread(NIL_RTTHREAD),
mUpdateReq(CWUPDATEREQARG),
mLock(LOCKCLASS_OBJECTSTATE)
{
#if defined(RT_OS_WINDOWS)
mUpdateReq = ::CreateEvent(NULL, FALSE, FALSE, NULL);
#elif defined(RT_OS_OS2)
RTSemEventCreate(&mUpdateReq);
#elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER) || defined(VBOX_WITH_GENERIC_SESSION_WATCHER)
RTSemEventCreate(&mUpdateReq);
/* start with high timeouts, nothing to do */
ASMAtomicUoWriteU8(&mUpdateAdaptCtr, 0);
#else
# error "Port me!"
#endif
int vrc = RTThreadCreate(&mThread,
worker,
(void *)this,
0,
RTTHREADTYPE_MAIN_WORKER,
RTTHREADFLAGS_WAITABLE,
"Watcher");
AssertRC(vrc);
}
示例6: pam_vbox_wait_for_creds
/**
* Waits for credentials to arrive by creating and waiting for a thread.
*
* @return IPRT status code.
* @param hPAM PAM handle.
* @param uClientID Guest property service client ID.
* @param uTimeoutMS Timeout (in ms) to wait for the change. Specify
* RT_INDEFINITE_WAIT to wait indefinitly.
*/
static int pam_vbox_wait_for_creds(pam_handle_t *hPAM, uint32_t uClientID, uint32_t uTimeoutMS)
{
RT_NOREF1(uClientID);
PAMVBOXTHREAD threadData;
threadData.hPAM = hPAM;
threadData.uTimeoutMS = uTimeoutMS;
RTTHREAD threadWait;
int rc = RTThreadCreate(&threadWait, pam_vbox_wait_thread,
(void *)&threadData, 0,
RTTHREADTYPE_DEFAULT, 0 /* Flags */, "pam_vbox");
if (RT_SUCCESS(rc))
{
pam_vbox_log(hPAM, "pam_vbox_wait_for_creds: Waiting for credentials (%dms) ...\n", uTimeoutMS);
/* Wait for thread to initialize. */
/** @todo We can do something else here in the meantime later. */
rc = RTThreadUserWait(threadWait, RT_INDEFINITE_WAIT);
if (RT_SUCCESS(rc))
rc = threadData.rc; /* Get back thread result to take further actions. */
}
else
pam_vbox_error(hPAM, "pam_vbox_wait_for_creds: Creating thread failed with rc=%Rrc\n", rc);
pam_vbox_log(hPAM, "pam_vbox_wait_for_creds: Waiting for credentials returned with rc=%Rrc\n", rc);
return rc;
}
示例7: AssertMsgReturn
int VBoxNetBaseService::startReceiveThreadAndEnterEventLoop()
{
AssertMsgReturn(isMainNeeded(), ("It's expected that we need Main"), VERR_INTERNAL_ERROR);
/* start receiving thread */
int rc = RTThreadCreate(&m->m_hThrRecv, /* thread handle*/
&VBoxNetBaseService::Data::recvLoop, /* routine */
this, /* user data */
128 * _1K, /* stack size */
RTTHREADTYPE_IO, /* type */
RTTHREADFLAGS_WAITABLE, /* flags */
"RECV");
AssertRCReturn(rc, rc);
m->m_EventQ = com::NativeEventQueue::getMainEventQueue();
AssertPtrReturn(m->m_EventQ, VERR_INTERNAL_ERROR);
while (!m->fShutdown)
{
rc = m->m_EventQ->processEventQueue(RT_INDEFINITE_WAIT);
if (rc == VERR_INTERRUPTED)
{
LogFlow(("Event queue processing ended with rc=%Rrc\n", rc));
break;
}
}
return VINF_SUCCESS;
}
示例8: AssertPtrReturn
int
VBoxCredProvPoller::Initialize(VBoxCredProvProvider *pProvider)
{
AssertPtrReturn(pProvider, VERR_INVALID_POINTER);
VBoxCredProvVerbose(0, "VBoxCredProvPoller: Initializing\n");
/* Don't create more than one of them. */
if (m_hThreadPoller != NIL_RTTHREAD)
{
VBoxCredProvVerbose(0, "VBoxCredProvPoller: Thread already running, returning\n");
return VINF_SUCCESS;
}
if (m_pProv != NULL)
m_pProv->Release();
m_pProv = pProvider;
/*
* We must not add a reference via AddRef() here, otherwise
* the credential provider does not get destructed properly.
* In order to get this thread terminated normally the credential
* provider has to call Shutdown().
*/
/* Create the poller thread. */
int rc = RTThreadCreate(&m_hThreadPoller, VBoxCredProvPoller::threadPoller, this, 0, RTTHREADTYPE_INFREQUENT_POLLER,
RTTHREADFLAGS_WAITABLE, "credpoll");
if (RT_FAILURE(rc))
VBoxCredProvVerbose(0, "VBoxCredProvPoller::Initialize: Failed to create thread, rc=%Rrc\n", rc);
return rc;
}
示例9: 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;
}
示例10: 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);
}
示例11: 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;
}
示例12: RTThreadCreate
int VFSExplorer::TaskVFSExplorer::startThread()
{
int vrc = RTThreadCreate(NULL, VFSExplorer::TaskVFSExplorer::taskThread, this,
0, RTTHREADTYPE_MAIN_HEAVY_WORKER, 0,
"Explorer::Task");
if (RT_FAILURE(vrc))
return VFSExplorer::setErrorStatic(E_FAIL, Utf8StrFmt("Could not create taskThreadVFS (%Rrc)\n", vrc));
return vrc;
}
示例13: startXPCOMEventQueueThread
/**
* Creates the XPCOM event thread
*
* @returns VBOX status code
* @param eqFD XPCOM event queue file descriptor
*/
int startXPCOMEventQueueThread(int eqFD)
{
int rc = RTSemEventCreate(&g_EventSemXPCOMQueueThread);
if (RT_SUCCESS(rc))
{
RTTHREAD Thread;
rc = RTThreadCreate(&Thread, xpcomEventThread, (void *)(intptr_t)eqFD,
0, RTTHREADTYPE_MSG_PUMP, 0, "XPCOMEvent");
}
AssertRC(rc);
return rc;
}
示例14: HostPowerService
HostPowerServiceWin::HostPowerServiceWin(VirtualBox *aVirtualBox) : HostPowerService(aVirtualBox), mThread(NIL_RTTHREAD)
{
mHwnd = 0;
int rc = RTThreadCreate(&mThread, HostPowerServiceWin::NotificationThread, this, 65536,
RTTHREADTYPE_GUI, RTTHREADFLAGS_WAITABLE, "MainPower");
if (RT_FAILURE(rc))
{
Log(("HostPowerServiceWin::HostPowerServiceWin: RTThreadCreate failed with %Rrc\n", rc));
return;
}
}
示例15: RTThreadCreate
/**
* Start the X11 window configuration change monitor thread.
*/
int SeamlessMain::startX11MonitorThread(void)
{
int rc;
mX11MonitorThreadStopping = false;
if (isX11MonitorThreadRunning())
return VINF_SUCCESS;
rc = RTThreadCreate(&mX11MonitorThread, x11MonitorThread, this, 0,
RTTHREADTYPE_MSG_PUMP, RTTHREADFLAGS_WAITABLE,
"X11 events");
if (RT_FAILURE(rc))
LogRelFunc(("Warning: failed to start X11 monitor thread (VBoxClient).\n"));
return rc;
}