Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3811588pxu; Tue, 20 Oct 2020 00:41:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyr9aJkP2r/bmHAfaIhX4MXUJ62mlulafKK0QAB7d2o7QP/W0GflLWM5rFAuTKaOk99lPG X-Received: by 2002:a50:c05b:: with SMTP id u27mr1416586edd.290.1603179708319; Tue, 20 Oct 2020 00:41:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603179708; cv=none; d=google.com; s=arc-20160816; b=ehx5sGwiXSZo98LRz38nE5DSGVCGgc6+KPWthrSH0iztBAaCmdvDQeoTlEu7hyDqWO fdNDJL65gSMky8gmFLZYWhWA+ytVE27Q6U10IrleSQN5jEYpC0vlrFECeuU9IKI018jy w6H5PBUY3KMm+flGfiYKmRKE92DWs13pEM5oezruK98yn1j/0GqLDLD+QpOxHEECYWQn I5tSGys7qNdq2kgHU8ykY60tGYDSzrJqjnuApW2TAHuzgWQCqct0Au4cnO3qgDAm8crE /m2H0LVMktF7eLu2ow3XtnYnwYf92a08+xtGAR9eJLGx8HZzGaW4R5bnXyopUOOONEZo hIJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=xqLU4oOK29Elmk+yTbDCjjGVCmjyNqMveIRrbZ5FjlU=; b=Rs3lBtQ0W2W3eUjkwNv37y4l+/SbL8hbrWjCHzp2TOr3HwACtNb9gvhuvSAgsDtaMr Q0+qBa7cLryiTsQSGLlpWUzW9MZetMqvdcSK+j6XG6Iy5E8jWs20TxVfate3iV7+AATN U+dBdn7+MhTeeRjnkQ7DNgKFGRsmUEtY0Azl1BmWB6AutZNA3bPPMBFZpzAXIE6rF9ro Xd9DzD94Pp3QFymM982wMFoBACoNaSi0+kHkzF8ZIAnjp9ceyQyz4HwQrMhtnbVDEMdP NBykBXEIdSn18Ba/9sgAttJbicIZAw0j4GE8eYk2qS8QYBxjhSJdMGLrbEXmjk2NYb0N VyjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vEFlqqO0; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p13si688973ejb.456.2020.10.20.00.41.24; Tue, 20 Oct 2020 00:41:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vEFlqqO0; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731249AbgJSUSV (ORCPT + 99 others); Mon, 19 Oct 2020 16:18:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726118AbgJSUSV (ORCPT ); Mon, 19 Oct 2020 16:18:21 -0400 Received: from mail-oi1-x243.google.com (mail-oi1-x243.google.com [IPv6:2607:f8b0:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26760C0613CE for ; Mon, 19 Oct 2020 13:18:21 -0700 (PDT) Received: by mail-oi1-x243.google.com with SMTP id u17so1415332oie.3 for ; Mon, 19 Oct 2020 13:18:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xqLU4oOK29Elmk+yTbDCjjGVCmjyNqMveIRrbZ5FjlU=; b=vEFlqqO0dzL/BD4R+dRT1SO7KroOYcqvwGwxFzKVlxlR7BB0drqs24wtKwJKvEedCC fgVwhWKbsjIHu485Ao0P2cZ3lBf4LZJjCk5DFbrhBMuhzXzCMORpLZyPETDG3bd+SJh9 F7gUJBOUFY8oATD2r5+YE67XUOS0vHlJTOQnNxWKG8XyNBC8UtV5Y75u4hf/3kE1o1wp yW7d10FRzjS1XDszq6qzy8h5ISnFDAjRoVbxTTlwYXkJRrJVvzNNpLsWHLHdLifsQbYz PdbMWG52BngLwoIc23i3FCxJKlQCLKENuyh2ye6PTmsooTwnGzv6xNuF17Orm+5xBg2T H6Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xqLU4oOK29Elmk+yTbDCjjGVCmjyNqMveIRrbZ5FjlU=; b=tE1RwKm00qPrztWDRM49n2u8GsKe1OAQvKkHK9xLS5HF+gEryBNvXP6zTrIbMNONnq QafZSSBuxw42oUu99unYxNG9riDkJMJwV4YcLuL5dY2PR4xs1N074mD7G0TvITO9LXyT JNXoAC827yfLD1CKYoqmYj5IDmcMi4EzL6SqdQKgwb1rVfylUOGvPZpPm8+YBcZ/0N3m zpVQBZEYgeailCtzGFUwwllzS8YwdNrK3uDVJ0MyU6LKk9mW6HNw4B1BKwr8cPBMPIGk JV5oYybR4rE06GKOm/rGtNPW2cago7kobpvHHD9qDuaU9Pvt9m6qUDdxDN0hVWDegKSN Dfsg== X-Gm-Message-State: AOAM532WFR1Zu0KIj+mdt/BUEXj200rEo/nybngSsL6ONvbfGLoA1RSk P6gtLO3H9usuDLQ7kbJPM7U9SkZZFDmCNsvw0n8= X-Received: by 2002:aca:4c7:: with SMTP id 190mr827796oie.58.1603138700480; Mon, 19 Oct 2020 13:18:20 -0700 (PDT) MIME-Version: 1.0 References: <20201005041932.99783-1-inga.stotland@intel.com> <38633edb6423eabcd54c3b7559117e7ee64cb51b.camel@intel.com> <34814d0a7ad0f0ba19bb85e596f5a47843d2da39.camel@intel.com> In-Reply-To: <34814d0a7ad0f0ba19bb85e596f5a47843d2da39.camel@intel.com> From: Luiz Augusto von Dentz Date: Mon, 19 Oct 2020 13:18:09 -0700 Message-ID: Subject: Re: [PATCH BlueZ] shared/timeout-ell: Fix timeout wrapper implementation To: "Stotland, Inga" Cc: "linux-bluetooth@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Inga, On Mon, Oct 19, 2020 at 1:00 PM Stotland, Inga wrote: > > Another ping > > On Fri, 2020-10-09 at 21:03 -0700, Inga Stotland wrote: > > Gentle ping > > On Sun, 2020-10-04 at 21:19 -0700, Inga Stotland wrote: > > This fixes the following issues: > > - Correct user data is passed around to l_timeout_create(): > > locally allocated timeout data is a valid "user data" to > > associate with a newly created timeout. Previously, user_data > > passed as an argument to timeout_add() was incorrectly used as > > an argument to l_timeout_create() > > - To maintain common API and work around the issue when the conversion > > of a pointer to an unsigned int truncates the initial value, a queue > > of active timeouts is maintained where pointer each l_timeout structure > > is associate with a unique id. This id is returned when timeout_create() > > API is called and can be subsequently used with timeout_remove(). > > --- > > src/shared/timeout-ell.c | 50 ++++++++++++++++++++++++++++++++++++---- > > 1 file changed, 45 insertions(+), 5 deletions(-) > > > diff --git a/src/shared/timeout-ell.c b/src/shared/timeout-ell.c > > index c2da387e2..023364069 100644 > > --- a/src/shared/timeout-ell.c > > +++ b/src/shared/timeout-ell.c > > @@ -12,13 +12,23 @@ > > > > #include "timeout.h" > > > > +static struct l_queue *timeout_q; > > + > > struct timeout_data { > > timeout_func_t func; > > timeout_destroy_func_t destroy; > > - unsigned int timeout; > > void *user_data; > > + unsigned int timeout; > > }; > > > > +static bool match_id(const void *a, const void *b) > > +{ > > + unsigned int to_id = L_PTR_TO_UINT(a); > > + unsigned int id = L_PTR_TO_UINT(b); > > + > > + return (to_id == id); > > +} > > + > > static void timeout_callback(struct l_timeout *timeout, void *user_data) > > { > > struct timeout_data *data = user_data; > > @@ -43,7 +53,12 @@ unsigned int timeout_add(unsigned int timeout, timeout_func_t func, > > void *user_data, timeout_destroy_func_t destroy) > > { > > struct timeout_data *data; > > - uint32_t id; > > + unsigned int id = 0; > > + struct l_timeout *to; > > + int tries = 0; > > + > > + if (!timeout_q) > > + timeout_q = l_queue_new(); > > > > data = l_new(struct timeout_data, 1); > > > > @@ -52,12 +67,37 @@ unsigned int timeout_add(unsigned int timeout, timeout_func_t func, > > data->user_data = user_data; > > data->timeout = timeout; > > > > - id = L_PTR_TO_UINT(l_timeout_create(timeout, timeout_callback, > > - user_data, timeout_destroy)); > > + while (id == 0 && tries < 3) { > > + to = l_timeout_create(timeout, timeout_callback, > > + data, timeout_destroy); > > + if (!to) > > + break; > > + > > + tries++; > > + id = L_PTR_TO_UINT(to); > > + > > + if (id == 0 || > > + l_queue_find(timeout_q, match_id, L_UINT_TO_PTR(id))) { > > + > > + l_timeout_remove(to); > > + continue; > > + } > > + > > + l_queue_push_tail(timeout_q, to); > > + } > > + > > + if (id == 0) > > + l_free(data); > > + > > return id; > > } > > > > void timeout_remove(unsigned int id) > > { > > - l_timeout_remove(L_UINT_TO_PTR(id)); > > + struct l_timeout *to; > > + > > + to = l_queue_remove_if(timeout_q, match_id, L_UINT_TO_PTR(id)); > > + > > + if (to) > > + l_timeout_remove(to); > > } Applied, thanks. -- Luiz Augusto von Dentz