[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LibEvent binding to Lua? Mix w/ HelperThreads?
- From: Javier Guerra <javier@...>
- Date: Fri, 31 Mar 2006 06:40:04 -0500
On Friday 31 March 2006 1:52 am, Thomas Harning Jr. wrote:
> Just wondering, how does a LibEvent binding into Lua sound? Right now
> it seems to be a good option/addition to the HelperThreads library for
> my MoonLog application (syslog/metalog replacement).
it wouldn't be hard to do a thin binding library; the main hurdle i see is
that any other library you'd want to produce those events would have to give
you a file descriptor (fd) to wait on.
that's not hard for 'real' file based I/O and sockets; but what about
databases? these could block for significant time, and i don't know of
anyone that gives you an fd telling "call me when this fd is writeable and i
won't block"
my goal with HelperThreads is to make it easy to write libraries binding any
kind of blocking C libraries; since several of them doesn't provide any
non-blocking interface; and those that do might use any of a number of ways
to signal completion.... the most general mechanism is to spawn a thread and
let it block.
> ... Another idea I thought of at this later hour is to have
> HelperThreads be the core... and setup a task/thread as the LibEvent
> dispatch loop... and whenever there's events, either signal_task and
> wait, or queue up the data in a threadsafe queue and
> signal_task(0). When the update handler gets called, the queue gets
> transferred somehow (either by returning an object w/ a CClosure that
> can access the latest queue objects and then free the data via __gc
> and/or :free())
maybe the nicest way to do it would be to add either a Lua object to be
returned by the update handler. just set up a hidden Lua table indexed by a
lightuserdata that holds the pointer given to event_set(). when the event is
signalled, just get the associated content and return it.
the same mechanism could be used to associate a Lua function to an event, and
call it when the event is ready.
also, it wouldn't be too hard to do it both as an independent library, and
provide a 'task-able' event_loop() if Helper-Threads is present.
--
Javier
Attachment:
pgpLKdswLEbmQ.pgp
Description: PGP signature