本文整理汇总了C++中RTThreadSelf函数的典型用法代码示例。如果您正苦于以下问题:C++ RTThreadSelf函数的具体用法?C++ RTThreadSelf怎么用?C++ RTThreadSelf使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTThreadSelf函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RTDECL
/**
* Unblocks a thread.
*
* This function is paired with rtThreadBlocking.
*
* @param hThread The current thread.
* @param enmCurState The current state, used to check for nested blocking.
* The new state will be running.
*/
RTDECL(void) RTThreadUnblocked(RTTHREAD hThread, RTTHREADSTATE enmCurState)
{
PRTTHREADINT pThread = hThread;
if (pThread != NIL_RTTHREAD)
{
Assert(pThread == RTThreadSelf());
ASMAtomicWriteBool(&pThread->fReallySleeping, false);
RTTHREADSTATE enmActualState = rtThreadGetState(pThread);
if (enmActualState == enmCurState)
{
rtThreadSetState(pThread, RTTHREADSTATE_RUNNING);
if ( pThread->LockValidator.pRec
&& pThread->LockValidator.enmRecState == enmCurState)
ASMAtomicWriteNullPtr(&pThread->LockValidator.pRec);
}
/* This is a bit ugly... :-/ */
else if ( ( enmActualState == RTTHREADSTATE_TERMINATED
|| enmActualState == RTTHREADSTATE_INITIALIZING)
&& pThread->LockValidator.pRec)
ASMAtomicWriteNullPtr(&pThread->LockValidator.pRec);
Assert( pThread->LockValidator.pRec == NULL
|| RTTHREAD_IS_SLEEPING(enmActualState));
}
}
示例2: Assert
/* static */
int NativeEventQueue::init()
{
Assert(sMainQueue == NULL);
Assert(RTThreadIsMain(RTThreadSelf()));
try
{
sMainQueue = new NativeEventQueue();
AssertPtr(sMainQueue);
#ifdef VBOX_WITH_XPCOM
/* Check that it actually is the main event queue, i.e. that
we're called on the right thread. */
nsCOMPtr<nsIEventQueue> q;
nsresult rv = NS_GetMainEventQ(getter_AddRefs(q));
AssertComRCReturn(rv, VERR_INVALID_POINTER);
Assert(q == sMainQueue->mEventQ);
/* Check that it's a native queue. */
PRBool fIsNative = PR_FALSE;
rv = sMainQueue->mEventQ->IsQueueNative(&fIsNative);
Assert(NS_SUCCEEDED(rv) && fIsNative);
#endif // VBOX_WITH_XPCOM
}
catch (std::bad_alloc &ba)
{
NOREF(ba);
return VERR_NO_MEMORY;
}
return VINF_SUCCESS;
}
示例3: VMMR3DECL
/**
* Called by the PDM thread in response to a wakeup call with
* suspending as the new state.
*
* The thread will block in side this call until the state is changed in
* response to a VM state change or to the device/driver/whatever calling the
* PDMR3ThreadResume API.
*
* @returns VBox status code.
* On failure, terminate the thread.
* @param pThread The PDM thread.
*/
VMMR3DECL(int) PDMR3ThreadIAmSuspending(PPDMTHREAD pThread)
{
/*
* Assert sanity.
*/
AssertPtr(pThread);
AssertReturn(pThread->u32Version == PDMTHREAD_VERSION, VERR_INVALID_MAGIC);
Assert(pThread->Thread == RTThreadSelf() || pThread->enmState == PDMTHREADSTATE_INITIALIZING);
PDMTHREADSTATE enmState = pThread->enmState;
Assert( enmState == PDMTHREADSTATE_SUSPENDING
|| enmState == PDMTHREADSTATE_INITIALIZING);
/*
* Update the state, notify the control thread (the API caller) and go to sleep.
*/
int rc = VERR_WRONG_ORDER;
if (pdmR3AtomicCmpXchgState(pThread, PDMTHREADSTATE_SUSPENDED, enmState))
{
rc = RTThreadUserSignal(pThread->Thread);
if (RT_SUCCESS(rc))
{
rc = RTSemEventMultiWait(pThread->Internal.s.BlockEvent, RT_INDEFINITE_WAIT);
if ( RT_SUCCESS(rc)
&& pThread->enmState != PDMTHREADSTATE_SUSPENDED)
return rc;
if (RT_SUCCESS(rc))
rc = VERR_PDM_THREAD_IPE_2;
}
}
AssertMsgFailed(("rc=%d enmState=%d\n", rc, pThread->enmState));
pdmR3ThreadBailMeOut(pThread);
return rc;
}
示例4: DECLINLINE
/**
* Wrapper that selects rtStrConvertCached or rtStrConvertUncached.
*
* @returns IPRT status code.
*
* @param pszInput Pointer to intput string.
* @param cchInput Size (in bytes) of input string. Excludes any
* terminators.
* @param pszInputCS Codeset of the input string.
* @param ppszOutput Pointer to pointer to output buffer if cbOutput > 0.
* If cbOutput is 0 this is where the pointer to the
* allocated buffer is stored.
* @param cbOutput Size of the passed in buffer.
* @param pszOutputCS Codeset of the input string.
* @param cFactor Input vs. output size factor.
* @param enmCacheIdx The iconv cache index.
*/
DECLINLINE(int) rtStrConvertWrapper(const char *pchInput, size_t cchInput, const char *pszInputCS,
char **ppszOutput, size_t cbOutput, const char *pszOutputCS,
unsigned cFactor, RTSTRICONV enmCacheIdx)
{
#ifdef RT_WITH_ICONV_CACHE
RTTHREAD hSelf = RTThreadSelf();
if (hSelf != NIL_RTTHREAD)
{
PRTTHREADINT pThread = rtThreadGet(hSelf);
if (pThread)
{
if ((pThread->fIntFlags & (RTTHREADINT_FLAGS_ALIEN | RTTHREADINT_FLAGS_MAIN)) != RTTHREADINT_FLAGS_ALIEN)
{
int rc = rtstrConvertCached(pchInput, cchInput, pszInputCS,
(void **)ppszOutput, cbOutput, pszOutputCS,
cFactor, (iconv_t *)&pThread->ahIconvs[enmCacheIdx]);
rtThreadRelease(pThread);
return rc;
}
rtThreadRelease(pThread);
}
}
#endif
return rtStrConvertUncached(pchInput, cchInput, pszInputCS,
(void **)ppszOutput, cbOutput, pszOutputCS,
cFactor);
}
示例5: rtSemEventMultiPosixWaitIndefinite
/**
* Implements the indefinite wait.
*
* @returns See RTSemEventMultiWaitEx.
* @param pThis The semaphore.
* @param fFlags See RTSemEventMultiWaitEx.
* @param pSrcPos The source position, can be NULL.
*/
static int rtSemEventMultiPosixWaitIndefinite(struct RTSEMEVENTMULTIINTERNAL *pThis, uint32_t fFlags, PCRTLOCKVALSRCPOS pSrcPos)
{
/* take mutex */
int rc = pthread_mutex_lock(&pThis->Mutex);
AssertMsgReturn(!rc, ("Failed to lock event multi sem %p, rc=%d.\n", pThis, rc), RTErrConvertFromErrno(rc));
ASMAtomicIncU32(&pThis->cWaiters);
for (;;)
{
/* check state. */
uint32_t const u32State = pThis->u32State;
if (u32State != EVENTMULTI_STATE_NOT_SIGNALED)
{
ASMAtomicDecU32(&pThis->cWaiters);
rc = pthread_mutex_unlock(&pThis->Mutex);
AssertMsg(!rc, ("Failed to unlock event multi sem %p, rc=%d.\n", pThis, rc));
return u32State == EVENTMULTI_STATE_SIGNALED
? VINF_SUCCESS
: VERR_SEM_DESTROYED;
}
/* wait */
#ifdef RTSEMEVENTMULTI_STRICT
RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt();
if (pThis->fEverHadSignallers)
{
rc = RTLockValidatorRecSharedCheckBlocking(&pThis->Signallers, hThreadSelf, pSrcPos, false,
RT_INDEFINITE_WAIT, RTTHREADSTATE_EVENT_MULTI, true);
if (RT_FAILURE(rc))
{
ASMAtomicDecU32(&pThis->cWaiters);
pthread_mutex_unlock(&pThis->Mutex);
return rc;
}
}
#else
RTTHREAD hThreadSelf = RTThreadSelf();
#endif
RTThreadBlocking(hThreadSelf, RTTHREADSTATE_EVENT_MULTI, true);
/** @todo interruptible wait is not implementable... */ NOREF(fFlags);
rc = pthread_cond_wait(&pThis->Cond, &pThis->Mutex);
RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_EVENT_MULTI);
if (RT_UNLIKELY(rc))
{
AssertMsgFailed(("Failed to wait on event multi sem %p, rc=%d.\n", pThis, rc));
ASMAtomicDecU32(&pThis->cWaiters);
int rc2 = pthread_mutex_unlock(&pThis->Mutex);
AssertMsg(!rc2, ("Failed to unlock event multi sem %p, rc=%d.\n", pThis, rc2));
NOREF(rc2);
return RTErrConvertFromErrno(rc);
}
}
}
示例6: pdmR3R0CritSectEnterContended
/**
* Deals with the contended case in ring-3 and ring-0.
*
* @returns VINF_SUCCESS or VERR_SEM_DESTROYED.
* @param pCritSect The critsect.
* @param hNativeSelf The native thread handle.
*/
static int pdmR3R0CritSectEnterContended(PPDMCRITSECT pCritSect, RTNATIVETHREAD hNativeSelf, PCRTLOCKVALSRCPOS pSrcPos)
{
/*
* Start waiting.
*/
if (ASMAtomicIncS32(&pCritSect->s.Core.cLockers) == 0)
return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos);
# ifdef IN_RING3
STAM_COUNTER_INC(&pCritSect->s.StatContentionR3);
# else
STAM_COUNTER_INC(&pCritSect->s.StatContentionRZLock);
# endif
/*
* The wait loop.
*/
PSUPDRVSESSION pSession = pCritSect->s.CTX_SUFF(pVM)->pSession;
SUPSEMEVENT hEvent = (SUPSEMEVENT)pCritSect->s.Core.EventSem;
# ifdef IN_RING3
# ifdef PDMCRITSECT_STRICT
RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt();
int rc2 = RTLockValidatorRecExclCheckOrder(pCritSect->s.Core.pValidatorRec, hThreadSelf, pSrcPos, RT_INDEFINITE_WAIT);
if (RT_FAILURE(rc2))
return rc2;
# else
RTTHREAD hThreadSelf = RTThreadSelf();
# endif
# endif
for (;;)
{
# ifdef PDMCRITSECT_STRICT
int rc9 = RTLockValidatorRecExclCheckBlocking(pCritSect->s.Core.pValidatorRec, hThreadSelf, pSrcPos,
!(pCritSect->s.Core.fFlags & RTCRITSECT_FLAGS_NO_NESTING),
RT_INDEFINITE_WAIT, RTTHREADSTATE_CRITSECT, true);
if (RT_FAILURE(rc9))
return rc9;
# elif defined(IN_RING3)
RTThreadBlocking(hThreadSelf, RTTHREADSTATE_CRITSECT, true);
# endif
int rc = SUPSemEventWaitNoResume(pSession, hEvent, RT_INDEFINITE_WAIT);
# ifdef IN_RING3
RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_CRITSECT);
# endif
if (RT_UNLIKELY(pCritSect->s.Core.u32Magic != RTCRITSECT_MAGIC))
return VERR_SEM_DESTROYED;
if (rc == VINF_SUCCESS)
return pdmCritSectEnterFirst(pCritSect, hNativeSelf, pSrcPos);
AssertMsg(rc == VERR_INTERRUPTED, ("rc=%Rrc\n", rc));
}
/* won't get here */
}
示例7: RTR3DECL
RTR3DECL(int) RTTlsSet(RTTLS iTls, void *pvValue)
{
if (RT_UNLIKELY( iTls < 0
|| iTls >= RTTHREAD_TLS_ENTRIES
|| !ASMBitTest(&g_au32AllocatedBitmap[0], iTls)))
return VERR_INVALID_PARAMETER;
PRTTHREADINT pThread = rtThreadGet(RTThreadSelf());
AssertReturn(pThread, VERR_NOT_SUPPORTED);
pThread->apvTlsEntries[iTls] = pvValue;
rtThreadRelease(pThread);
return VINF_SUCCESS;
}
示例8: SYS_ARCH_DECL_PROTECT
/**
* Grab the pointer to this thread's timeouts from TLS.
*/
struct sys_timeouts *sys_arch_timeouts(void)
{
unsigned i;
#if SYS_LIGHTWEIGHT_PROT
SYS_ARCH_DECL_PROTECT(old_level);
#endif
RTTHREAD myself;
struct sys_timeouts *to = NULL;
myself = RTThreadSelf();
#if SYS_LIGHTWEIGHT_PROT
SYS_ARCH_PROTECT(old_level);
#else
RTSemEventWait(g_ThreadSem, RT_INDEFINITE_WAIT);
#endif
for (i = 0; i < g_cThreads; i++)
{
if (g_aTLS[i].tid == myself)
{
to = &g_aTLS[i].timeouts;
break;
}
}
/* Auto-adopt new threads which use lwIP as they pop up. */
if (!to)
{
unsigned id;
id = g_cThreads;
g_cThreads++;
Assert(g_cThreads <= THREADS_MAX);
g_aTLS[id].tid = myself;
to = &g_aTLS[id].timeouts;
}
#if SYS_LIGHTWEIGHT_PROT
SYS_ARCH_UNPROTECT(old_level);
#else
RTSemEventSignal(g_ThreadSem);
#endif
return to;
}
示例9: DECLCALLBACK
DECLCALLBACK(int) VBoxClipboardWorker(void *pInstance, bool volatile *pfShutdown)
{
AssertPtr(pInstance);
LogFlowFunc(("pInstance=%p\n", pInstance));
/*
* Tell the control thread that it can continue
* spawning services.
*/
RTThreadUserSignal(RTThreadSelf());
PVBOXCLIPBOARDCONTEXT pCtx = (PVBOXCLIPBOARDCONTEXT)pInstance;
AssertPtr(pCtx);
int rc;
/* The thread waits for incoming messages from the host. */
for (;;)
{
uint32_t u32Msg;
uint32_t u32Formats;
rc = VbglR3ClipboardGetHostMsg(pCtx->u32ClientID, &u32Msg, &u32Formats);
if (RT_FAILURE(rc))
{
if (rc == VERR_INTERRUPTED)
break;
LogFlowFunc(("Error getting host message, rc=%Rrc\n", rc));
if (*pfShutdown)
break;
/* Wait a bit before retrying. */
RTThreadSleep(1000);
continue;
}
else
{
LogFlowFunc(("u32Msg=%RU32, u32Formats=0x%x\n", u32Msg, u32Formats));
switch (u32Msg)
{
/** @todo r=andy: Use a \#define for WM_USER (+1). */
case VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS:
{
/* The host has announced available clipboard formats.
* Forward the information to the window, so it can later
* respond to WM_RENDERFORMAT message. */
::PostMessage(pCtx->hwnd, WM_USER, 0, u32Formats);
} break;
case VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA:
{
/* The host needs data in the specified format. */
::PostMessage(pCtx->hwnd, WM_USER + 1, 0, u32Formats);
} break;
case VBOX_SHARED_CLIPBOARD_HOST_MSG_QUIT:
{
/* The host is terminating. */
LogRel(("Clipboard: Terminating ...\n"));
ASMAtomicXchgBool(pfShutdown, true);
} break;
default:
{
LogFlowFunc(("Unsupported message from host, message=%RU32\n", u32Msg));
/* Wait a bit before retrying. */
RTThreadSleep(1000);
} break;
}
}
if (*pfShutdown)
break;
}
LogFlowFuncLeaveRC(rc);
return rc;
}
示例10: DECL_FORCE_INLINE
/**
* Internal worker for RTSemMutexRequestNoResume and it's debug companion.
*
* @returns Same as RTSEmMutexRequestNoResume
* @param hMutexSem The mutex handle.
* @param cMillies The number of milliseconds to wait.
* @param pSrcPos The source position of the caller.
*/
DECL_FORCE_INLINE(int) rtSemMutexRequestNoResume(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies, PCRTLOCKVALSRCPOS pSrcPos)
{
/*
* Validate.
*/
RTSEMMUTEXINTERNAL *pThis = hMutexSem;
AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
/*
* Check for recursive entry.
*/
RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf();
RTNATIVETHREAD hNativeOwner;
ASMAtomicReadHandle(&pThis->hNativeOwner, &hNativeOwner);
if (hNativeOwner == hNativeSelf)
{
#ifdef RTSEMMUTEX_STRICT
int rc9 = RTLockValidatorRecExclRecursion(&pThis->ValidatorRec, pSrcPos);
if (RT_FAILURE(rc9))
return rc9;
#endif
ASMAtomicIncU32(&pThis->cRecursions);
return VINF_SUCCESS;
}
/*
* Lock mutex semaphore.
*/
RTTHREAD hThreadSelf = NIL_RTTHREAD;
if (cMillies > 0)
{
#ifdef RTSEMMUTEX_STRICT
hThreadSelf = RTThreadSelfAutoAdopt();
int rc9 = RTLockValidatorRecExclCheckOrderAndBlocking(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true,
cMillies, RTTHREADSTATE_MUTEX, true);
if (RT_FAILURE(rc9))
return rc9;
#else
hThreadSelf = RTThreadSelf();
RTThreadBlocking(hThreadSelf, RTTHREADSTATE_MUTEX, true);
#endif
}
DWORD rc = WaitForSingleObjectEx(pThis->hMtx,
cMillies == RT_INDEFINITE_WAIT ? INFINITE : cMillies,
TRUE /*fAlertable*/);
RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_MUTEX);
switch (rc)
{
case WAIT_OBJECT_0:
#ifdef RTSEMMUTEX_STRICT
RTLockValidatorRecExclSetOwner(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true);
#endif
ASMAtomicWriteHandle(&pThis->hNativeOwner, hNativeSelf);
ASMAtomicWriteU32(&pThis->cRecursions, 1);
return VINF_SUCCESS;
case WAIT_TIMEOUT: return VERR_TIMEOUT;
case WAIT_IO_COMPLETION: return VERR_INTERRUPTED;
case WAIT_ABANDONED: return VERR_SEM_OWNER_DIED;
default:
AssertMsgFailed(("%u\n", rc));
case WAIT_FAILED:
{
int rc2 = RTErrConvertFromWin32(GetLastError());
AssertMsgFailed(("Wait on hMutexSem %p failed, rc=%d lasterr=%d\n", hMutexSem, rc, GetLastError()));
if (rc2 != VINF_SUCCESS)
return rc2;
AssertMsgFailed(("WaitForSingleObject(event) -> rc=%d while converted lasterr=%d\n", rc, rc2));
return VERR_INTERNAL_ERROR;
}
}
}
示例11: DECL_FORCE_INLINE
DECL_FORCE_INLINE(int) rtSemMutexRequest(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies, bool fAutoResume, PCRTLOCKVALSRCPOS pSrcPos)
{
/*
* Validate input.
*/
struct RTSEMMUTEXINTERNAL *pThis = hMutexSem;
AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
AssertReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, VERR_INVALID_HANDLE);
/*
* Check if nested request.
*/
pthread_t Self = pthread_self();
if ( pThis->Owner == Self
&& pThis->cNestings > 0)
{
#ifdef RTSEMMUTEX_STRICT
int rc9 = RTLockValidatorRecExclRecursion(&pThis->ValidatorRec, pSrcPos);
if (RT_FAILURE(rc9))
return rc9;
#endif
ASMAtomicIncU32(&pThis->cNestings);
return VINF_SUCCESS;
}
#ifdef RTSEMMUTEX_STRICT
RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt();
if (cMillies)
{
int rc9 = RTLockValidatorRecExclCheckOrder(&pThis->ValidatorRec, hThreadSelf, pSrcPos, cMillies);
if (RT_FAILURE(rc9))
return rc9;
}
#else
RTTHREAD hThreadSelf = RTThreadSelf();
#endif
/*
* Convert timeout value.
*/
struct timespec ts;
struct timespec *pTimeout = NULL;
uint64_t u64End = 0; /* shut up gcc */
if (cMillies != RT_INDEFINITE_WAIT)
{
ts.tv_sec = cMillies / 1000;
ts.tv_nsec = (cMillies % 1000) * UINT32_C(1000000);
u64End = RTTimeSystemNanoTS() + cMillies * UINT64_C(1000000);
pTimeout = &ts;
}
/*
* Lock the mutex.
* Optimize for the uncontended case (makes 1-2 ns difference).
*/
if (RT_UNLIKELY(!ASMAtomicCmpXchgS32(&pThis->iState, 1, 0)))
{
for (;;)
{
int32_t iOld = ASMAtomicXchgS32(&pThis->iState, 2);
/*
* Was the lock released in the meantime? This is unlikely (but possible)
*/
if (RT_UNLIKELY(iOld == 0))
break;
/*
* Go to sleep.
*/
if (pTimeout && ( pTimeout->tv_sec || pTimeout->tv_nsec ))
{
#ifdef RTSEMMUTEX_STRICT
int rc9 = RTLockValidatorRecExclCheckBlocking(&pThis->ValidatorRec, hThreadSelf, pSrcPos, true,
cMillies, RTTHREADSTATE_MUTEX, true);
if (RT_FAILURE(rc9))
return rc9;
#else
RTThreadBlocking(hThreadSelf, RTTHREADSTATE_MUTEX, true);
#endif
}
long rc = sys_futex(&pThis->iState, FUTEX_WAIT, 2, pTimeout, NULL, 0);
RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_MUTEX);
if (RT_UNLIKELY(pThis->u32Magic != RTSEMMUTEX_MAGIC))
return VERR_SEM_DESTROYED;
/*
* Act on the wakup code.
*/
if (rc == -ETIMEDOUT)
{
Assert(pTimeout);
return VERR_TIMEOUT;
}
if (rc == 0)
/* we'll leave the loop now unless another thread is faster */;
else if (rc == -EWOULDBLOCK)
/* retry with new value. */;
//.........这里部分代码省略.........
示例12: DECLCALLBACK
/** @copydoc VBOXSERVICE::pfnWorker */
DECLCALLBACK(int) VBoxServiceVMStatsWorker(bool volatile *pfShutdown)
{
int rc = VINF_SUCCESS;
/* Start monitoring of the stat event change event. */
rc = VbglR3CtlFilterMask(VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST, 0);
if (RT_FAILURE(rc))
{
VBoxServiceVerbose(3, "VBoxServiceVMStatsWorker: VbglR3CtlFilterMask failed with %d\n", rc);
return rc;
}
/*
* Tell the control thread that it can continue
* spawning services.
*/
RTThreadUserSignal(RTThreadSelf());
/*
* Now enter the loop retrieving runtime data continuously.
*/
for (;;)
{
uint32_t fEvents = 0;
RTMSINTERVAL cWaitMillies;
/* Check if an update interval change is pending. */
rc = VbglR3WaitEvent(VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST, 0 /* no wait */, &fEvents);
if ( RT_SUCCESS(rc)
&& (fEvents & VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST))
{
VbglR3StatQueryInterval(&gCtx.cMsStatInterval);
}
if (gCtx.cMsStatInterval)
{
VBoxServiceVMStatsReport();
cWaitMillies = gCtx.cMsStatInterval;
}
else
cWaitMillies = 3000;
/*
* Block for a while.
*
* The event semaphore takes care of ignoring interruptions and it
* allows us to implement service wakeup later.
*/
if (*pfShutdown)
break;
int rc2 = RTSemEventMultiWait(g_VMStatEvent, cWaitMillies);
if (*pfShutdown)
break;
if (rc2 != VERR_TIMEOUT && RT_FAILURE(rc2))
{
VBoxServiceError("VBoxServiceVMStatsWorker: RTSemEventMultiWait failed; rc2=%Rrc\n", rc2);
rc = rc2;
break;
}
}
/* Cancel monitoring of the stat event change event. */
rc = VbglR3CtlFilterMask(0, VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST);
if (RT_FAILURE(rc))
VBoxServiceVerbose(3, "VBoxServiceVMStatsWorker: VbglR3CtlFilterMask failed with %d\n", rc);
RTSemEventMultiDestroy(g_VMStatEvent);
g_VMStatEvent = NIL_RTSEMEVENTMULTI;
VBoxServiceVerbose(3, "VBoxStatsThread: finished statistics change request thread\n");
return 0;
}
示例13: DECLCALLBACK
/** @copydoc VBOXSERVICE::pfnWorker */
DECLCALLBACK(int) VBoxServiceCpuHotPlugWorker(bool volatile *pfShutdown)
{
/*
* Tell the control thread that it can continue spawning services.
*/
RTThreadUserSignal(RTThreadSelf());
/*
* Enable the CPU hotplug notifier.
*/
int rc = VbglR3CpuHotPlugInit();
if (RT_FAILURE(rc))
return rc;
/*
* The Work Loop.
*/
for (;;)
{
/* Wait for CPU hot plugging event. */
uint32_t idCpuCore;
uint32_t idCpuPackage;
VMMDevCpuEventType enmEventType;
rc = VbglR3CpuHotPlugWaitForEvent(&enmEventType, &idCpuCore, &idCpuPackage);
if (RT_SUCCESS(rc))
{
VBoxServiceVerbose(3, "CpuHotPlug: Event happened idCpuCore=%u idCpuPackage=%u enmEventType=%d\n",
idCpuCore, idCpuPackage, enmEventType);
switch (enmEventType)
{
case VMMDevCpuEventType_Plug:
VBoxServiceCpuHotPlugHandlePlugEvent(idCpuCore, idCpuPackage);
break;
case VMMDevCpuEventType_Unplug:
VBoxServiceCpuHotPlugHandleUnplugEvent(idCpuCore, idCpuPackage);
break;
default:
{
static uint32_t s_iErrors = 0;
if (s_iErrors++ < 10)
VBoxServiceError("CpuHotPlug: Unknown event: idCpuCore=%u idCpuPackage=%u enmEventType=%d\n",
idCpuCore, idCpuPackage, enmEventType);
break;
}
}
}
else if (rc != VERR_INTERRUPTED && rc != VERR_TRY_AGAIN)
{
VBoxServiceError("CpuHotPlug: VbglR3CpuHotPlugWaitForEvent returned %Rrc\n", rc);
break;
}
if (*pfShutdown)
break;
}
VbglR3CpuHotPlugTerm();
return rc;
}
示例14: DECLCALLBACK
/**
* @interface_method_impl{VBOXSERVICE,pfnWorker}
*/
DECLCALLBACK(int) vgsvcTimeSyncWorker(bool volatile *pfShutdown)
{
RTTIME Time;
char sz[64];
int rc = VINF_SUCCESS;
/*
* Tell the control thread that it can continue spawning services.
*/
RTThreadUserSignal(RTThreadSelf());
/*
* The Work Loop.
*/
for (;;)
{
/*
* Try get a reliable time reading.
*/
int cTries = 3;
do
{
/* query it. */
RTTIMESPEC GuestNow0, GuestNow, HostNow;
RTTimeNow(&GuestNow0);
int rc2 = VbglR3GetHostTime(&HostNow);
if (RT_FAILURE(rc2))
{
if (g_cTimeSyncErrors++ < 10)
VGSvcError("vgsvcTimeSyncWorker: VbglR3GetHostTime failed; rc2=%Rrc\n", rc2);
break;
}
RTTimeNow(&GuestNow);
/* calc latency and check if it's ok. */
RTTIMESPEC GuestElapsed = GuestNow;
RTTimeSpecSub(&GuestElapsed, &GuestNow0);
if ((uint32_t)RTTimeSpecGetMilli(&GuestElapsed) < g_TimeSyncMaxLatency)
{
/*
* Set the time once after we were restored.
* (Of course only if the drift is bigger than MinAdjust)
*/
uint32_t TimeSyncSetThreshold = g_TimeSyncSetThreshold;
if (g_fTimeSyncSetOnRestore)
{
uint64_t idNewSession = g_idTimeSyncSession;
VbglR3GetSessionId(&idNewSession);
if (idNewSession != g_idTimeSyncSession)
{
VGSvcVerbose(3, "vgsvcTimeSyncWorker: The VM session ID changed, forcing resync.\n");
TimeSyncSetThreshold = 0;
g_idTimeSyncSession = idNewSession;
}
}
/*
* Calculate the adjustment threshold and the current drift.
*/
uint32_t MinAdjust = RTTimeSpecGetMilli(&GuestElapsed) * g_TimeSyncLatencyFactor;
if (MinAdjust < g_TimeSyncMinAdjust)
MinAdjust = g_TimeSyncMinAdjust;
RTTIMESPEC Drift = HostNow;
RTTimeSpecSub(&Drift, &GuestNow);
if (RTTimeSpecGetMilli(&Drift) < 0)
MinAdjust += g_TimeSyncMinAdjust; /* extra buffer against moving time backwards. */
RTTIMESPEC AbsDrift = Drift;
RTTimeSpecAbsolute(&AbsDrift);
if (g_cVerbosity >= 3)
{
VGSvcVerbose(3, "vgsvcTimeSyncWorker: Host: %s (MinAdjust: %RU32 ms)\n",
RTTimeToString(RTTimeExplode(&Time, &HostNow), sz, sizeof(sz)), MinAdjust);
VGSvcVerbose(3, "vgsvcTimeSyncWorker: Guest: - %s => %RDtimespec drift\n",
RTTimeToString(RTTimeExplode(&Time, &GuestNow), sz, sizeof(sz)), &Drift);
}
uint32_t AbsDriftMilli = RTTimeSpecGetMilli(&AbsDrift);
if (AbsDriftMilli > MinAdjust)
{
/*
* Ok, the drift is above the threshold.
*
* Try a gradual adjustment first, if that fails or the drift is
* too big, fall back on just setting the time.
*/
if ( AbsDriftMilli > TimeSyncSetThreshold
|| g_fTimeSyncSetNext
|| !vgsvcTimeSyncAdjust(&Drift))
{
vgsvcTimeSyncCancelAdjust();
vgsvcTimeSyncSet(&Drift);
}
}
else
//.........这里部分代码省略.........