[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
proposed getitimer and setitimer functions
From: |
Rob Browning |
Subject: |
proposed getitimer and setitimer functions |
Date: |
06 Jul 2001 12:53:17 -0500 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 |
Is the following implementation of/interface for setitimer OK? I need
to add real docs, but in summary, you call it like this:
(setitimer which-timer
interval-secs interval-microsecs
value-secs value-microsecs)
and it returns a three element list:
(result-int
(old-timer-interval-secs . old-timer-interval-microsecs)
(old-timer-value-secs . old-timer-value-microsecs))
Also, what about the getitimer code below? You call it like this:
(getitimer which-timer)
and it returns a result structured the same as with setitimer.
Finally, this patch defines ITIMER_REAL, ITIMER_VIRTUAL, and
ITIMER_PROF.
If all of this is OK (and not to big a change), I'd like to commit it
now for 1.6.0 which I'll be branching before Sun. These two functions
are needed by anyone trying to build a statistical profiler.
(Oh, and is there any rule of thumb about when you're supposed to use
SCM_VALIDATE_FOO vs just letting scm_foo2bar handle signaling an
error?)
Thanks
Index: libguile/scmsigs.c
===================================================================
RCS file: /cvsroot/guile/guile/guile-core/libguile/scmsigs.c,v
retrieving revision 1.60
diff -u -r1.60 scmsigs.c
--- libguile/scmsigs.c 2001/06/26 17:53:09 1.60
+++ libguile/scmsigs.c 2001/07/06 17:44:45
@@ -46,6 +46,7 @@
#include <signal.h>
#include <errno.h>
+#include <stdio.h>
#include "libguile/_scm.h"
@@ -417,6 +418,64 @@
}
#undef FUNC_NAME
+SCM_DEFINE (scm_setitimer, "setitimer", 5, 0, 0,
+ (SCM which_timer,
+ SCM interval_seconds, SCM interval_microseconds,
+ SCM value_seconds, SCM value_microseconds),
+ "Undocumented yet.")
+#define FUNC_NAME s_scm_setitimer
+{
+ int result;
+ int c_which_timer;
+ struct itimerval new_timer;
+ struct itimerval old_timer;
+
+ SCM_VALIDATE_INUM (1, which_timer);
+ SCM_VALIDATE_NUMBER (2, interval_seconds);
+ SCM_VALIDATE_NUMBER (3, interval_microseconds);
+ SCM_VALIDATE_NUMBER (4, value_seconds);
+ SCM_VALIDATE_NUMBER (5, value_microseconds);
+
+ c_which_timer = SCM_INUM(which_timer);
+
+ new_timer.it_interval.tv_sec = scm_num2long(interval_seconds, 0, NULL);
+ new_timer.it_interval.tv_usec = scm_num2long(interval_microseconds, 0, NULL);
+ new_timer.it_value.tv_sec = scm_num2long(value_seconds, 0, NULL);
+ new_timer.it_value.tv_usec = scm_num2long(value_microseconds, 0, NULL);
+
+ result = setitimer(c_which_timer, &new_timer, &old_timer);
+
+ return scm_list_3(SCM_MAKINUM(result),
+ scm_cons(scm_long2num(old_timer.it_interval.tv_sec),
+ scm_long2num(old_timer.it_interval.tv_usec)),
+ scm_cons(scm_long2num(old_timer.it_value.tv_sec),
+ scm_long2num(old_timer.it_value.tv_usec)));
+}
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_getitimer, "getitimer", 1, 0, 0,
+ (SCM which_timer),
+ "Undocumented yet.")
+#define FUNC_NAME s_scm_getitimer
+{
+ int result;
+ int c_which_timer;
+ struct itimerval old_timer;
+
+ SCM_VALIDATE_INUM (1, which_timer);
+
+ c_which_timer = SCM_INUM(which_timer);
+
+ result = getitimer(c_which_timer, &old_timer);
+
+ return scm_list_3(SCM_MAKINUM(result),
+ scm_cons(scm_long2num(old_timer.it_interval.tv_sec),
+ scm_long2num(old_timer.it_interval.tv_usec)),
+ scm_cons(scm_long2num(old_timer.it_value.tv_sec),
+ scm_long2num(old_timer.it_value.tv_usec)));
+}
+#undef FUNC_NAME
+
#ifdef HAVE_PAUSE
SCM_DEFINE (scm_pause, "pause", 0, 0, 0,
(),
@@ -553,6 +612,11 @@
#ifdef SA_RESTART
scm_c_define ("SA_RESTART", scm_long2num (SA_RESTART));
#endif
+
+ /* Stuff needed by setitimer. */
+ scm_c_define ("ITIMER_REAL", SCM_MAKINUM (ITIMER_REAL));
+ scm_c_define ("ITIMER_VIRTUAL", SCM_MAKINUM (ITIMER_VIRTUAL));
+ scm_c_define ("ITIMER_PROF", SCM_MAKINUM (ITIMER_PROF));
#ifndef SCM_MAGIC_SNARFER
#include "libguile/scmsigs.x"
--
Rob Browning
rlb @defaultvalue.org, @linuxdevel.com, and @debian.org
Previously @cs.utexas.edu
GPG=1C58 8B2C FB5E 3F64 EA5C 64AE 78FE E5FE F0CB A0AD