[PATCH] tevent and threads - infrastructure improvements.

Jeremy Allison jra at samba.org
Wed Jul 22 23:12:08 UTC 2015


On Thu, Jul 23, 2015 at 12:52:15AM +0200, Stefan (metze) Metzmacher wrote:
> Hi Jeremy,
> 
> > 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);
> 
> void ** is not valid in an argument list.

OK, I'll fix that.

> > which asynchronously schedules callback_fn to be invoked
> > on the destination context under the thread that's running
> > it's event loop.
> 
> This somehow feels unnatural in the tevent environment.

I need a better argument than "feels". Remember this
easily allows porting libev code concepts to tevent,
which is a big plus.

Right now tevent is great infrastucture that's almost
completly ignored outside of our coding circle. We need
to do better if it's going to survive.

Plus this is working code plus documentation and tutorial,
so if you want something better, please code it up first :-).

> Something like this would be better:
> 
> struct tevent_context *tevent_thread_proxy_context(struct tevent_context
> *main_ev);
> 
> The thread can then only schedule immediate events on the returned proxy
> context, this will wakeup the main_ev and move the immediate events from
> the proxy to the main_ev.
> 
> The immediate events can be preallocated in before starting the thread.

I don't get this. Can you explain how this would be
used in the same way as ev_async_send() ?

Plus I don't think having to preallocate immediate events
is a good idea. This needs to be dynamic, so threads
can send as many messages as process resources allow,
without any arbitrary limits.



More information about the samba-technical mailing list