ark::pipeline::AbstractTimer

Defined in header “ark/pipeline/abstract_timer.hh”.


A timer interface is used by the executors to understand when to fire an event next. This allows you to deterministically execute and trigger events.

Typedefs

  • using ReadyCallbackFunction = std::function< void()>
    The definition of the ready callback function pointer.

Methods

  • ~AbstractTimer()
    Virtual destructor, for cleanup.

  • void reset_to_time(const std::chrono::steady_clock::time_point & time)
    Resets the timer to the given timestamp. No executions will occur, and future ticks/elapsed calls will be relative to this timestamp. All elapsed time will be erased.

  • bool tick(const std::chrono::steady_clock::time_point & now)
    Called periodically with the current clock (virtual or otherwise). This will register the times that a timer should execute, so that downstream code can take care of executing them.

    Returns true if execute() will need to be invoked, false otherwise.

  • size_t queue_size()
    Returns the number of executions remaining (the number of times you can invoke execute()).

  • bool pop(TimerWorkItem & item)
    Pops the oldest execution off the queue and returns a work item. This is the first phase of execution, allowing you to deterministically pop an execution time off the timer, and execute it in a background thread.

    Returns true if the pop was successful, false if the queue is empty.

  • void execute_work_item(TimerWorkItem && item)
    The second half of timer execution. Consumes the given timer work item as received from pop(), taking ownership of it, and then invokes the callback.

  • bool execute()
    Pops the oldest execution off the queue and executes the callback against it. Returns true if something was executed, or false otherwise.

  • std::chrono::nanoseconds time_remaining(const std::chrono::steady_clock::time_point & now)
    Returns the amount of time left before the next execution, based on the given timestamp.

  • TimerStatistics statistics()
    Returns statistics related to this timer.

  • TimerCallbackTimings timings()
    Returns timing information related to this timer’s callback. Resets the timing information after this call (so the maximums are reset). This API is meant to be called periodically to determine the max timing information over some period of time.

  • std::chrono::nanoseconds configured_expected_runtime()
    Returns the configured execution time for this timer.

  • std::chrono::nanoseconds expected_runtime(const TimerWorkItem & item)
    Returns the expected runtime as if this timer had executed the given work item.

  • std::string name()
    Returns the human-readable name assigned to the timer.

  • void set_ready_callback(ReadyCallbackFunction function)
    Installs a callback that will be notified when the timer is ready to execute.

  • void shutdown()
    Shuts down the timer, clearing internal state. This is necessary to avoid leaks/loops in resources in captured callbacks.