From: Mat Martineau <mathewm@codeaurora.org>
To: Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com>,
padovan@profusion.mobi
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH] Bluetooth: Simplify L2CAP timer logic
Date: Tue, 20 Mar 2012 11:39:00 -0700 (PDT) [thread overview]
Message-ID: <alpine.DEB.2.02.1203201119440.19427@mathewm-linux> (raw)
In-Reply-To: <1332247868-32396-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
On Tue, 20 Mar 2012, Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> Simplify L2CAP timers logic. Previous logic was hard to understand.
> Now we always hold(chan) when setting up timer and put(chan) only
> if work pending and we successfully cancel delayed work.
>
> If delayed work is executing it will put(chan) itself.
>
> Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> ---
> include/net/bluetooth/l2cap.h | 27 ++++++++++++++-------------
> 1 files changed, 14 insertions(+), 13 deletions(-)
>
> diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
> index 9b242c6..e4b2fe7 100644
> --- a/include/net/bluetooth/l2cap.h
> +++ b/include/net/bluetooth/l2cap.h
> @@ -621,29 +621,30 @@ static inline void l2cap_chan_unlock(struct l2cap_chan *chan)
> mutex_unlock(&chan->lock);
> }
>
> -static inline void l2cap_set_timer(struct l2cap_chan *chan,
> - struct delayed_work *work, long timeout)
> -{
> - BT_DBG("chan %p state %s timeout %ld", chan,
> - state_to_string(chan->state), timeout);
> -
> - if (!cancel_delayed_work(work))
> - l2cap_chan_hold(chan);
> - schedule_delayed_work(work, timeout);
> -}
> -
> static inline bool l2cap_clear_timer(struct l2cap_chan *chan,
> - struct delayed_work *work)
> + struct delayed_work *work)
> {
> bool ret;
>
> - ret = cancel_delayed_work(work);
> + ret = (delayed_work_pending(work) && cancel_delayed_work(work));
Why change this? cancel_delayed_work() can handle a delayed_work that
is not pending, and has the proper locking to guard against race
conditions.
> if (ret)
> l2cap_chan_put(chan);
>
> return ret;
> }
>
> +static inline void l2cap_set_timer(struct l2cap_chan *chan,
> + struct delayed_work *work, long timeout)
> +{
> + BT_DBG("chan %p state %s timeout %ld", chan,
> + state_to_string(chan->state), timeout);
> +
> + l2cap_clear_timer(chan, work);
> +
> + l2cap_chan_hold(chan);
> + schedule_delayed_work(work, timeout);
> +}
> +
> #define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t))
> #define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer)
> #define __set_retrans_timer(c) l2cap_set_timer(c, &c->retrans_timer, \
--
Mat Martineau
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
next prev parent reply other threads:[~2012-03-20 18:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-20 12:51 [PATCH] Bluetooth: Simplify L2CAP timer logic Andrei Emeltchenko
2012-03-20 13:26 ` Gustavo Padovan
2012-03-20 18:39 ` Mat Martineau [this message]
2012-03-20 19:56 ` Ulisses Furquim
2012-03-21 8:15 ` Andrei Emeltchenko
2012-03-22 19:00 ` Ulisses Furquim
2012-03-23 14:33 ` Andrei Emeltchenko
2012-03-23 22:10 ` Ulisses Furquim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.02.1203201119440.19427@mathewm-linux \
--to=mathewm@codeaurora.org \
--cc=Andrei.Emeltchenko.news@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=padovan@profusion.mobi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox