这篇教程C++ ASMAtomicWriteBool函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中ASMAtomicWriteBool函数的典型用法代码示例。如果您正苦于以下问题:C++ ASMAtomicWriteBool函数的具体用法?C++ ASMAtomicWriteBool怎么用?C++ ASMAtomicWriteBool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了ASMAtomicWriteBool函数的22个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: RTDECLRTDECL(int) RTTimerStart(PRTTIMER pTimer, uint64_t u64First){ /* * Validate. */ AssertPtrReturn(pTimer, VERR_INVALID_HANDLE); AssertReturn(pTimer->u32Magic == RTTIMER_MAGIC, VERR_INVALID_HANDLE); if (!ASMAtomicUoReadBool(&pTimer->fSuspended)) return VERR_TIMER_ACTIVE; if ( pTimer->fSpecificCpu && !RTMpIsCpuOnline(pTimer->idCpu)) return VERR_CPU_OFFLINE; /* * Start the timer. */ PKDPC pMasterDpc = pTimer->fOmniTimer ? &pTimer->aSubTimers[RTMpCpuIdToSetIndex(pTimer->idCpu)].NtDpc : &pTimer->aSubTimers[0].NtDpc;#ifndef RTR0TIMER_NT_MANUAL_RE_ARM uint64_t u64Interval = pTimer->u64NanoInterval / 1000000; /* This is ms, believe it or not. */ ULONG ulInterval = (ULONG)u64Interval; if (ulInterval != u64Interval) ulInterval = MAXLONG; else if (!ulInterval && pTimer->u64NanoInterval) ulInterval = 1;#endif LARGE_INTEGER DueTime; DueTime.QuadPart = -(int64_t)(u64First / 100); /* Relative, NT time. */ if (!DueTime.QuadPart) DueTime.QuadPart = -1; unsigned cSubTimers = pTimer->fOmniTimer ? pTimer->cSubTimers : 1; for (unsigned iCpu = 0; iCpu < cSubTimers; iCpu++) pTimer->aSubTimers[iCpu].iTick = 0; ASMAtomicWriteS32(&pTimer->cOmniSuspendCountDown, 0); ASMAtomicWriteBool(&pTimer->fSuspended, false);#ifdef RTR0TIMER_NT_MANUAL_RE_ARM pTimer->uNtStartTime = rtTimerNtQueryInterruptTime() + u64First / 100; KeSetTimerEx(&pTimer->NtTimer, DueTime, 0, pMasterDpc);#else KeSetTimerEx(&pTimer->NtTimer, DueTime, ulInterval, pMasterDpc);#endif return VINF_SUCCESS;}
开发者ID:miguelinux,项目名称:vbox,代码行数:48,
示例2: LogFlowFuncEnterint GuestCtrlEvent::Wait(ULONG uTimeoutMS){ LogFlowFuncEnter(); AssertReturn(hEventSem != NIL_RTSEMEVENT, VERR_CANCELLED); RTMSINTERVAL msInterval = uTimeoutMS; if (!uTimeoutMS) msInterval = RT_INDEFINITE_WAIT; int rc = RTSemEventWait(hEventSem, msInterval); if (RT_SUCCESS(rc)) ASMAtomicWriteBool(&fCompleted, true); LogFlowFuncLeaveRC(rc); return rc;}
开发者ID:greg100795,项目名称:virtualbox,代码行数:16,
示例3: RTDECLRTDECL(uint32_t) RTPollSetGetCount(RTPOLLSET hPollSet){ /* * Validate the input. */ RTPOLLSETINTERNAL *pThis = hPollSet; AssertPtrReturn(pThis, UINT32_MAX); AssertReturn(pThis->u32Magic == RTPOLLSET_MAGIC, UINT32_MAX); /* * Set the busy flag and do the job. */ AssertReturn(ASMAtomicCmpXchgBool(&pThis->fBusy, true, false), UINT32_MAX); uint32_t cHandles = pThis->cHandles; ASMAtomicWriteBool(&pThis->fBusy, false); return cHandles;}
开发者ID:leopucci,项目名称:VirtualMonitor,代码行数:18,
示例4: vboxClipboardDestroyvoid vboxClipboardDestroy (void){ Log(("vboxClipboardDestroy/n")); /* Set the termination flag and ping the window thread. */ ASMAtomicWriteBool (&g_ctx.fTerminate, true); if (g_ctx.hwnd) { PostMessage (g_ctx.hwnd, WM_CLOSE, 0, 0); } CloseHandle (g_ctx.hRenderEvent); /* Wait for the window thread to terminate. */ RTThreadWait (g_ctx.thread, RT_INDEFINITE_WAIT, NULL); g_ctx.thread = NIL_RTTHREAD;}
开发者ID:gvsurenderreddy,项目名称:VirtualBox-OSE,代码行数:19,
示例5: DECLCALLBACK/** * Bootstrap VMR3Wait() worker. * * @returns VBox status code. * @param pUVMCPU Pointer to the user mode VMCPU structure. */static DECLCALLBACK(int) vmR3BootstrapWait(PUVMCPU pUVCpu){ PUVM pUVM = pUVCpu->pUVM; ASMAtomicWriteBool(&pUVCpu->vm.s.fWait, true); int rc = VINF_SUCCESS; for (;;) { /* * Check Relevant FFs. */ if (pUVM->vm.s.pNormalReqs || pUVM->vm.s.pPriorityReqs) /* global requests pending? */ break; if (pUVCpu->vm.s.pNormalReqs || pUVCpu->vm.s.pPriorityReqs) /* local requests pending? */ break; if ( pUVCpu->pVM && ( VM_FF_ISPENDING(pUVCpu->pVM, VM_FF_EXTERNAL_SUSPENDED_MASK) || VMCPU_FF_ISPENDING(VMMGetCpu(pUVCpu->pVM), VMCPU_FF_EXTERNAL_SUSPENDED_MASK) ) ) break; if (pUVM->vm.s.fTerminateEMT) 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/n", rc); break; } } ASMAtomicUoWriteBool(&pUVCpu->vm.s.fWait, false); return rc;}
开发者ID:greg100795,项目名称:virtualbox,代码行数:49,
示例6: DECLCALLBACK/** * @interface_method_impl{PDMINETWORKUP,pfnNotifyLinkChanged} */static DECLCALLBACK(void) drvR3DedicatedNicUp_NotifyLinkChanged(PPDMINETWORKUP pInterface, PDMNETWORKLINKSTATE enmLinkState){ PDRVDEDICATEDNIC pThis = RT_FROM_MEMBER(pInterface, DRVDEDICATEDNIC, CTX_SUFF(INetworkUp)); bool fLinkDown; switch (enmLinkState) { case PDMNETWORKLINKSTATE_DOWN: case PDMNETWORKLINKSTATE_DOWN_RESUME: fLinkDown = true; break; default: AssertMsgFailed(("enmLinkState=%d/n", enmLinkState)); case PDMNETWORKLINKSTATE_UP: fLinkDown = false; break; } LogFlow(("drvR3DedicatedNicUp_NotifyLinkChanged: enmLinkState=%d %d->%d/n", enmLinkState, pThis->fLinkDown, fLinkDown)); ASMAtomicWriteBool(&pThis->fLinkDown, fLinkDown);}
开发者ID:VirtualMonitor,项目名称:VirtualMonitor,代码行数:22,
示例7: rtTimerNtStopWorker/** * Worker function that stops an active timer. * * Shared by RTTimerStop and RTTimerDestroy. * * @param pTimer The active timer. */static void rtTimerNtStopWorker(PRTTIMER pTimer){ /* * Just cancel the timer, dequeue the DPCs and flush them (if this is supported). */ ASMAtomicWriteBool(&pTimer->fSuspended, true); KeCancelTimer(&pTimer->NtTimer); for (RTCPUID iCpu = 0; iCpu < pTimer->cSubTimers; iCpu++) KeRemoveQueueDpc(&pTimer->aSubTimers[iCpu].NtDpc); /* * I'm a bit uncertain whether this should be done during RTTimerStop * or only in RTTimerDestroy()... Linux and Solaris will wait AFAIK, * which is why I'm keeping this here for now. */ if (g_pfnrtNtKeFlushQueuedDpcs) g_pfnrtNtKeFlushQueuedDpcs();}
开发者ID:greg100795,项目名称:virtualbox,代码行数:26,
示例8: DECLCALLBACKstatic DECLCALLBACK(int) Once2CB(void *pvUser){ if (ASMAtomicIncU32(&g_cOnce2CB) != 1) { RTPrintf("tstOnce: ERROR - Once2CB: g_cOnce2CB not zero!/n"); g_cErrors++; return VERR_WRONG_ORDER; } if (pvUser != (void *)42) { RTPrintf("tstOnce: ERROR - Once2CB: pvUser=%p!/n", pvUser); g_cErrors++; return VERR_INVALID_PARAMETER; } RTThreadSleep(2); Assert(!g_fOnce2Ready); ASMAtomicWriteBool(&g_fOnce2Ready, true); return VINF_SUCCESS;}
开发者ID:miguelinux,项目名称:vbox,代码行数:19,
示例9: DECLCALLBACK/** * Callback employed by drvscsiReset. * * @returns true if we've quiesced, false if we're still working. * @param pDrvIns The driver instance. */static DECLCALLBACK(bool) drvscsiIsAsyncResetDone(PPDMDRVINS pDrvIns){ PDRVSCSI pThis = PDMINS_2_DATA(pDrvIns, PDRVSCSI); if (pThis->pDrvBlockAsync) { if (pThis->StatIoDepth > 0) return false; else return true; } else { if (!drvscsiAsyncIOLoopNoPendingDummy(pThis, 0 /*ms*/)) return false; ASMAtomicWriteBool(&pThis->fDummySignal, false); return true; }}
开发者ID:stefano-garzarella,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:25,
示例10: DECLCALLBACK/** * EMT worker for DBGFR3Attach. * * @returns VBox status code. * @param pVM Pointer to the VM. */static DECLCALLBACK(int) dbgfR3Attach(PVM pVM){ if (pVM->dbgf.s.fAttached) { Log(("dbgR3Attach: Debugger already attached/n")); return VERR_DBGF_ALREADY_ATTACHED; } /* * Create the Ping-Pong structure. */ int rc = RTSemPingPongInit(&pVM->dbgf.s.PingPong); AssertRCReturn(rc, rc); /* * Set the attached flag. */ ASMAtomicWriteBool(&pVM->dbgf.s.fAttached, true); return VINF_SUCCESS;}
开发者ID:greg100795,项目名称:virtualbox,代码行数:26,
示例11: vboxClipboardDestroy/** Terminate the host side of the shared clipboard - called by the hgcm layer. */void vboxClipboardDestroy(void){ Log(("vboxClipboardDestroy/n")); /* * Signal the termination of the polling thread and wait for it to respond. */ ASMAtomicWriteBool(&g_ctx.fTerminate, true); int rc = RTThreadUserSignal(g_ctx.thread); AssertRC(rc); rc = RTThreadWait(g_ctx.thread, RT_INDEFINITE_WAIT, NULL); AssertRC(rc); /* * Destroy the pasteboard and uninitialize the global context record. */ destroyPasteboard(&g_ctx.pasteboard); g_ctx.thread = NIL_RTTHREAD; g_ctx.pClient = NULL;}
开发者ID:mdaniel,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:21,
示例12: DECLCALLBACK/** * Callback employed by drvscsiSuspend and drvscsiPowerOff. * * @returns true if we've quiesced, false if we're still working. * @param pDrvIns The driver instance. */static DECLCALLBACK(bool) drvscsiIsAsyncSuspendOrPowerOffDone(PPDMDRVINS pDrvIns){ PDRVSCSI pThis = PDMINS_2_DATA(pDrvIns, PDRVSCSI); if (pThis->pDrvMediaAsync) { if (pThis->StatIoDepth > 0) return false; else return true; } else { if (!drvscsiAsyncIOLoopNoPendingDummy(pThis, 0 /*ms*/)) return false; ASMAtomicWriteBool(&pThis->fDummySignal, false); PDMR3ThreadSuspend(pThis->pAsyncIOThread); return true; }}
开发者ID:jeppeter,项目名称:vbox,代码行数:26,
示例13: rtTimerNtSimpleCallback/** * Timer callback function for the non-omni timers. * * @returns HRTIMER_NORESTART or HRTIMER_RESTART depending on whether it's a one-shot or interval timer. * @param pDpc Pointer to the DPC. * @param pvUser Pointer to our internal timer structure. * @param SystemArgument1 Some system argument. * @param SystemArgument2 Some system argument. */static void _stdcall rtTimerNtSimpleCallback(IN PKDPC pDpc, IN PVOID pvUser, IN PVOID SystemArgument1, IN PVOID SystemArgument2){ PRTTIMER pTimer = (PRTTIMER)pvUser; AssertPtr(pTimer);#ifdef RT_STRICT if (KeGetCurrentIrql() < DISPATCH_LEVEL) RTAssertMsg2Weak("rtTimerNtSimpleCallback: Irql=%d expected >=%d/n", KeGetCurrentIrql(), DISPATCH_LEVEL);#endif /* * Check that we haven't been suspended before doing the callout. */ if ( !ASMAtomicUoReadBool(&pTimer->fSuspended) && pTimer->u32Magic == RTTIMER_MAGIC) { if (!pTimer->u64NanoInterval) ASMAtomicWriteBool(&pTimer->fSuspended, true); pTimer->pfnTimer(pTimer, pTimer->pvUser, ++pTimer->aSubTimers[0].iTick); } NOREF(pDpc); NOREF(SystemArgument1); NOREF(SystemArgument2);}
开发者ID:MadHacker217,项目名称:VirtualBox-OSE,代码行数:31,
示例14: AssertVBoxDbgConsole::~VBoxDbgConsole(){ Assert(isGUIThread()); /* * Wait for the thread. */ ASMAtomicWriteBool(&m_fTerminate, true); RTSemEventSignal(m_EventSem); if (m_Thread != NIL_RTTHREAD) { int rc = RTThreadWait(m_Thread, 15000, NULL); AssertRC(rc); m_Thread = NIL_RTTHREAD; } /* * Free resources. */ delete m_pTimer; m_pTimer = NULL; RTCritSectDelete(&m_Lock); RTSemEventDestroy(m_EventSem); m_EventSem = 0; m_pOutput = NULL; m_pInput = NULL; if (m_pszInputBuf) { RTMemFree(m_pszInputBuf); m_pszInputBuf = NULL; } m_cbInputBuf = 0; m_cbInputBufAlloc = 0; delete m_pFocusToInput; m_pFocusToInput = NULL; delete m_pFocusToOutput; m_pFocusToOutput = NULL;}
开发者ID:mdaniel,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:39,
示例15: DECLHIDDENDECLHIDDEN(int) rtR0MpNotificationNativeInit(void){ if (ASMAtomicReadBool(&g_fSolCpuWatch) == true) return VERR_WRONG_ORDER; /* * Register the callback building the online cpu set as we do so. */ RTCpuSetEmpty(&g_rtMpSolCpuSet); mutex_enter(&cpu_lock); register_cpu_setup_func(rtMpNotificationCpuEvent, NULL /* pvArg */); for (int i = 0; i < (int)RTMpGetCount(); ++i) if (cpu_is_online(cpu[i])) rtMpNotificationCpuEvent(CPU_ON, i, NULL /* pvArg */); ASMAtomicWriteBool(&g_fSolCpuWatch, true); mutex_exit(&cpu_lock); return VINF_SUCCESS;}
开发者ID:svn2github,项目名称:virtualbox,代码行数:22,
示例16: VMMDECL/** * Obtain bandwidth in a bandwidth group. * * @returns True if bandwidth was allocated, false if not. * @param pFilter Pointer to the filter that allocates bandwidth. * @param cbTransfer Number of bytes to allocate. */VMMDECL(bool) PDMNsAllocateBandwidth(PPDMNSFILTER pFilter, size_t cbTransfer){ AssertPtrReturn(pFilter, true); if (!VALID_PTR(pFilter->CTX_SUFF(pBwGroup))) return true; PPDMNSBWGROUP pBwGroup = ASMAtomicReadPtrT(&pFilter->CTX_SUFF(pBwGroup), PPDMNSBWGROUP); int rc = PDMCritSectEnter(&pBwGroup->Lock, VERR_SEM_BUSY); AssertRC(rc); if (RT_UNLIKELY(rc == VERR_SEM_BUSY)) return true; bool fAllowed = true; if (pBwGroup->cbPerSecMax) { /* Re-fill the bucket first */ uint64_t tsNow = RTTimeSystemNanoTS(); uint32_t uTokensAdded = (tsNow - pBwGroup->tsUpdatedLast) * pBwGroup->cbPerSecMax / (1000 * 1000 * 1000); uint32_t uTokens = RT_MIN(pBwGroup->cbBucket, uTokensAdded + pBwGroup->cbTokensLast); if (cbTransfer > uTokens) { fAllowed = false; ASMAtomicWriteBool(&pFilter->fChoked, true); } else { pBwGroup->tsUpdatedLast = tsNow; pBwGroup->cbTokensLast = uTokens - (uint32_t)cbTransfer; } Log2(("pdmNsAllocateBandwidth: BwGroup=%#p{%s} cbTransfer=%u uTokens=%u uTokensAdded=%u fAllowed=%RTbool/n", pBwGroup, R3STRING(pBwGroup->pszNameR3), cbTransfer, uTokens, uTokensAdded, fAllowed)); } else Log2(("pdmNsAllocateBandwidth: BwGroup=%#p{%s} disabled fAllowed=%RTbool/n", pBwGroup, R3STRING(pBwGroup->pszNameR3), fAllowed)); rc = PDMCritSectLeave(&pBwGroup->Lock); AssertRC(rc); return fAllowed;}
开发者ID:mdaniel,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:46,
示例17: DECLCALLBACK/** * @copydoc SSMSTRMOPS::pfnClose */static DECLCALLBACK(int) teleporterTcpOpClose(void *pvUser, bool fCanceled){ TeleporterState *pState = (TeleporterState *)pvUser; if (pState->mfIsSource) { TELEPORTERTCPHDR EofHdr; EofHdr.u32Magic = TELEPORTERTCPHDR_MAGIC; EofHdr.cb = fCanceled ? UINT32_MAX : 0; int rc = RTTcpWrite(pState->mhSocket, &EofHdr, sizeof(EofHdr)); if (RT_FAILURE(rc)) { LogRel(("Teleporter/TCP: EOF Header write error: %Rrc/n", rc)); return rc; } } else { ASMAtomicWriteBool(&pState->mfStopReading, true); } return VINF_SUCCESS;}
开发者ID:marktsai0316,项目名称:VirtualMonitor,代码行数:26,
示例18: RTDECLRTDECL(int) RTTimerStart(PRTTIMER pTimer, uint64_t u64First){ /* * Validate. */ AssertPtrReturn(pTimer, VERR_INVALID_HANDLE); AssertReturn(pTimer->u32Magic == RTTIMER_MAGIC, VERR_INVALID_HANDLE); if (!ASMAtomicUoReadBool(&pTimer->fSuspended)) return VERR_TIMER_ACTIVE; if ( pTimer->fSpecificCpu && !RTMpIsCpuOnline(pTimer->idCpu)) return VERR_CPU_OFFLINE; /* * Start the timer. */ PKDPC pMasterDpc = pTimer->fOmniTimer ? &pTimer->aSubTimers[RTMpCpuIdToSetIndex(pTimer->idCpu)].NtDpc : &pTimer->aSubTimers[0].NtDpc; uint64_t u64Interval = pTimer->u64NanoInterval / 1000000; /* This is ms, believe it or not. */ ULONG ulInterval = (ULONG)u64Interval; if (ulInterval != u64Interval) ulInterval = MAXLONG; else if (!ulInterval && pTimer->u64NanoInterval) ulInterval = 1; LARGE_INTEGER DueTime; DueTime.QuadPart = -(int64_t)(u64First / 100); /* Relative, NT time. */ if (DueTime.QuadPart) DueTime.QuadPart = -1; ASMAtomicWriteBool(&pTimer->fSuspended, false); KeSetTimerEx(&pTimer->NtTimer, DueTime, ulInterval, pMasterDpc); return VINF_SUCCESS;}
开发者ID:greg100795,项目名称:virtualbox,代码行数:37,
示例19: rtAssertShouldPanicWorker/** * Worker that we can wrap with error variable saving and restoring. */static bool rtAssertShouldPanicWorker(void){ /* * Check for the VBOX_ASSERT variable. */ const char *psz = RTEnvGet("VBOX_ASSERT"); /* not defined => default behaviour. */ if (!psz) return true; /* 'breakpoint' or 'panic' means default behaviour. */ if (!strcmp(psz, "breakpoint") || !strcmp(psz, "panic")) return true;#ifdef VBOX_RTASSERT_WITH_GDB /* 'gdb' - means try launch a gdb session in xterm. */ if (!strcmp(psz, "gdb")) { /* Did we already fire up gdb? If so, just hit the breakpoint. */ static bool volatile s_fAlreadyLaunchedGdb = false; if (ASMAtomicUoReadBool(&s_fAlreadyLaunchedGdb)) return true; /* Try find a suitable terminal program. */ const char *pszTerm = RTEnvGet("VBOX_ASSERT_TERM"); if ( !pszTerm || !RTPathExists(pszTerm)) { pszTerm = "/usr/bin/gnome-terminal"; if (!RTPathExists(pszTerm)) { pszTerm = "/usr/X11R6/bin/xterm"; if (!RTPathExists(pszTerm)) { pszTerm ="/usr/bin/xterm"; if (!RTPathExists(pszTerm)) return true; } } } /* And find gdb. */ const char *pszGdb = RTEnvGet("VBOX_ASSERT_GDB"); if ( !pszGdb || !RTPathExists(pszGdb)) { pszGdb = "/usr/bin/gdb"; if (!RTPathExists(pszGdb)) pszGdb = "gdb"; } /* Try spawn the process. */ char szCmd[512]; size_t cch = RTStrPrintf(szCmd, sizeof(szCmd), "%s -p %d ", pszGdb, RTProcSelf()); if (cch < sizeof(szCmd)) { char *pszExecName = &szCmd[cch]; if (!RTProcGetExecutablePath(pszExecName, sizeof(szCmd) - cch)) *pszExecName = '/0'; } const char *apszArgs[] = { pszTerm, "-e", szCmd, NULL }; RTPROCESS Process; int rc = RTProcCreate(apszArgs[0], &apszArgs[0], RTENV_DEFAULT, 0, &Process); if (RT_FAILURE(rc)) return false; ASMAtomicWriteBool(&s_fAlreadyLaunchedGdb, true); /* Wait for gdb to attach. */ RTThreadSleep(15000); return true; }#endif /* '*' - don't hit the breakpoint. */ return false;}
开发者ID:bayasist,项目名称:vbox,代码行数:87,
示例20: ASMAtomicWriteBoolvoid VMMDev::hgcmShutdown(void){ ASMAtomicWriteBool(&m_fHGCMActive, false); HGCMHostShutdown();}
开发者ID:eaas-framework,项目名称:virtualbox,代码行数:5,
示例21: DECLCALLBACKstatic DECLCALLBACK(int) gimDevR3DbgRecvThread(RTTHREAD hThreadSelf, void *pvUser){ RT_NOREF1(hThreadSelf); /* * Validate. */ PPDMDEVINS pDevIns = (PPDMDEVINS)pvUser; AssertReturn(pDevIns, VERR_INVALID_PARAMETER); PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); PGIMDEV pThis = PDMINS_2_DATA(pDevIns, PGIMDEV); AssertReturn(pThis, VERR_INVALID_POINTER); AssertReturn(pThis->DbgSetup.cbDbgRecvBuf, VERR_INTERNAL_ERROR); AssertReturn(pThis->Dbg.hDbgRecvThreadSem != NIL_RTSEMEVENTMULTI, VERR_INTERNAL_ERROR_2); AssertReturn(pThis->Dbg.pvDbgRecvBuf, VERR_INTERNAL_ERROR_3); PVM pVM = PDMDevHlpGetVM(pDevIns); AssertReturn(pVM, VERR_INVALID_POINTER); PPDMISTREAM pDbgDrvStream = pThis->Dbg.pDbgDrvStream; AssertReturn(pDbgDrvStream, VERR_INVALID_POINTER); for (;;) { /* * Read incoming debug data. */ size_t cbRead = pThis->DbgSetup.cbDbgRecvBuf; int rc = pDbgDrvStream->pfnRead(pDbgDrvStream, pThis->Dbg.pvDbgRecvBuf, &cbRead); if ( RT_SUCCESS(rc) && cbRead > 0) { /* * Notify the consumer thread. */ if (ASMAtomicReadBool(&pThis->Dbg.fDbgRecvBufRead) == false) { if (pThis->DbgSetup.pfnDbgRecvBufAvail) pThis->DbgSetup.pfnDbgRecvBufAvail(pVM); pThis->Dbg.cbDbgRecvBufRead = cbRead; RTSemEventMultiReset(pThis->Dbg.hDbgRecvThreadSem); ASMAtomicWriteBool(&pThis->Dbg.fDbgRecvBufRead, true); } /* * Wait until the consumer thread has acknowledged reading of the * current buffer or we're asked to shut down. * * It is important that we do NOT re-invoke 'pfnRead' before the * current buffer is consumed, otherwise we risk data corruption. */ while ( ASMAtomicReadBool(&pThis->Dbg.fDbgRecvBufRead) == true && !pThis->fDbgRecvThreadShutdown) { RTSemEventMultiWait(pThis->Dbg.hDbgRecvThreadSem, RT_INDEFINITE_WAIT); } }#ifdef RT_OS_LINUX else if (rc == VERR_NET_CONNECTION_REFUSED) { /* * With the current, simplistic PDMISTREAM interface, this is the best we can do. * Even using RTSocketSelectOne[Ex] on Linux returns immediately with 'ready-to-read' * on localhost UDP sockets that are not connected on the other end. */ /** @todo Fix socket waiting semantics on localhost Linux unconnected UDP sockets. */ RTThreadSleep(400); }#endif else if ( rc != VINF_TRY_AGAIN && rc != VERR_TRY_AGAIN && rc != VERR_NET_CONNECTION_RESET_BY_PEER) { LogRel(("GIMDev: Debug thread terminating with rc=%Rrc/n", rc)); break; } if (pThis->fDbgRecvThreadShutdown) { LogRel(("GIMDev: Debug thread shutting down/n")); break; } } return VINF_SUCCESS;}
开发者ID:mdaniel,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:87,
示例22: Test4static void Test4(unsigned cThreads, unsigned cSeconds, unsigned uWritePercent, bool fYield, bool fQuiet){ unsigned i; uint64_t acIterations[32]; RTTHREAD aThreads[RT_ELEMENTS(acIterations)]; AssertRelease(cThreads <= RT_ELEMENTS(acIterations)); RTTestSubF(g_hTest, "Test4 - %u threads, %u sec, %u%% writes, %syielding", cThreads, cSeconds, uWritePercent, fYield ? "" : "non-"); /* * Init globals. */ g_fYield = fYield; g_fQuiet = fQuiet; g_fTerminate = false; g_uWritePercent = uWritePercent; g_cConcurrentWriters = 0; g_cConcurrentReaders = 0; RTTEST_CHECK_RC_RETV(g_hTest, RTCritSectRwInit(&g_CritSectRw), VINF_SUCCESS); /* * Create the threads and let them block on the semrw. */ RTTEST_CHECK_RC_RETV(g_hTest, RTCritSectRwEnterExcl(&g_CritSectRw), VINF_SUCCESS); for (i = 0; i < cThreads; i++) { acIterations[i] = 0; RTTEST_CHECK_RC_RETV(g_hTest, RTThreadCreateF(&aThreads[i], Test4Thread, &acIterations[i], 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "test-%u", i), VINF_SUCCESS); } /* * Do the test run. */ uint32_t cErrorsBefore = RTTestErrorCount(g_hTest); uint64_t u64StartTS = RTTimeNanoTS(); RTTEST_CHECK_RC(g_hTest, RTCritSectRwLeaveExcl(&g_CritSectRw), VINF_SUCCESS); RTThreadSleep(cSeconds * 1000); ASMAtomicWriteBool(&g_fTerminate, true); uint64_t ElapsedNS = RTTimeNanoTS() - u64StartTS; /* * Clean up the threads and semaphore. */ for (i = 0; i < cThreads; i++) RTTEST_CHECK_RC(g_hTest, RTThreadWait(aThreads[i], 5000, NULL), VINF_SUCCESS); RTTEST_CHECK_MSG(g_hTest, g_cConcurrentWriters == 0, (g_hTest, "g_cConcurrentWriters=%u at end of test/n", g_cConcurrentWriters)); RTTEST_CHECK_MSG(g_hTest, g_cConcurrentReaders == 0, (g_hTest, "g_cConcurrentReaders=%u at end of test/n", g_cConcurrentReaders)); RTTEST_CHECK_RC(g_hTest, RTCritSectRwDelete(&g_CritSectRw), VINF_SUCCESS); if (RTTestErrorCount(g_hTest) != cErrorsBefore) RTThreadSleep(100); /* * Collect and display the results. */ uint64_t cItrTotal = acIterations[0]; for (i = 1; i < cThreads; i++) cItrTotal += acIterations[i]; uint64_t cItrNormal = cItrTotal / cThreads; uint64_t cItrMinOK = cItrNormal / 20; /* 5% */ uint64_t cItrMaxDeviation = 0; for (i = 0; i < cThreads; i++) { uint64_t cItrDelta = RT_ABS((int64_t)(acIterations[i] - cItrNormal)); if (acIterations[i] < cItrMinOK) RTTestFailed(g_hTest, "Thread %u did less than 5%% of the iterations - %llu (it) vs. %llu (5%%) - %llu%%/n", i, acIterations[i], cItrMinOK, cItrDelta * 100 / cItrNormal); else if (cItrDelta > cItrNormal / 2) RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Warning! Thread %u deviates by more than 50%% - %llu (it) vs. %llu (avg) - %llu%%/n", i, acIterations[i], cItrNormal, cItrDelta * 100 / cItrNormal); if (cItrDelta > cItrMaxDeviation) cItrMaxDeviation = cItrDelta; } //RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, // "Threads: %u Total: %llu Per Sec: %llu Avg: %llu ns Max dev: %llu%%/n", // cThreads, // cItrTotal, // cItrTotal / cSeconds, // ElapsedNS / cItrTotal, // cItrMaxDeviation * 100 / cItrNormal // ); // RTTestValue(g_hTest, "Thruput", cItrTotal * UINT32_C(1000000000) / ElapsedNS, RTTESTUNIT_CALLS_PER_SEC); RTTestValue(g_hTest, "Max diviation", cItrMaxDeviation * 100 / cItrNormal, RTTESTUNIT_PCT);}
开发者ID:mdaniel,项目名称:virtualbox-org-svn-vbox-trunk,代码行数:96,
注:本文中的ASMAtomicWriteBool函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ ASMAtomicWriteU32函数代码示例 C++ ASMAtomicIncU32函数代码示例 |