How to know if all pending tevent_req requests have completed?

Stefan Metzmacher metze at samba.org
Thu Feb 23 18:55:22 UTC 2017


Am 23.02.2017 um 18:25 schrieb Jeremy Allison:
> On Thu, Feb 23, 2017 at 03:58:36PM +1100, Amitay Isaacs wrote:
>> On Thu, Feb 23, 2017 at 11:39 AM, Jeremy Allison <jra at samba.org> wrote:
>>
>>> On Thu, Feb 23, 2017 at 11:18:41AM +1100, Amitay Isaacs wrote:
>>>> Hi tevent experts,
>>>>
>>>> tevent_req_poll() allows to wait for a specific request.
>>>>
>>>> If I want to create n requests and wait for all of them to finish, is
>>> there
>>>> an easy way to do it?
>>>>
>>>> Here is an example computation:
>>>>
>>>> run_event_send()
>>>>    ... run scripts one after the other ...
>>>>
>>>>    if (timer expires) {
>>>>       run_debug_send()
>>>>       tevent_req_done()
>>>>    }
>>>>
>>>> In this case, run_debug_send() computation is *not* hanging off the
>>>> run_event_send() request.
>>>> The calling code needs to know that run_event computation has timed out,
>>>> but doesn't really care whether debugging computation is over or not.
>>> The
>>>> debug program can run in the background and log useful debug information
>>>> without affecting the caller.
>>>
>>> Can't you use tevent_wakeup_send() to set a timeout on the
>>> tevent context, and then check the state of each req you've
>>> saved off in a list somewhere by using tevent_req_is_in_progress() ?
>>>
>>
>> Well, the requests could created any at level, so keeping track of them
>> might not be feasible without layering violations.
>>
>> I was really hoping that event context keeps track of active requests and I
>> can query the event context if the requests list (or queue) is empty or not.
> 
> The event context does keep track, but different backends
> may do so in different ways - so there's no generic 'are
> any events pending' call (well, there's tevent_common_have_events(),
> but that's an internal tevent call meant for simple backends
> to use, so you can't use that :-).
> 
> The layering violation is your real problem here.

tevent_common_have_events() is used to break out of

tevent_loop_wait(ev);
so you may just want to use that and wait for it to return.

metze

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20170223/e1b9a725/signature.sig>


More information about the samba-technical mailing list