1996-04-12 08:57:28 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1996-04-12 08:57:28 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1996-04-12 08:57:28 -07:00
|
|
|
/* Automatique. Distributed only by permission. */
|
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include <mlvalues.h>
|
|
|
|
#include <alloc.h>
|
|
|
|
#include <memory.h>
|
1996-09-04 07:15:31 -07:00
|
|
|
#include "unixsupport.h"
|
1996-04-12 08:57:28 -07:00
|
|
|
|
|
|
|
#ifdef HAS_SETITIMER
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#define Get_timeval(tv) \
|
|
|
|
(double) tv.tv_sec + (double) tv.tv_usec / 1e6
|
|
|
|
#define Set_timeval(tv, d) \
|
|
|
|
tv.tv_sec = (int)(d), \
|
|
|
|
tv.tv_usec = (int) (1e6 * ((d) - tv.tv_sec))
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
static value unix_convert_itimer(struct itimerval *tp)
|
1996-04-12 08:57:28 -07:00
|
|
|
{
|
|
|
|
value res;
|
1997-05-26 10:16:31 -07:00
|
|
|
value interval = Val_unit, v = Val_unit;
|
|
|
|
|
|
|
|
Begin_roots2(interval, v);
|
|
|
|
interval = copy_double(Get_timeval(tp->it_interval));
|
|
|
|
v = copy_double(Get_timeval(tp->it_value));
|
|
|
|
res = alloc_tuple(2);
|
|
|
|
Field(res, 0) = interval;
|
|
|
|
Field(res, 1) = v;
|
|
|
|
End_roots();
|
1996-04-12 08:57:28 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
static value unix_convert_itimer_native(struct itimerval *tp)
|
1996-07-25 06:18:23 -07:00
|
|
|
{
|
|
|
|
value res = alloc(Double_wosize * 2, Double_array_tag);
|
|
|
|
Store_double_field(res, 0, Get_timeval(tp->it_interval));
|
|
|
|
Store_double_field(res, 1, Get_timeval(tp->it_value));
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
1996-04-12 08:57:28 -07:00
|
|
|
static int itimers[3] = { ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF };
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value unix_setitimer(value which, value newval)
|
1996-04-12 08:57:28 -07:00
|
|
|
{
|
|
|
|
struct itimerval new, old;
|
|
|
|
Set_timeval(new.it_interval, Double_val(Field(newval, 0)));
|
|
|
|
Set_timeval(new.it_value, Double_val(Field(newval, 1)));
|
|
|
|
if (setitimer(itimers[Int_val(which)], &new, &old) == -1)
|
|
|
|
uerror("setitimer", Nothing);
|
|
|
|
return unix_convert_itimer(&old);
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value unix_setitimer_native(value which, value newval)
|
1996-07-25 06:18:23 -07:00
|
|
|
{
|
|
|
|
struct itimerval new, old;
|
|
|
|
Set_timeval(new.it_interval, Double_field(newval, 0));
|
|
|
|
Set_timeval(new.it_value, Double_field(newval, 1));
|
|
|
|
if (setitimer(itimers[Int_val(which)], &new, &old) == -1)
|
|
|
|
uerror("setitimer", Nothing);
|
|
|
|
return unix_convert_itimer_native(&old);
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value unix_getitimer(value which)
|
1996-04-12 08:57:28 -07:00
|
|
|
{
|
|
|
|
struct itimerval val;
|
|
|
|
if (getitimer(itimers[Int_val(which)], &val) == -1)
|
|
|
|
uerror("getitimer", Nothing);
|
|
|
|
return unix_convert_itimer(&val);
|
|
|
|
}
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value unix_getitimer_native(value which)
|
1996-07-25 06:18:23 -07:00
|
|
|
{
|
|
|
|
struct itimerval val;
|
|
|
|
if (getitimer(itimers[Int_val(which)], &val) == -1)
|
|
|
|
uerror("getitimer", Nothing);
|
|
|
|
return unix_convert_itimer_native(&val);
|
|
|
|
}
|
|
|
|
|
1996-04-12 08:57:28 -07:00
|
|
|
#else
|
|
|
|
|
1997-09-02 05:55:01 -07:00
|
|
|
value unix_setitimer(value which, value newval)
|
1996-07-25 06:18:23 -07:00
|
|
|
{ invalid_argument("setitimer not implemented"); }
|
1997-09-02 05:55:01 -07:00
|
|
|
value unix_getitimer(value which)
|
1996-07-25 06:18:23 -07:00
|
|
|
{ invalid_argument("getitimer not implemented"); }
|
1997-09-02 05:55:01 -07:00
|
|
|
value unix_setitimer_native(value which, value newval)
|
1996-07-25 06:18:23 -07:00
|
|
|
{ invalid_argument("setitimer not implemented"); }
|
1997-09-02 05:55:01 -07:00
|
|
|
value unix_getitimer_native(value which)
|
1996-07-25 06:18:23 -07:00
|
|
|
{ invalid_argument("getitimer not implemented"); }
|
1996-04-12 08:57:28 -07:00
|
|
|
|
|
|
|
#endif
|