Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2002:
[Freeciv-Dev] Re: (PR#2278) Ping version 13
Home

[Freeciv-Dev] Re: (PR#2278) Ping version 13

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#2278) Ping version 13
From: "Raimar Falke via RT" <rt@xxxxxxxxxxxxxx>
Date: Sun, 10 Nov 2002 13:44:36 -0800
Reply-to: rt@xxxxxxxxxxxxxx

On Sun, Nov 10, 2002 at 12:18:21PM -0800, Thomas Strub via RT wrote:

It looks like Thomas problem is a buggy gettimeofday. The attached
test program (stolen from linux-kernel) should show this.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
 "Transported to a surreal landscape, a young girl kills the first woman
  she meets and then teams up with three complete strangers to kill again."
    -- TV listing for the Wizard of Oz in the Marin Independent Journal

#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdio.h>
#include <time.h>

int main(int argc, char **argv)
{
  time_t tick;
  struct timeval tv[2];
  int prev = 0;
  int fwd = 0;
  int back = 0;
  int max = 0;

  for (;;) {
    gettimeofday(tv, 0);
    if (prev) {
      if (tv[0].tv_sec < tv[1].tv_sec ||
          (tv[0].tv_sec == tv[1].tv_sec && tv[0].tv_usec < tv[1].tv_usec)) {
        unsigned long long delta = ((tv[1].tv_sec - tv[0].tv_sec) * 1000000 +
                                    (tv[1].tv_usec - tv[0].tv_usec));
        if (delta > max) {
          max = delta;
        }
        ++back;
      } else {
        if (tv[0].tv_sec - tv[1].tv_sec > 1) {
          unsigned long long delta =
              ((tv[0].tv_sec - tv[1].tv_sec) * 1000000 +
               (tv[0].tv_usec - tv[1].tv_usec));

          printf("got a huge step forward, delta=%lldus\n", delta);
        }
        ++fwd;
      }
    }
    if (tick != tv[0].tv_sec && tv[0].tv_sec == tv[1].tv_sec + 1) {
      tick = tv[0].tv_sec;
      printf("%.24s: fwd:%d/%d:back max %07u\n",
             ctime(&tv[0].tv_sec), fwd, back, max);
      fwd = back = 0;
      max = 0;
    }
    prev = 1;
    tv[1] = tv[0];
  }
}

[Prev in Thread] Current Thread [Next in Thread]