dr_set_itimer

Function dr_set_itimer 

Source
pub unsafe extern "C" fn dr_set_itimer(
    which: c_int,
    millisec: uint,
    func: Option<unsafe extern "C" fn(drcontext: *mut c_void, mcontext: *mut dr_mcontext_t)>,
) -> bool_
Expand description

Installs an interval timer in the itimer sharing group that contains the calling thread.

@param[in] which Must be one of ITIMER_REAL, ITIMER_VIRTUAL, or ITIMER_PROF @param[in] millisec The frequency of the timer, in milliseconds. Passing 0 disables the timer. @param[in] func The function that will be called each time the timer fires. It will be passed the context of the thread that received the itimer signal and its machine context, which has not been translated and so may contain raw code cache values. The function will be called from a signal handler that may have interrupted a lock holder or other critical code, so it must be careful in its operations: keep it as simple as possible, and avoid any non-reentrant actions such as lock usage. If a general timer that does not interrupt client code is required, the client should create a separate thread via dr_create_client_thread() (which is guaranteed to have a private itimer) and set the itimer there, where the callback function can perform more operations safely if that new thread never acquires locks in its normal operation.

Itimer sharing varies by kernel. Prior to 2.6.12 itimers were thread-private; after 2.6.12 they are shared across a thread group, though there could be multiple thread groups in one address space. The dr_get_itimer() function can be used to see whether a thread already has an itimer in its group to avoid re-setting an itimer set by an earlier thread. A client thread created by dr_create_client_thread() is guaranteed to not share its itimers with application threads.

The itimer will operate successfully in the presence of an application itimer of the same type.

Additional itimer signals are blocked while in our signal handler.

The return value indicates whether the timer was successfully installed (or uninstalled if 0 was passed for \p millisec).

\note Linux-only.