|
xorp
|
A class for computing whether some processing is taking too long. More...
#include <time_slice.hh>
Public Member Functions | |
| TimeSlice (uint32_t usec_limit, size_t test_iter_frequency) | |
| Constructor for a given time limit and test frequency. | |
| void | reset () |
| Reset the TimeSlice object. | |
| bool | is_expired () |
| Test if the time slice has expired. | |
Private Attributes | |
| TimeVal | _time_slice_limit |
| const size_t | _test_iter_frequency |
| TimeVal | _time_slice_start |
| size_t | _remain_iter |
A class for computing whether some processing is taking too long.
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.
return;
}
// Do something CPU-hungry
}
time_slice.reset(); // Prepare it again for later usage if needed
| TimeSlice::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.
| bool TimeSlice::is_expired | ( | ) | [inline] |