[PATCH] tevent and threads - infrastructure improvements.

Jeremy Allison jra at samba.org
Wed Jul 22 19:09:29 UTC 2015


It always irritated me that someone close to the Samba
Team (who shall remain nameless) selected libev over
tevent when designing some new code.

The reason was that libev has the function:

ev_async_send()

which allows one thread to schedule a callback
on the event loop of another thread.

I knew this could be done in tevent, but didn't
have an elegant (a matter of opinion of course :-)
solution, so I coded one up. Here it is for your
review.

It has the advantage that if you don't need
the functionality to schedule a callback
on the event loop of another thread, you don't
pay any costs in regular tevent usage.

It adds 3 functions to tevent:

int tevent_threaded_context_register(struct tevent_context *ev);

which sets up the background data structures
needed for the functionality.

int tevent_threaded_context_unregister(struct tevent_context *ev);

which tears them down again, and finally:

int tevent_threaded_async_call(struct tevent_context *dest_ev_ctx,
                                void (*callback_fn)(struct tevent_context *,
                                                void *),
                                void **pp_private);

which asynchronously schedules callback_fn to be invoked
on the destination context under the thread that's running
it's event loop.

It (and the tests I added) pass valgrind --tool=drd
but Volker, you are the threaded code master, so
I'd love you to take a closer look.

Please review.

Cheers !

Jeremy.

PS. Just wanted to leave this here:

http://bholley.net/blog/2015/must-be-this-tall-to-write-multi-threaded-code.html

PPS. This is why I've been a bit quiet recently,
getting this done took a lot of thinking time :-).
Back to your normally scheduled Jeremy service
now...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tevent-threads.patch
Type: text/x-diff
Size: 32339 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20150722/e2a05295/tevent-threads.diff>


More information about the samba-technical mailing list