This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 3/3] Refactor atfork handlers


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]