/*------------------------------------------------------------------------
 *
 *  File:	o1k_misc.cc
 *  Revision:	1.3
 *  Last Mod:	17:36:49, 03/01/97
 *
 *  Description:
 *     Misc functions. Mostly time related.
 *     
 *----------------------------------------------------------------------*/
#pragma ident	"@(#)o1k_misc.cc	1.3\t97/03/01  "
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/poll.h>

static struct timeval conf_base_time;

void o1k_time_init()
{
  gettimeofday(&conf_base_time, NULL);
}

void o1k_new_time(struct timeval* t)
{
  gettimeofday(t, NULL);
}

double o1k_mtime_diff(struct timeval* t)
{
  struct timeval tend;
  double tval;
  gettimeofday(&tend, NULL);
  tval = (tend.tv_sec - t->tv_sec) + (tend.tv_usec - t->tv_usec) * 1e-6;

  return tval;
}

double o1k_msec_time()
{
  return o1k_mtime_diff(&conf_base_time);
}

void o1k_msec_sleep(int mstime)
{
  int poll_time = (((mstime-1)/10)*10)+1;
  poll(NULL, 0, poll_time);
}
