File: timing.c

package info (click to toggle)
xtux 0.2-2.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,616 kB
  • ctags: 465
  • sloc: ansic: 2,921; makefile: 89
file content (35 lines) | stat: -rw-r--r-- 700 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
/*
 * timing.c: Timing functions for XTux.
 * Copyright 1999 David Lawrence (philaw@camtech.net.au)
 * Last modified July 26
 */

#include <sys/time.h>
#include "header.h"
#include "timing.h"

/* Delay for i microseconds, returns seconds paused. */
int delay(unsigned int i)
{
  
  struct timeval timeout;
  
  if( i ) {
    timeout.tv_usec =  i % (unsigned long) M_SEC;
    timeout.tv_sec  =  i / (unsigned long) M_SEC;
    select(0, NULL, NULL, NULL, &timeout);
    return i;
  }

  return 0;

}

/* Return the difference in microseconds between st and current time */
int time_diff(struct timeval rt, struct timeval st)
{

  return 1000000 * (rt.tv_sec - st.tv_sec) + rt.tv_usec - st.tv_usec;

}