VirtualBox

Changeset 47572 in vbox


Ignore:
Timestamp:
Aug 7, 2013 9:51:45 AM (12 years ago)
Author:
vboxsync
Message:

Runtime/threadctxhooks: RTThreadCtxHooksAreRegistered().

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/mangling.h

    r47516 r47572  
    15921592# define RTThreadCreateF                                RT_MANGLER(RTThreadCreateF)
    15931593# define RTThreadCreateV                                RT_MANGLER(RTThreadCreateV)
     1594# define RTThreadCtxHooksAreRegistered                  RT_MANGLER(RTThreadCtxHooksAreRegistered)  /* r0drv */
    15941595# define RTThreadCtxHooksCreate                         RT_MANGLER(RTThreadCtxHooksCreate)         /* r0drv */
    15951596# define RTThreadCtxHooksDeregister                     RT_MANGLER(RTThreadCtxHooksDeregister)     /* r0drv */
  • trunk/include/iprt/thread.h

    r47370 r47572  
    637637 *
    638638 * @returns New reference count.
    639  * @retval  0 if the thread-context hook was freed or the handle was
     639 * @retval  0 if the thread-context hook was freed or @a hThreadCtx is
    640640 *          NIL_RTTHREADCTX.
    641641 * @retval  UINT32_MAX is returned if the handle is invalid (asserted).
    642642 *
    643  * @param   phThreadCtx         Pointer to the thread-context handle (can be
    644  *                              NIL_RTTHREADCTX).
     643 * @param   hThreadCtx          The thread-context handle.
    645644 *
    646645 * @remarks This can be called from any thread but must be called with
     
    654653 *
    655654 * @returns IPRT status code.
    656  * @param   phThreadCtx         Poinner to the thread-context handle.
     655 * @param   hThreadCtx          The thread-context handle.
    657656 * @param   pfnThreadHook       Pointer to a thread-context hook (a callback)
    658657 *                              for all thread-context events.
     
    667666 *
    668667 * @returns IPRT status code.
    669  * @param   phThreadCtx         Pointer to the thread-context handle.
     668 * @param   hThreadCtx          The thread-context handle.
    670669 *
    671670 * @remarks Can be called with preemption disabled.
    672671 */
    673672RTDECL(int) RTThreadCtxHooksDeregister(RTTHREADCTX hThreadCtx);
     673
     674/**
     675 * Are thread-context hooks registered for the thread?
     676 *
     677 * @returns true if registered, false if not supported or not registered.
     678 * @param   hThreadCtx          The thread-context handle.
     679 *
     680 * @remarks Can be called from any thread (but possibility of races when
     681 *          it's not the current thread!)
     682 */
     683RTDECL(bool) RTThreadCtxHooksAreRegistered(RTTHREADCTX hThreadCtx);
    674684
    675685# endif /* IN_RING0 */
  • trunk/src/VBox/HostDrivers/Support/SUPDrv.c

    r47542 r47572  
    367367    { "RTStrPrintfV",                           (void *)RTStrPrintfV },
    368368    { "RTThreadCreate",                         (void *)RTThreadCreate },
     369    { "RTThreadCtxHooksAreRegistered",          (void *)RTThreadCtxHooksAreRegistered },
    369370    { "RTThreadCtxHooksCreate",                 (void *)RTThreadCtxHooksCreate },
    370371    { "RTThreadCtxHooksDeregister",             (void *)RTThreadCtxHooksDeregister },
  • trunk/src/VBox/Runtime/r0drv/generic/threadctxhooks-r0drv-generic.cpp

    r47352 r47572  
    7575RT_EXPORT_SYMBOL(RTThreadCtxHooksDeregister);
    7676
     77
     78RTDECL(bool) RTThreadCtxHooksAreRegistered(RTTHREADCTX hThreadCtx)
     79{
     80    NOREF(hThreadCtx);
     81    return false;
     82}
     83RT_EXPORT_SYMBOL(RTThreadCtxHooksAreRegistered);
     84
  • trunk/src/VBox/Runtime/r0drv/linux/threadctxhooks-r0drv-linux.c

    r47375 r47572  
    212212    PRTTHREADCTXINT pThis = hThreadCtx;
    213213    if (pThis == NIL_RTTHREADCTX)
    214         return VINF_SUCCESS;
     214        return VERR_INVALID_HANDLE;
    215215    AssertPtr(pThis);
    216216    AssertMsgReturn(pThis->u32Magic == RTTHREADCTXINT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis),
     
    242242    PRTTHREADCTXINT pThis = hThreadCtx;
    243243    if (pThis == NIL_RTTHREADCTX)
    244         return VINF_SUCCESS;
     244        return VERR_INVALID_HANDLE;
    245245    AssertPtr(pThis);
    246246    AssertMsgReturn(pThis->u32Magic == RTTHREADCTXINT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis),
     
    257257RT_EXPORT_SYMBOL(RTThreadCtxHooksDeregister);
    258258
     259
     260RTDECL(bool) RTThreadCtxHooksAreRegistered(RTTHREADCTX hThreadCtx)
     261{
     262    /*
     263     * Validate input.
     264     */
     265    PRTTHREADCTXINT pThis = hThreadCtx;
     266    if (pThis == NIL_RTTHREADCTX)
     267        return false;
     268    AssertPtr(pThis);
     269    AssertMsg(pThis->u32Magic == RTTHREADCTXINT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis));
     270
     271    return pThis->fRegistered;
     272}
     273
    259274#else    /* Not supported / Not needed */
    260275
     
    300315RT_EXPORT_SYMBOL(RTThreadCtxHooksDeregister);
    301316
     317
     318RTDECL(bool) RTThreadCtxHooksAreRegistered(RTTHREADCTX hThreadCtx)
     319{
     320    NOREF(hThreadCtx);
     321    return false;
     322}
     323RT_EXPORT_SYMBOL(RTThreadCtxHooksAreRegistered);
     324
    302325#endif   /* Not supported / Not needed */
    303326
  • trunk/src/VBox/Runtime/r0drv/solaris/threadctxhooks-r0drv-solaris.c

    r47380 r47572  
    281281    PRTTHREADCTXINT pThis = hThreadCtx;
    282282    if (pThis == NIL_RTTHREADCTX)
    283         return VINF_SUCCESS;
     283        return VERR_INVALID_HANDLE;
    284284    AssertPtr(pThis);
    285285    AssertMsgReturn(pThis->u32Magic == RTTHREADCTXINT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis),
     
    305305    PRTTHREADCTXINT pThis = hThreadCtx;
    306306    if (pThis == NIL_RTTHREADCTX)
    307         return VINF_SUCCESS;
     307        return VERR_INVALID_HANDLE;
    308308    AssertPtr(pThis);
    309309    AssertMsgReturn(pThis->u32Magic == RTTHREADCTXINT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis),
     
    320320}
    321321
     322
     323RTDECL(bool) RTThreadCtxHooksAreRegistered(RTTHREADCTX hThreadCtx)
     324{
     325    /*
     326     * Validate input.
     327     */
     328    PRTTHREADCTXINT pThis = hThreadCtx;
     329    if (pThis == NIL_RTTHREADCTX)
     330        return false;
     331    AssertPtr(pThis);
     332    AssertMsg(pThis->u32Magic == RTTHREADCTXINT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis));
     333
     334    return pThis->fRegistered;
     335}
     336
  • trunk/src/VBox/Runtime/testcase/tstR0ThreadPreemption.cpp

    r47521 r47572  
    299299            }
    300300
     301            bool fRegistered = RTThreadCtxHooksAreRegistered(NIL_RTTHREADCTX);
     302            if (fRegistered)
     303            {
     304                RTStrPrintf(pszErr, cchErr, "!RTThreadCtxHooksAreRegistered returns true before creating any hooks");
     305                break;
     306            }
     307
    301308            RTTHREADCTX hThreadCtx;
    302309            int rc = RTThreadCtxHooksCreate(&hThreadCtx);
     
    307314                else
    308315                    RTStrPrintf(pszErr, cchErr, "!RTThreadCtxHooksCreate returns %Rrc", rc);
     316                break;
     317            }
     318
     319            fRegistered = RTThreadCtxHooksAreRegistered(hThreadCtx);
     320            if (fRegistered)
     321            {
     322                RTStrPrintf(pszErr, cchErr, "!RTThreadCtxHooksAreRegistered returns true before registering any hooks");
     323                RTThreadCtxHooksRelease(hThreadCtx);
    309324                break;
    310325            }
     
    330345            if (RT_FAILURE(rc))
    331346            {
     347                RTThreadPreemptRestore(&PreemptState);
    332348                RTMemFree(pCtxData);
    333349                RTStrPrintf(pszErr, cchErr, "!RTThreadCtxHooksRegister returns %Rrc", rc);
     
    335351            }
    336352
     353            fRegistered = RTThreadCtxHooksAreRegistered(hThreadCtx);
     354            if (!fRegistered)
     355            {
     356                RTThreadPreemptRestore(&PreemptState);
     357                RTMemFree(pCtxData);
     358                RTStrPrintf(pszErr, cchErr, "!RTThreadCtxHooksAreRegistered return false when hooks are supposedly registered");
     359                break;
     360            }
     361
    337362            RTThreadPreemptRestore(&PreemptState);
    338363
    339364            /* Check if the preempting callback has/will been invoked. */
    340             const uint32_t  cMsTimeout           = 8000;
     365            const uint32_t  cMsTimeout           = 10000;
    341366            const uint32_t  cMsSleepGranularity  = 50;
    342367            uint32_t        cMsSlept             = 0;
     368            RTCPUID         uCurrentCpuId        = NIL_RTCPUID;
    343369            for (;;)
    344370            {
    345371                RTThreadPreemptDisable(&PreemptState);
    346                 const RTCPUID uCurrentCpuId = RTMpCpuId();
     372                uCurrentCpuId = RTMpCpuId();
    347373                RTThreadPreemptRestore(&PreemptState);
    348374
     
    359385            if (!ASMAtomicReadBool(&pCtxData->fPreemptingInvoked))
    360386            {
    361                 RTStrPrintf(pszErr, cchErr, "!tstR0ThreadCtxHooks[RTTHREADCTXEVENT_PREEMPTING] not invoked after ca. %u ms",
    362                             cMsSlept);
     387                if (pCtxData->uSourceCpuId != uCurrentCpuId)
     388                {
     389                    RTStrPrintf(pszErr, cchErr,
     390                                "!tstR0ThreadCtxHooks[RTTHREADCTXEVENT_PREEMPTING] not invoked before migrating from CPU %RU32 to %RU32",
     391                                pCtxData->uSourceCpuId, uCurrentCpuId);
     392                }
     393                else
     394                {
     395                    RTStrPrintf(pszErr, cchErr, "!tstR0ThreadCtxHooks[RTTHREADCTXEVENT_PREEMPTING] not invoked after ca. %u ms",
     396                                cMsSlept);
     397                }
    363398            }
    364399            else if (!pCtxData->fPreemptingSuccess)
     
    391426            RTThreadCtxHooksDeregister(hThreadCtx);
    392427
     428            fRegistered = RTThreadCtxHooksAreRegistered(hThreadCtx);
     429            if (fRegistered)
     430            {
     431                RTMemFree(pCtxData);
     432                RTStrPrintf(pszErr, cchErr, "!RTThreadCtxHooksAreRegistered return true when hooks are deregistered");
     433                break;
     434            }
     435
    393436            Assert(RTThreadPreemptIsEnabled(NIL_RTTHREAD));
    394437            uint32_t cRefs = RTThreadCtxHooksRelease(hThreadCtx);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette