From: Sam Steingold <sds@podval.org>
To: caml-list@inria.fr
Subject: pthread_getcpuclockid et al
Date: Wed, 24 May 2006 11:51:46 -0400 [thread overview]
Message-ID: <alwtcb2zfx.fsf@quant8.janestcapital.quant> (raw)
How do I time an individual Ocaml thread?
There appears to be no interface to pthread_getcpuclockid() and
clock_gettime() and it is not obvious from
ocaml/otherlibs/systhreads/posix.c how to get the pthread_t of a given
Ocaml Thread.t object (caml_thread_descr does not point to a
caml_thread_struct).
here is what I have so far:
=========================== pth_clock.mli
type clock
external getcpuclock: Thread.t -> clock = "getcpuclock"
=========================== pth_clock.mli
=========================== pth_clock.ml
external getcpuclock : Thread.t -> clock = "getcpuclock"
=========================== pth_clock.ml
=========================== pth_clock.c
#include <pthread.h>
#include <time.h>
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/fail.h>
#include <caml/alloc.h>
#include <caml/custom.h>
/* see /usr/local/home/godi/godi/lib/godi/saved-src/ocaml.tar.gz
ocaml/otherlibs/systhreads/posix.c */
extern pthread_t tid_to_pth (value tid);/* how do I define this??? */
/* Encapsulation of clockid_t as Caml custom blocks. */
#define clock_val(v) (*((clockid_t **) Data_custom_val(v)))
void clock_finalize (value v) { free(clock_val(v)); }
static struct custom_operations clockid_ops = {
"caml.clockid_t",
&clock_finalize,
custom_compare_default,
custom_hash_default,
custom_serialize_default,
custom_deserialize_default
};
/* Allocating a Caml custom block to hold the given clockid_t * */
static value alloc_clock (clockid_t * c) {
value v = alloc_custom(&clockid_ops, sizeof(clockid_t *), 0, 1);
clock_val(v) = c;
return v;
}
CAMLprim value getcpuclock (value tid) {
CAMLparam1(tid);
clockid_t *c = malloc(sizeof(clockid_t));
if (pthread_getcpuclockid(tid_to_pth(tid),c) == 0)
CAMLreturn(alloc_clock(c));
else {
free(c);
caml_failwith("pthread_getcpuclockid");
}
}
=========================== pth_clock.c
Help?
Thanks.
--
Sam Steingold (http://www.podval.org/~sds) on Fedora Core release 5 (Bordeaux)
http://pmw.org.il http://openvotingconsortium.org http://dhimmi.com
http://thereligionofpeace.com http://palestinefacts.org http://ffii.org
Why do we want intelligent terminals when there are so many stupid users?
reply other threads:[~2006-05-24 15:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alwtcb2zfx.fsf@quant8.janestcapital.quant \
--to=sds@podval.org \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox