class TimeSlice

A class for computing whether some processing is taking too long. More...

 Annotated List  Files  Globals  Hierarchy  Index  Top

Public Methods

Detailed Description

This class can be used to compute whether some processing is taking too long time to complete. It is up to the program that uses TimeSlice to check whether the processing is taking too long, and suspend processing of that task if necessary.

Example of usage:

    TimeSlice time_slice(100000, 20); // 100ms, test every 20th iteration
    for (size_t i = 0; i < 1000000000; i++) {
        if (time_slice.is_expired()) {
            // Stop processing.
            // Schedule a timer after 0 ms to continue processing.
            // If needed, save state to continue from here.
        // Do something CPU-hungry
    time_slice.reset(); // Prepare it again for later usage if needed

 TimeSlice (uint32_t usec_limit, size_t test_iter_frequency)


Constructor for a given time limit and test frequency.

Create a TimeSlice object that will measure time slices with given frequency of testing. The time slice is measured once in test_iter_frequency times when method is_expired() is called.


usec_limitthe time slice to measure in microseconds.
test_iter_frequencythe frequency of measuring the time slice.
void  reset ()


Reset the TimeSlice object.

bool  is_expired ()


Test if the time slice has expired.

If the time slice has expired, automatically prepare this object to start measuring again the time slice.

Returns: true if the time slice has expired, otherwise false.

Generated by: pavlin on on Wed Jan 7 19:10:36 2009, using kdoc 2.0a54+XORP.