本文整理汇总了C++中RTThreadSleep函数的典型用法代码示例。如果您正苦于以下问题:C++ RTThreadSleep函数的具体用法?C++ RTThreadSleep怎么用?C++ RTThreadSleep使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTThreadSleep函数的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: tstPDMACTestFileThread
static int tstPDMACTestFileThread(PVM pVM, PPDMTHREAD pThread)
{
PPDMACTESTFILE pTestFile = (PPDMACTESTFILE)pThread->pvUser;
int iWriteChance = 100; /* Chance to get a write task in percent. */
uint32_t cTasksStarted = 0;
int rc = VINF_SUCCESS;
if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
return VINF_SUCCESS;
while (pTestFile->fRunning)
{
unsigned iTaskCurr = 0;
/* Fill all tasks */
while ( (pTestFile->cTasksActiveCurr < pTestFile->cTasksActiveMax)
&& (iTaskCurr < pTestFile->cTasksActiveMax))
{
PPDMACTESTFILETASK pTask = &pTestFile->paTasks[iTaskCurr];
if (!pTask->fActive)
{
/* Read or write task? */
bool fWrite = tstPDMACTestIsTrue(iWriteChance);
ASMAtomicIncU32(&pTestFile->cTasksActiveCurr);
if (fWrite)
rc = tstPDMACStressTestFileWrite(pTestFile, pTask);
else
rc = tstPDMACStressTestFileRead(pTestFile, pTask);
if (rc != VINF_AIO_TASK_PENDING)
tstPDMACStressTestFileTaskCompleted(pVM, pTask, pTestFile, rc);
cTasksStarted++;
}
iTaskCurr++;
}
/*
* Recalc write chance. The bigger the file the lower the chance to have a write.
* The minimum chance is 33 percent.
*/
iWriteChance = 100 - (int)(((float)100.0 / pTestFile->cbFileMax) * (float)pTestFile->cbFileCurr);
iWriteChance = RT_MAX(33, iWriteChance);
/* Wait a random amount of time. (1ms - 100ms) */
RTThreadSleep(RTRandU32Ex(1, 100));
}
/* Wait for the rest to complete. */
while (pTestFile->cTasksActiveCurr)
RTThreadSleep(250);
RTPrintf("Thread exiting: processed %u tasks\n", cTasksStarted);
return rc;
}
示例3: VBoxOglIs3DAccelerationSupported
bool RTCALL VBoxOglIs3DAccelerationSupported(void)
{
if (RTEnvExist("VBOX_CROGL_FORCE_SUPPORTED"))
{
LogRel(("VBOX_CROGL_FORCE_SUPPORTED is specified, skipping 3D test, and treating as supported\n"));
return true;
}
static char pszVBoxPath[RTPATH_MAX];
const char *papszArgs[4] = { NULL, "-test", "3D", NULL};
int rc;
RTPROCESS Process;
RTPROCSTATUS ProcStatus;
uint64_t StartTS;
rc = RTPathExecDir(pszVBoxPath, RTPATH_MAX); AssertRCReturn(rc, false);
#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
rc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL.exe");
#else
rc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL");
#endif
papszArgs[0] = pszVBoxPath; /* argv[0] */
AssertRCReturn(rc, false);
rc = RTProcCreate(pszVBoxPath, papszArgs, RTENV_DEFAULT, 0, &Process);
if (RT_FAILURE(rc))
return false;
StartTS = RTTimeMilliTS();
while (1)
{
rc = RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
if (rc != VERR_PROCESS_RUNNING)
break;
#ifndef DEBUG_misha
if (RTTimeMilliTS() - StartTS > 30*1000 /* 30 sec */)
{
RTProcTerminate(Process);
RTThreadSleep(100);
RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
return false;
}
#endif
RTThreadSleep(100);
}
if (RT_SUCCESS(rc))
{
if ((ProcStatus.enmReason==RTPROCEXITREASON_NORMAL) && (ProcStatus.iStatus==0))
{
return true;
}
}
return false;
}
示例4: 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);
}
示例5: is3DAccelerationSupported
bool is3DAccelerationSupported()
{
static char pszVBoxPath[RTPATH_MAX];
const char *papszArgs[4] = { NULL, "-test", "3D", NULL};
int rc;
RTPROCESS Process;
RTPROCSTATUS ProcStatus;
uint64_t StartTS;
rc = RTPathExecDir(pszVBoxPath, RTPATH_MAX);
AssertRCReturn(rc, false);
#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
rc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL.exe");
#else
rc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL");
#endif
papszArgs[0] = pszVBoxPath; /* argv[0] */
AssertRCReturn(rc, false);
rc = RTProcCreate(pszVBoxPath, papszArgs, RTENV_DEFAULT, 0, &Process);
if (RT_FAILURE(rc))
return false;
StartTS = RTTimeMilliTS();
while (1)
{
rc = RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
if (rc != VERR_PROCESS_RUNNING)
break;
if (RTTimeMilliTS() - StartTS > 30*1000 /* 30 sec */)
{
RTProcTerminate(Process);
RTThreadSleep(100);
RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
return false;
}
RTThreadSleep(100);
}
if (RT_SUCCESS(rc))
{
if ((ProcStatus.enmReason==RTPROCEXITREASON_NORMAL) && (ProcStatus.iStatus==0))
{
return true;
}
}
return false;
}
示例6: DECLCALLBACK
/**
* @interface_method_impl{TXSTRANSPORT,pfnInit}
*/
static DECLCALLBACK(int) txsTcpInit(void)
{
int rc = RTCritSectInit(&g_TcpCritSect);
if (RT_SUCCESS(rc) && g_enmTcpMode != TXSTCPMODE_CLIENT)
{
rc = RTTcpServerCreateEx(g_szTcpBindAddr[0] ? g_szTcpBindAddr : NULL, g_uTcpBindPort, &g_pTcpServer);
if (RT_FAILURE(rc))
{
if (rc == VERR_NET_DOWN)
{
RTMsgInfo("RTTcpServerCreateEx(%s, %u,) failed: %Rrc, retrying for 20 seconds...\n",
g_szTcpBindAddr[0] ? g_szTcpBindAddr : NULL, g_uTcpBindPort, rc);
uint64_t StartMs = RTTimeMilliTS();
do
{
RTThreadSleep(1000);
rc = RTTcpServerCreateEx(g_szTcpBindAddr[0] ? g_szTcpBindAddr : NULL, g_uTcpBindPort, &g_pTcpServer);
} while ( rc == VERR_NET_DOWN
&& RTTimeMilliTS() - StartMs < 20000);
if (RT_SUCCESS(rc))
RTMsgInfo("RTTcpServerCreateEx succceeded.\n");
}
if (RT_FAILURE(rc))
{
g_pTcpServer = NULL;
RTCritSectDelete(&g_TcpCritSect);
RTMsgError("RTTcpServerCreateEx(%s, %u,) failed: %Rrc\n",
g_szTcpBindAddr[0] ? g_szTcpBindAddr : NULL, g_uTcpBindPort, rc);
}
}
}
return rc;
}
示例7: tstTrafficThreadCommon
static int tstTrafficThreadCommon(uintptr_t iThread, bool fNS)
{
for (uint32_t iLoop = 0; RTTimeMilliTS() - g_u64StartMilliTS < g_cSecs*1000; iLoop++)
{
/* fudge */
if ((iLoop % 223) == 223)
RTThreadYield();
else if ((iLoop % 16127) == 16127)
RTThreadSleep(1);
if (fNS)
{
RTTEST_CHECK_RC(g_hTest,RTSemXRoadsNSEnter(g_hXRoads), VINF_SUCCESS);
ASMAtomicIncU32(&g_cNSCrossings);
RTTEST_CHECK_RC(g_hTest,RTSemXRoadsNSLeave(g_hXRoads), VINF_SUCCESS);
}
else
{
RTTEST_CHECK_RC(g_hTest,RTSemXRoadsEWEnter(g_hXRoads), VINF_SUCCESS);
ASMAtomicIncU32(&g_cEWCrossings);
RTTEST_CHECK_RC(g_hTest,RTSemXRoadsEWLeave(g_hXRoads), VINF_SUCCESS);
}
}
return VINF_SUCCESS;
}
示例8: RTDECL
RTDECL(int) RTTraceSetDefaultBuf(RTTRACEBUF hTraceBuf)
{
/* Retain the new buffer. */
if (hTraceBuf != NIL_RTTRACEBUF)
{
uint32_t cRefs = RTTraceBufRetain(hTraceBuf);
if (cRefs >= _1M)
return VERR_INVALID_HANDLE;
}
RTTRACEBUF hOldTraceBuf;
#ifdef IN_RC
hOldTraceBuf = (RTTRACEBUF)ASMAtomicXchgPtr((void **)&g_hDefaultTraceBuf, hTraceBuf);
#else
ASMAtomicXchgHandle(&g_hDefaultTraceBuf, hTraceBuf, &hOldTraceBuf);
#endif
if ( hOldTraceBuf != NIL_RTTRACEBUF
&& hOldTraceBuf != hTraceBuf)
{
/* Race prevention kludge. */
#ifndef IN_RC
RTThreadSleep(33);
#endif
RTTraceBufRelease(hOldTraceBuf);
}
return VINF_SUCCESS;
}
示例9: NotifyUpdate
STDMETHODIMP UIFrameBufferQGL::RequestResize (ULONG aScreenId, ULONG aPixelFormat,
BYTE *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine,
ULONG aWidth, ULONG aHeight,
BOOL *aFinished)
{
aWidth = VBOXQGL_PROF_WIDTH;
aHeight = VBOXQGL_PROF_HEIGHT;
VBoxFrameBuffer::RequestResize (aScreenId, aPixelFormat,
aVRAM, aBitsPerPixel, aBytesPerLine,
aWidth, aHeight,
aFinished);
// if(aVRAM)
{
for(;;)
{
ULONG aX = 0;
ULONG aY = 0;
ULONG aW = aWidth;
ULONG aH = aHeight;
NotifyUpdate (aX, aY, aW, aH);
RTThreadSleep(40);
}
}
return S_OK;
}
示例10: test1
static void test1(void)
{
RTTestSub(g_hTest, "Interrupt RTThreadSleep");
RTTHREAD hThread[16];
RTMSINTERVAL msWait = 1000;
for (unsigned i = 0; i < RT_ELEMENTS(hThread); i++)
{
RTTESTI_CHECK_RC_RETV(RTThreadCreate(&hThread[i], testThread, NULL, 0, RTTHREADTYPE_DEFAULT,
RTTHREADFLAGS_WAITABLE, "test"), VINF_SUCCESS);
}
RTThreadSleep(500);
RTPrintf("Waiting for %dms ...\n", msWait);
RTThreadSleep(msWait);
for (unsigned i = 0; i < RT_ELEMENTS(hThread); i++)
RTTESTI_CHECK_RC(RTThreadWait(hThread[i], RT_INDEFINITE_WAIT, NULL), VINF_SUCCESS);
RTPrintf("sum kernel = %lldms, sum user = %lldms\n", g_kernel, g_user);
}
开发者ID:stefano-garzarella,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:18,代码来源:tstRTThreadExecutionTime.cpp
示例11: DECLCALLBACK
/**
* Receive thread loop.
*
* @returns 0 on success.
* @param ThreadSelf Thread handle to this thread.
* @param pvUser User argument.
*/
static DECLCALLBACK(int) drvCharReceiveLoop(RTTHREAD ThreadSelf, void *pvUser)
{
PDRVCHAR pThis = (PDRVCHAR)pvUser;
char abBuffer[256];
char *pbRemaining = abBuffer;
size_t cbRemaining = 0;
int rc;
while (!pThis->fShutdown)
{
if (!cbRemaining)
{
/* Get block of data from stream driver. */
if (pThis->pDrvStream)
{
pbRemaining = abBuffer;
cbRemaining = sizeof(abBuffer);
rc = pThis->pDrvStream->pfnRead(pThis->pDrvStream, abBuffer, &cbRemaining);
if (RT_FAILURE(rc))
{
LogFlow(("Read failed with %Rrc\n", rc));
break;
}
}
else
RTThreadSleep(100);
}
else
{
/* Send data to guest. */
size_t cbProcessed = cbRemaining;
rc = pThis->pDrvCharPort->pfnNotifyRead(pThis->pDrvCharPort, pbRemaining, &cbProcessed);
if (RT_SUCCESS(rc))
{
Assert(cbProcessed);
pbRemaining += cbProcessed;
cbRemaining -= cbProcessed;
STAM_COUNTER_ADD(&pThis->StatBytesRead, cbProcessed);
}
else if (rc == VERR_TIMEOUT)
{
/* Normal case, just means that the guest didn't accept a new
* character before the timeout elapsed. Just retry. */
rc = VINF_SUCCESS;
}
else
{
LogFlow(("NotifyRead failed with %Rrc\n", rc));
break;
}
}
}
return VINF_SUCCESS;
}
示例12: DECLCALLBACK
/**
* Send thread.
* This is constantly sending frames to the other interface.
*/
DECLCALLBACK(int) SendThread(RTTHREAD Thread, void *pvArg)
{
PMYARGS pArgs = (PMYARGS)pvArg;
int rc;
/*
* Send g_cbTransfer of data.
*/
uint8_t abBuf[16384] = {0};
MYFRAMEHDR *pHdr = (MYFRAMEHDR *)&abBuf[0];
uint32_t iFrame = 0;
uint32_t cbSent = 0;
uint32_t cSend = 0;
pHdr->SrcMac = pArgs->Mac;
pHdr->DstMac = pArgs->Mac;
pHdr->DstMac.au16[2] = (pArgs->Mac.au16[2] + 1) % 2;
pArgs->u64Start = RTTimeNanoTS();
for (; cbSent < g_cbTransfer; iFrame++)
{
const unsigned cb = pArgs->cbFrame
? pArgs->cbFrame
: iFrame % 1519 + sizeof(RTMAC) * 2 + sizeof(unsigned);
pHdr->iFrame = iFrame;
INTNETSG Sg;
IntNetSgInitTemp(&Sg, abBuf, cb);
RTTEST_CHECK_RC_OK(g_hTest, rc = intnetR0RingWriteFrame(&pArgs->pBuf->Send, &Sg, NULL));
if (RT_SUCCESS(rc))
RTTEST_CHECK_RC_OK(g_hTest, rc = IntNetR0IfSend(pArgs->hIf, g_pSession));
cbSent += cb;
}
/*
* Termination frames.
*/
pHdr->iFrame = 0xffffdead;
pHdr->auEos[0] = 0xffffdead;
pHdr->auEos[1] = 0xffffdead;
pHdr->auEos[2] = 0xffffdead;
for (unsigned c = 0; c < 20; c++)
{
RTTEST_CHECK_RC_OK(g_hTest, rc = tstIntNetSendBuf(&pArgs->pBuf->Send, pArgs->hIf, g_pSession,
abBuf, sizeof(RTMAC) * 2 + sizeof(unsigned) * 4));
RTThreadSleep(1);
}
RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
"sender thread %.6Rhxs terminating.\n"
"iFrame=%u cb=%'u\n",
&pArgs->Mac, iFrame, cbSent);
return 0;
}
示例13: mainParent
/**
* The parent main routine.
* @param argv0 The executable name (or whatever).
*/
static int mainParent(const char *argv0)
{
/*
* Init.
*/
RTTEST hTest;
int rc = RTTestInitAndCreate("tstSupSem-Zombie", &hTest);
if (rc)
return rc;
RTTestBanner(hTest);
/*
* Spin of the child process which may or may not turn into a zombie
*/
for (uint32_t iPass = 0; iPass < 32; iPass++)
{
RTTestSubF(hTest, "Pass %u", iPass);
RTPROCESS hProcess;
const char *apszArgs[3] = { argv0, "--child", NULL };
RTTESTI_CHECK_RC_OK(rc = RTProcCreate(argv0, apszArgs, RTENV_DEFAULT, 0 /*fFlags*/, &hProcess));
if (RT_SUCCESS(rc))
{
/*
* Wait for 60 seconds then give up.
*/
RTPROCSTATUS Status;
uint64_t StartTS = RTTimeMilliTS();
for (;;)
{
rc = RTProcWait(hProcess, RTPROCWAIT_FLAGS_NOBLOCK, &Status);
if (RT_SUCCESS(rc))
break;
uint64_t cElapsed = RTTimeMilliTS() - StartTS;
if (cElapsed > 60*1000)
break;
RTThreadSleep(cElapsed < 60 ? 30 : cElapsed < 200 ? 10 : 100);
}
RTTESTI_CHECK_RC_OK(rc);
if ( RT_SUCCESS(rc)
&& ( Status.enmReason != RTPROCEXITREASON_NORMAL
|| Status.iStatus != 0))
{
RTTestIFailed("child %d (%#x) reason %d\n", Status.iStatus, Status.iStatus, Status.enmReason);
rc = VERR_PERMISSION_DENIED;
}
}
/* one zombie process is enough. */
if (RT_FAILURE(rc))
break;
}
return RTTestSummaryAndDestroy(hTest);
}
示例14: main
int main(int argc, char **argv)
{
RTR3InitExe(argc, &argv, RTR3INIT_FLAGS_SUPLIB);
if (argc <= 1)
{
RTPrintf("tstTime-3: usage: tstTime-3 <seconds> [seconds2 [..]]\n");
return 1;
}
RTPrintf("tstTime-3: Testing difference between RTTimeNanoTS() and OS time...\n");
for (int i = 1; i < argc; i++)
{
uint64_t cSeconds = 0;
int rc = RTStrToUInt64Ex(argv[i], NULL, 0, &cSeconds);
if (RT_FAILURE(rc))
{
RTPrintf("tstTime-3: Invalid argument %d: %s\n", i, argv[i]);
return 1;
}
RTPrintf("tstTime-3: %d - %RU64 seconds period...\n", i, cSeconds);
RTTimeNanoTS(); OSNanoTS(); RTThreadSleep(1);
uint64_t u64RTStartTS = RTTimeNanoTS();
uint64_t u64OSStartTS = OSNanoTS();
RTThreadSleep(cSeconds * 1000);
uint64_t u64RTElapsedTS = RTTimeNanoTS();
uint64_t u64OSElapsedTS = OSNanoTS();
u64RTElapsedTS -= u64RTStartTS;
u64OSElapsedTS -= u64OSStartTS;
RTPrintf("tstTime-3: %d - RT: %16RU64 ns\n", i, u64RTElapsedTS);
RTPrintf("tstTime-3: %d - OS: %16RU64 ns\n", i, u64OSElapsedTS);
RTPrintf("tstTime-3: %d - diff: %16RI64 ns\n", i, u64RTElapsedTS - u64OSElapsedTS);
}
return 0;
}
示例15: tstRTCreateProcEx2
static void tstRTCreateProcEx2(const char *pszAsUser, const char *pszPassword)
{
RTTestISub("Standard Err");
RTPIPE hPipeR, hPipeW;
RTTESTI_CHECK_RC_RETV(RTPipeCreate(&hPipeR, &hPipeW, RTPIPE_C_INHERIT_WRITE), VINF_SUCCESS);
const char * apszArgs[3] =
{
"non-existing-non-executable-file",
"--testcase-child-2",
NULL
};
RTHANDLE Handle;
Handle.enmType = RTHANDLETYPE_PIPE;
Handle.u.hPipe = hPipeW;
RTPROCESS hProc;
RTTESTI_CHECK_RC_RETV(RTProcCreateEx(g_szExecName, apszArgs, RTENV_DEFAULT, 0 /*fFlags*/, NULL,
NULL, &Handle, pszAsUser, pszPassword, &hProc), VINF_SUCCESS);
RTTESTI_CHECK_RC(RTPipeClose(hPipeW), VINF_SUCCESS);
char szOutput[_4K];
size_t offOutput = 0;
for (;;)
{
size_t cbLeft = sizeof(szOutput) - 1 - offOutput;
RTTESTI_CHECK(cbLeft > 0);
if (cbLeft == 0)
break;
size_t cbRead;
int rc = RTPipeReadBlocking(hPipeR, &szOutput[offOutput], cbLeft, &cbRead);
if (RT_FAILURE(rc))
{
RTTESTI_CHECK_RC(rc, VERR_BROKEN_PIPE);
break;
}
offOutput += cbRead;
}
szOutput[offOutput] = '\0';
RTTESTI_CHECK_RC(RTPipeClose(hPipeR), VINF_SUCCESS);
RTPROCSTATUS ProcStatus = { -1, RTPROCEXITREASON_ABEND };
RTTESTI_CHECK_RC(RTProcWait(hProc, RTPROCWAIT_FLAGS_BLOCK, &ProcStatus), VINF_SUCCESS);
RTThreadSleep(10);
if (ProcStatus.enmReason != RTPROCEXITREASON_NORMAL || ProcStatus.iStatus != 0)
RTTestIFailed("enmReason=%d iStatus=%d", ProcStatus.enmReason, ProcStatus.iStatus);
else if ( offOutput != sizeof("howdy") - 1
|| strcmp(szOutput, "howdy"))
RTTestIFailed("wrong output: \"%s\" (len=%u)", szOutput, offOutput);
else
RTTestIPassed(NULL);
}