[PATCH 3/3] Refactor atfork handlers
Florian Weimer
fweimer@redhat.com
Thu Feb 8 11:26:00 GMT 2018
On 02/07/2018 06:16 PM, Adhemerval Zanella wrote:
> + for (size_t i = 0; i < fork_handler_list_size (&fork_handlers);)
> + {
> + /* dynarray remove maintains element order, so update index iff there is
> + no removal. */
> + if (fork_handler_list_at (&fork_handlers, i)->dso_handle == dso_handle)
> + fork_handler_list_remove (&fork_handlers, i);
> + else
> + i++;
> + }
I thought a bit more about this. Doesn't this lead to cubic run-time as
DSOs are unloaded (quadratic run-time locally here, multiplied by the
outer loop for unloading the DSOs)?
I think fork_handler_list_remove is the wrong abstraction here.
Something like std::remove_if would be better, which moves each array
element at most once even if multiple elements are removed during the
scan. Writing this generically in C is probably not worth the effort,
so perhaps open-code that here?
Thanks,
Florian
More information about the Libc-alpha
mailing list