namespace::chrono

Example Code on Github

The chrono namespace includes the following time-measurement objects.

  • Microseconds: 32-bit value for microseconds
  • ClockTime: 64-bit value for seconds and nanoseconds (clock as in CPU clock)
  • Time: 32-bit value in seconds (basically a time_t object)

The parent object for all chrono items is api::WorkObject or api::InfoObject. Both of the top level objects provide a way to insert a static delay.

//md2code:include
#include <sapi/chrono.hpp>
//md2code:main
wait(Seconds(1)); //wait for one second
wait(Milliseconds(1000)); //wait for one second
wait(Microseconds(1000000)); //wait for one second

ClockTime clock_time;
wait(clock_time); //wait based on a clock time value

Microseconds microseconds;
microseconds = Milliseconds(100);
wait(microseconds); //wait based on a microsecond value

Details

void wait(

const chrono::Microseconds & microseconds
)

Delays based on a chrono::Microseconds value.

//md2code:main

wait(Microseconds(100));

//Milliseconds, Seconds, and Nanoseconds will convert to Microseconds automatically
wait(Seconds(3));
wait(Milliseconds(3000));
wait(Nanoseconds(60000));
wait(Nanoseconds(999)); //this won't wait because it converts to 0 microseconds

This method will yield control of the processor to another thread. So the delay time may go over based on scheduling constraints.


typedef u32 micro_time_t

Defines the type for a chrono::MicroTime value.


typedef Microseconds MicroTime

typedef class Timer MicroTimer

X

Thanks for Coming!

Subscribe to news and updates