Commit 5740c0e1 authored by sof's avatar sof
Browse files

[project @ 1999-09-12 14:33:56 by sof]

Re-ordered code so that the POSIX-blessed time() is used in preference
to the plethora of other clock reading calls. This *should* be an OK and
non-upsetting change, but idiosyncracies of OS-supplied header files may
just force me to rethink. We'll see..
parent 61316922
/*
* (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
*
* $Id: getClockTime.c,v 1.4 1999/05/03 13:22:29 sof Exp $
* $Id: getClockTime.c,v 1.5 1999/09/12 14:33:56 sof Exp $
*
* getClockTime Runtime Support
*/
#ifndef _AIX
#define NON_POSIX_SOURCE /* gettimeofday */
#endif
#include "Rts.h"
#include "stgio.h"
#ifdef HAVE_GETCLOCK
/* It seems morally wrong to skew this in favour of
using non-POSIX calls (gettimeofday(), ftime()..),
rather than time()....so, let's re-order it all
(and hope OS idiosyncracies won't get in the way
of using time(), the moral elite's favourite.)
*/
#if defined(HAVE_TIME_H)
# include <time.h>
#elif defined(HAVE_GETCLOCK)
# ifdef HAVE_SYS_TIMERS_H
# define POSIX_4D9 1
# include <sys/timers.h>
# endif
#else
# ifdef HAVE_GETTIMEOFDAY
#elif defined(HAVE_GETTIMEOFDAY)
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# endif
# else
# ifdef HAVE_TIME_H
# include <time.h>
# endif
# endif
#endif
#ifdef HAVE_WINDOWS_H
......@@ -45,7 +38,11 @@
StgInt
getClockTime(StgByteArray sec, StgByteArray nsec)
{
#if defined(_WIN32)
#if defined(_WIN32) && !defined(cygwin32_TARGET_OS)
/*
* time() as is implemented by cygwin (in B20.1) is
* not right, so stay away (and use time()) instead.
*/
struct timeb t;
_ftime(&t);
......@@ -53,6 +50,16 @@ getClockTime(StgByteArray sec, StgByteArray nsec)
((unsigned int *)sec)[0] = (unsigned int)t.time;
((unsigned int *)nsec)[0] = (unsigned int)t.millitm * 1000;
return 0;
#elif defined(HAVE_TIME_H)
time_t t;
if ((t = time(NULL)) == (time_t) -1) {
cvtErrno();
stdErrno();
return -1;
}
((unsigned long int *)sec)[0] = t;
((unsigned long int *)nsec)[0] = 0;
return 0;
#elif defined(HAVE_GETCLOCK)
struct timespec tp;
......@@ -76,22 +83,15 @@ getClockTime(StgByteArray sec, StgByteArray nsec)
((unsigned long int *)nsec)[0] = tp.tv_usec * 1000;
return 0;
#else
time_t t;
if ((t = time(NULL)) == (time_t) -1) {
cvtErrno();
stdErrno();
return -1;
}
((unsigned long int *)sec)[0] = t;
((unsigned long int *)nsec)[0] = 0;
return 0;
#error "getClockTime: don't know how to get at the clock's time"
#endif
}
StgInt
prim_getClockTime(StgByteArray sec, StgByteArray nsec)
{
#if defined(_WIN32)
#if defined(_WIN32) && !defined(cygwin32_TARGET_OS)
/* see getClockTime() comment re: ftime() & cygwin */
struct timeb t;
_ftime(&t);
......@@ -99,6 +99,16 @@ prim_getClockTime(StgByteArray sec, StgByteArray nsec)
((unsigned long int *)sec)[0] = t.time;
((unsigned long int *)nsec)[0] = t.millitm * 1000;
return 0;
#elif defined(HAVE_TIME_H)
time_t t;
if ((t = time(NULL)) == (time_t) -1) {
cvtErrno();
stdErrno();
return -1;
}
((StgInt64*)sec)[0] = t;
((StgInt64*)nsec)[0] = 0;
return 0;
#elif defined(HAVE_GETCLOCK)
struct timespec tp;
......@@ -122,14 +132,6 @@ prim_getClockTime(StgByteArray sec, StgByteArray nsec)
((StgInt64*)nsec)[0] = tp.tv_usec * 1000;
return 0;
#else
time_t t;
if ((t = time(NULL)) == (time_t) -1) {
cvtErrno();
stdErrno();
return -1;
}
((StgInt64*)sec)[0] = t;
((StgInt64*)nsec)[0] = 0;
return 0;
#error "getClockTime: don't know how to get at the clock's time"
#endif
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment