|
|
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 (uint32_t usec_limit, size_t test_iter_frequency)
| TimeSlice |
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.
Parameters:
usec_limit | the time slice to measure in microseconds. |
test_iter_frequency | the frequency of measuring the time slice. |
void reset ()
| reset |
Reset the TimeSlice object.
inline bool is_expired ()
| 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 possum.icir.org on Mon Mar 10 19:34:43 2003, using kdoc 2.0a54+XORP. |