File: static.c

package info (click to toggle)
eztrace 2.0%2Brepack-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,132 kB
  • sloc: ansic: 23,501; perl: 910; sh: 857; cpp: 771; makefile: 696; fortran: 327; f90: 320; python: 57
file content (52 lines) | stat: -rw-r--r-- 1,153 bytes parent folder | download | duplicates (8)
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
/* -*- c-file-style: "GNU" -*- */
/*
 * Copyright (C) CNRS, INRIA, Université Bordeaux 1, Télécom SudParis
 * See COPYING in top-level directory.
 */

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

#include <stdarg.h>

// Debugging part, print out only if debugging level of the system is verbose or more
int _debug = -77;

void debug(char *fmt, ...) {
  if (_debug == -77) {
    char *buf = getenv("EZTRACE_DEBUG");
    if (buf == NULL)
      _debug = 0;
    else
      _debug = atoi(buf);
  }
  if (_debug >= 0) { // debug verbose mode
    va_list va;
    va_start(va, fmt);
    vfprintf(stdout, fmt, va);
    va_end(va);
  }
}
// end of debugging part

#define microsleep(us) do { struct timespec tm; tm.tv_sec = (time_t)us / 1000; tm.tv_nsec = (long)(us % 1000) * 1000; nanosleep(&tm, NULL); } while(0)

int mafunc(int n) {
  debug("i sleep %d microsec\n", n);
  microsleep(n);
  return EXIT_SUCCESS;
}

int main() {
  int i = 0;
  debug("hello i m in main an i will wait 4 microsec\n");
  microsleep(4);
  for (i = 0; i < 4; i++) {
    mafunc(i);
    debug("main sleep 1 microsec\n");
    microsleep(1);
  }
  return EXIT_SUCCESS;

}