[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] getloadavg in chicken?

From: felix
Subject: Re: [Chicken-users] getloadavg in chicken?
Date: Thu, 08 Jul 2004 10:21:04 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113

address@hidden wrote:

I am not familiar with the C interface, so the following code contains
a bug (because conversion from C double to Scheme flonum is missing in
get-load-average? How?)
static double C_get_load_average(__scheme_value i)
  double avg;
  getloadavg(&avg, 1);
  return avg;

(define (get-load-average value)
  (let ((avg (##core#inline "C_get_load_average" value)))
    ;(write avg)(newline)

;; Not-so-quick-but-dirty:

(require-extension srfi-4)

int getloadavg(double *, int);

(define vec (f64vector 0))
(getloadavg vec 1)
(print (f64vector-ref vec 0))

;; Better:

(define get-load-average
  (foreign-lambda* double ()
     "double avg;"
     "if(getloadavg(&avg, 1) != 1) return(0);"
     "else return(avg);") )


reply via email to

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