VirtualBox

Changeset 55863 in vbox for trunk/include/iprt


Ignore:
Timestamp:
May 14, 2015 6:29:34 PM (10 years ago)
Author:
vboxsync
Message:

IPRT,SUPDrv,VMM: Revised the context switching hook interface. Do less work when enabling the hook (formerly 'registration'). Drop the reference counting (kept internally for solaris) as it complicates restrictions wrt destroying enabled hooks. Bumped support driver version.

Location:
trunk/include/iprt
Files:
3 edited

Legend:

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

    r55584 r55863  
    16821682# define RTThreadCreateF                                RT_MANGLER(RTThreadCreateF)
    16831683# define RTThreadCreateV                                RT_MANGLER(RTThreadCreateV)
    1684 # define RTThreadCtxHooksAreRegistered                  RT_MANGLER(RTThreadCtxHooksAreRegistered)  /* r0drv */
    1685 # define RTThreadCtxHooksCreate                         RT_MANGLER(RTThreadCtxHooksCreate)         /* r0drv */
    1686 # define RTThreadCtxHooksDeregister                     RT_MANGLER(RTThreadCtxHooksDeregister)     /* r0drv */
    1687 # define RTThreadCtxHooksRegister                       RT_MANGLER(RTThreadCtxHooksRegister)       /* r0drv */
    1688 # define RTThreadCtxHooksRelease                        RT_MANGLER(RTThreadCtxHooksRelease)        /* r0drv */
    1689 # define RTThreadCtxHooksRetain                         RT_MANGLER(RTThreadCtxHooksRetain)         /* r0drv */
     1684# define RTThreadCtxHookIsEnabled                       RT_MANGLER(RTThreadCtxHookIsEnabled)    /* r0drv */
     1685# define RTThreadCtxHookCreate                          RT_MANGLER(RTThreadCtxHookCreate)       /* r0drv */
     1686# define RTThreadCtxHookDestroy                         RT_MANGLER(RTThreadCtxHookDestroy)      /* r0drv */
     1687# define RTThreadCtxHookDisable                         RT_MANGLER(RTThreadCtxHookDisable)      /* r0drv */
     1688# define RTThreadCtxHookEnable                          RT_MANGLER(RTThreadCtxHookEnable)       /* r0drv */
    16901689# define RTThreadFromNative                             RT_MANGLER(RTThreadFromNative)
    16911690# define RTThreadGetAffinity                            RT_MANGLER(RTThreadGetAffinity)
  • trunk/include/iprt/thread.h

    r55386 r55863  
    588588
    589589/**
    590  * Thread-context events.
     590 * Thread context swithcing events.
    591591 */
    592592typedef enum RTTHREADCTXEVENT
    593593{
    594     /** This thread is about to be preempted. */
    595     RTTHREADCTXEVENT_PREEMPTING = 0,
    596     /** This thread has just been resumed. */
    597     RTTHREADCTXEVENT_RESUMED,
     594    /** This thread is being scheduled out on the current CPU (includes preemption,
     595     * waiting, sleep and whatever else may trigger scheduling). */
     596    RTTHREADCTXEVENT_OUT = 0,
     597    /** This thread is being scheduled in on the current CPU and will resume
     598     * execution. */
     599    RTTHREADCTXEVENT_IN,
    598600    /** The usual 32-bit size hack. */
    599601    RTTHREADCTXEVENT_32BIT_HACK = 0x7fffffff
     
    601603
    602604/**
    603  * Thread-context hook.
    604  *
    605  * @returns IPRT status code.
    606  * @param   enmEvent    The thread-context event.
     605 * Thread context switching hook callback.
     606 *
     607 * This hook function is called when a thread is scheduled and preempted.  Check
     608 * @a enmEvent to see which it is.  Since the function is being called from
     609 * hooks inside the scheduler, it is limited what you can do from this function.
     610 * Do NOT acquire locks, sleep or yield the thread for instance.  IRQ safe
     611 * spinlocks are fine though.
     612 *
     613 * @returns IPRT status code.
     614 * @param   enmEvent    The thread-context event.  Please quitely ignore unknown
     615 *                      events, we may add more (thread exit, ++) later.
    607616 * @param   pvUser      User argument.
    608  *
    609  * @remarks This function may be called under different contexts, i.e. with
    610  *          different locks held, with/without preemption disabled depending on
    611  *          the event in @a enmEvent.
    612617 */
    613618typedef DECLCALLBACK(void) FNRTTHREADCTXHOOK(RTTHREADCTXEVENT enmEvent, void *pvUser);
    614 /** Pointer to a thread-context hook. */
     619/** Pointer to a context switching hook. */
    615620typedef FNRTTHREADCTXHOOK *PFNRTTHREADCTXHOOK;
    616621
    617622/**
    618  * Initializes a thread-context hook for the current thread.
    619  *
    620  * This must be called once per-thread before using RTThreadCtxHooksRegister().
    621  *
    622  * @returns IPRT status code.
    623  * @param   phThreadCtx         Where to store the thread-context handle.
    624  *
    625  * @remarks This must be called with preemption enabled!
    626  */
    627 RTDECL(int) RTThreadCtxHooksCreate(PRTTHREADCTX phThreadCtx);
    628 
    629 /**
    630  * Retains a new reference to a thread-context hook.
    631  *
    632  * @returns New reference count.
    633  *          UINT32_MAX is returned if the handle is invalid (asserted).
    634  * @param   phThreadCtx         Pointer to the thread-context handle.
    635  *
    636  * @remarks This can be called from any thread. Can be called with preemption
    637  *          disabled.
    638  */
    639 RTDECL(uint32_t) RTThreadCtxHooksRetain(RTTHREADCTX hThreadCtx);
    640 
    641 /**
    642  * Releases a reference to a thread-context hook.
    643  *
    644  * @returns New reference count.
    645  * @retval  0 if the thread-context hook was freed or @a hThreadCtx is
    646  *          NIL_RTTHREADCTX.
    647  * @retval  UINT32_MAX is returned if the handle is invalid (asserted).
    648  *
    649  * @param   hThreadCtx          The thread-context handle.
    650  *
    651  * @remarks This can be called from any thread but must be called with
    652  *          preemption enabled!
    653  */
    654 RTDECL(uint32_t) RTThreadCtxHooksRelease(RTTHREADCTX hThreadCtx);
    655 
    656 /**
    657  * Registers a thread-context hook for the current thread to receive
    658  * notifications for all supported thread-context events.
    659  *
    660  * @returns IPRT status code.
    661  * @param   hThreadCtx          The thread-context handle.
    662  * @param   pfnThreadHook       Pointer to a thread-context hook (a callback)
    663  *                              for all thread-context events.
    664  * @param   pvUser              User argument (optional, can be NULL).
    665  *
    666  * @remarks Can be called with preemption disabled.
    667  */
    668 RTDECL(int) RTThreadCtxHooksRegister(RTTHREADCTX hThreadCtx, PFNRTTHREADCTXHOOK pfnThreadHook, void *pvUser);
    669 
    670 /**
    671  * Deregisters the thread-context hook for the current thread.
    672  *
    673  * @returns IPRT status code.
    674  * @param   hThreadCtx          The thread-context handle.
    675  *
    676  * @remarks Can be called with preemption disabled.
    677  */
    678 RTDECL(int) RTThreadCtxHooksDeregister(RTTHREADCTX hThreadCtx);
    679 
    680 /**
    681  * Are thread-context hooks registered for the thread?
     623 * Initializes a thread context switching hook for the current thread.
     624 *
     625 * The hook is created as disabled, use RTThreadCtxHookEnable to enable it.
     626 *
     627 * @returns IPRT status code.
     628 * @param   phCtxHook       Where to store the hook handle.
     629 * @param   fFlags          Reserved for future extensions, must be zero.
     630 * @param   pfnCallback     Pointer to a the hook function (callback) that
     631 *                          should be called for all context switching events
     632 *                          involving the current thread.
     633 * @param   pvUser          User argument that will be passed to @a pfnCallback.
     634 * @remarks Preemption must be enabled.
     635 */
     636RTDECL(int) RTThreadCtxHookCreate(PRTTHREADCTXHOOK phCtxHook, uint32_t fFlags, PFNRTTHREADCTXHOOK pfnCallback, void *pvUser);
     637
     638/**
     639 * Destroys a thread context switching hook.
     640 *
     641 * Caller must make sure the hook is disabled before the final reference is
     642 * released.  Recommended to call this on the owning thread, otherwise the
     643 * memory backing it may on some systems only be released when the thread
     644 * terminates.
     645 *
     646 * @returns IPRT status code.
     647 *
     648 * @param   hCtxHook        The context hook handle.  NIL_RTTHREADCTXHOOK is
     649 *                          ignored and the function will return VINF_SUCCESS.
     650 * @remarks Preemption must be enabled.
     651 * @remarks Do not call from FNRTTHREADCTXHOOK.
     652 */
     653RTDECL(int) RTThreadCtxHookDestroy(RTTHREADCTXHOOK hCtxHook);
     654
     655/**
     656 * Enables the context switching hooks for the current thread.
     657 *
     658 * @returns IPRT status code.
     659 * @param   hCtxHook        The context hook handle.
     660 * @remarks Should be called with preemption disabled.
     661 */
     662RTDECL(int) RTThreadCtxHookEnable(RTTHREADCTXHOOK hCtxHook);
     663
     664/**
     665 * Disables the thread context switching hook for the current thread.
     666 *
     667 * Will not assert or fail if called twice or with a NIL handle.
     668 *
     669 * @returns IPRT status code.
     670 * @param   hCtxHook        The context hook handle. NIL_RTTHREADCTXHOOK is
     671 *                          ignored and the function wil return VINF_SUCCESS.
     672 * @remarks Should be called with preemption disabled.
     673 * @remarks Do not call from FNRTTHREADCTXHOOK.
     674 */
     675RTDECL(int) RTThreadCtxHookDisable(RTTHREADCTXHOOK hCtxHook);
     676
     677/**
     678 * Is the thread context switching hook enabled?
    682679 *
    683680 * @returns true if registered, false if not supported or not registered.
    684  * @param   hThreadCtx          The thread-context handle.
    685  *
    686  * @remarks Can be called from any thread (but possibility of races when
    687  *          it's not the current thread!)
    688  */
    689 RTDECL(bool) RTThreadCtxHooksAreRegistered(RTTHREADCTX hThreadCtx);
     681 * @param   hCtxHook        The context hook handle.   NIL_RTTHREADCTXHOOK is
     682 *                          ignored and the function will return false.
     683 *
     684 * @remarks Can be called from any thread, though is naturally subject to races
     685 *          when not called from the thread associated with the hook.
     686 */
     687RTDECL(bool) RTThreadCtxHookIsEnabled(RTTHREADCTXHOOK hCtxHook);
    690688
    691689# endif /* IN_RING0 */
  • trunk/include/iprt/types.h

    r53615 r55863  
    17631763#define NIL_RTTHREAD                                0
    17641764
    1765 /** Thread-context handle.*/
    1766 typedef R0PTRTYPE(struct RTTHREADCTXINT *)          RTTHREADCTX;
    1767 /** Pointer to thread handle. */
    1768 typedef RTTHREADCTX                                *PRTTHREADCTX;
    1769 /** Nil thread-context handle. */
    1770 #define NIL_RTTHREADCTX                             0
     1765/** Thread context switching hook handle.   */
     1766typedef R0PTRTYPE(struct RTTHREADCTXHOOKINT *)      RTTHREADCTXHOOK;
     1767/** Pointer to Thread context switching hook handle. */
     1768typedef RTTHREADCTXHOOK                            *PRTTHREADCTXHOOK;
     1769/** Nil Thread context switching hook handle. */
     1770#define NIL_RTTHREADCTXHOOK                         ((RTTHREADCTXHOOK)0)
    17711771
    17721772/** A TLS index. */
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