Beispiel #1
0
void timer::calibrate ()
{
    // It is average approximation for duration of
    // the minimum measured time interval.

    #ifdef _ARAGELI_WIN_PERFORMANCE_TIMER
        if(!QueryPerformanceFrequency(&freq))
            throw time_source_isnot_available();
    #endif

    const int ncalibs = 10;  // number of calibration runs
    ARAGELI_ASSERT_1(ncalibs >= 1);

    tick_type curclock = kernel_time();

    // Pass the first partial period.
    while(curclock == kernel_time());

    tick_type startclock = curclock;    // mark start of interval

    // Pass ncalibs whole periods.
    for(int i = 0; i < ncalibs; ++i)
    {
        tick_type prevclock = curclock;

        // Wait actively for changing of kernel_time returned value.
        do
        {
            curclock = kernel_time();
            ARAGELI_ASSERT_1(curclock != -1);
        }while(curclock == prevclock);

        ARAGELI_ASSERT_1(curclock > prevclock);
    }

    delta = (kernel_time() - startclock)/ncalibs + 1;    // +1 is for the upper estimate

    #ifdef _ARAGELI_WIN_PERFORMANCE_TIMER
        sdelta = double(delta)/freq.QuadPart;
    #else
        sdelta = double(delta)/CLOCKS_PER_SEC;
    #endif
}
Beispiel #2
0
void demo_main(void* arg)
{
	debug("demo thread start.\r\n");
	debug("thread pid=%p, arg=%p\r\n",kthread_self(),arg);
	while(1)
	{
		sleep(2000);
		debug("thread<%p> running.kernel time=%d\r\n",kthread_self(),kernel_time());
	}
}
Beispiel #3
0
void timer::stop ()
{
    if(!turn_on_m)return;
    tick_type curclock = kernel_time();
    duration += (curclock - start_stamp);

    ARAGELI_ASSERT_1(is_calibrated());
    absprec += delta;

    turn_on_m = false;
}
Beispiel #4
0
timer::tick_type timer::clock_time () const
{
    tick_type tm = duration;

    if(turn_on_m)
    {
        tick_type curclock = kernel_time();
        tm += (curclock - start_stamp);
    }

    return tm;
}
Beispiel #5
0
void timer::start ()
{
    if(turn_on_m)return;
    start_stamp = kernel_time();
    turn_on_m = true;
}