caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
To: Richard Neswold <rich.neswold@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] OpenGL and LWT
Date: Tue, 18 Mar 2014 00:50:29 +0100	[thread overview]
Message-ID: <E63E96E3484F43BD99787750DF170A94@erratique.ch> (raw)
In-Reply-To: <2F20BDD4-4475-4250-921F-E4CDB34BFD86@gmail.com>

Le lundi, 17 mars 2014 à 23:50, Richard Neswold a écrit :
> I could have an Lwt thread call Sdl.poll_event and then go to sleep if no events were available, but I'm trying to make this driven by events and not resort to polling, if possible.

There is certainly more than one way to do that, but that's what I do at the moment (with another cooperative threading library). Favor the treatement of the UI events, if there's no UI event run the scheduler for 10ms.  

let rec loop deadline =  
  while Sdl.poll_event e do do_event e done;
  run_scheduler ~timeout:10;  
  loop ()

Regarding Tsdl.Sdl.wait_event, it's not really better than that, if you have a look at its C implementation [1] you'll see it tries to get an event and if none is available it will sleep for 10ms before trying again. This means that any SDL based program using Sdl.wait_event, constantly uses ~1.5% cpu (at least on osx), you should be able to bring that down by writing your own loop as above and augmenting the timeout value when your application is not in the foreground.  

Best,

Daniel

[1] http://hg.libsdl.org/SDL/file/4c01875a4620/src/events/SDL_events.c#l421



  reply	other threads:[~2014-03-17 23:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-15 17:37 Richard Neswold
2014-03-17 10:09 ` Jeremie Dimino
2014-03-17 10:32   ` Ivan Gotovchits
2014-03-17 13:39     ` Rich Neswold
2014-03-17 14:05       ` Daniel Bünzli
2014-03-17 14:13         ` Daniel Bünzli
2014-03-17 22:50         ` Richard Neswold
2014-03-17 23:50           ` Daniel Bünzli [this message]
2014-03-19 12:01             ` Rich Neswold
2014-03-17 10:34   ` Török Edwin
2014-03-17 11:01     ` Daniel Bünzli

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=E63E96E3484F43BD99787750DF170A94@erratique.ch \
    --to=daniel.buenzli@erratique.ch \
    --cc=caml-list@inria.fr \
    --cc=rich.neswold@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).