File: tick_tack.c

package info (click to toggle)
netproc 0.6.6-0.1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 908 kB
  • sloc: ansic: 7,876; makefile: 101; sh: 12
file content (54 lines) | stat: -rw-r--r-- 970 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// gcc -o tick_tack tick_tack.c ../src/timer.c -Wall -Wextra && ./tick_tack

// this is a stupid test done to check for a bug,
// run this will stress the cpu

#include <stdio.h>
#include <time.h>
#include <stdint.h>

#include "../src/timer.h"

// in milliseconds
#define ONE_SEC 1000

void
tick_tack ( uint64_t running )
{
  static int tick_tack = 0;

  printf ( "%s - %s\n",
           ( tick_tack ) ? "tack" : "tick",
           msec2clock ( running ) );

  tick_tack = !tick_tack;
}

int
main ( void )
{
  uint64_t cur_time = get_time ();
  uint64_t running = 0;

  tick_tack ( running );
  while ( 1 )
    {
      uint64_t new_time = get_time ();

      if ( new_time < cur_time )
        continue;

      uint32_t diff_time = new_time - cur_time;

      if ( diff_time >= ONE_SEC )
        {
          running += diff_time;
          diff_time -= ONE_SEC;
          cur_time = new_time + diff_time;

          tick_tack ( running );
        }
    }

  return 0;
}