From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18177 invoked by alias); 8 Feb 2018 08:32:19 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 17605 invoked by uid 89); 8 Feb 2018 08:32:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-7.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_1,RCVD_IN_DNSWL_LOW,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Subject: Re: [PATCH 3/3] Refactor atfork handlers To: Adhemerval Zanella Cc: libc-alpha@sourceware.org References: <1518008967-8310-1-git-send-email-adhemerval.zanella@linaro.org> <1518008967-8310-3-git-send-email-adhemerval.zanella@linaro.org> From: Florian Weimer Message-ID: <88a58530-092d-4daa-1096-97a1bf8e08ff@redhat.com> Date: Thu, 08 Feb 2018 11:26:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2018-02/txt/msg00282.txt.bz2 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