From: Ingo Molnar <mingo@elte.hu>
To: Eric Dumazet <eric.dumazet@gmail.com>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: "David S. Miller" <davem@davemloft.net>,
Linux Netdev List <netdev@vger.kernel.org>,
linux kernel <linux-kernel@vger.kernel.org>
Subject: Re: [RFC,PATCH] mutex: mutex_is_owner() helper
Date: Wed, 4 Nov 2009 16:40:15 +0100 [thread overview]
Message-ID: <20091104154015.GA32567@elte.hu> (raw)
In-Reply-To: <4AF19D06.3060401@gmail.com>
* Eric Dumazet <eric.dumazet@gmail.com> wrote:
> mutex_is_locked() is called most of the time to check if mutex is locked by current
> thread. But it's a lazy check, because mutex might be locked by another thread.
>
> Adds a new mutex_is_owned_by() helper, that can check ownership if CONFIG_SMP or
> CONFIG_DEBUG_MUTEXES are set.
>
> Returns are
> 0 if mutex is unlocked.
> 1 if locked
> -1 if not locked by designated thread.
>
> Last return value is possible only if CONFIG_SMP=y or CONFIG_DEBUG_MUTEXES=y
>
> Example of use :
>
> int rtnl_is_locked(void)
> {
> return mutex_is_locked(&rtnl_mutex);
> }
> ->
> int rtnl_is_locked(void)
> {
> return mutex_is_owned_by(&rtnl_mutex, current_thread_info()) == 1;
> }
To make sure this does not extend mutexes to be used a recursive
mutexes, mind naming it more clearly, like debug_mutex_is_owned(), and
adding a comment that says that this shouldnt be taken?
Also, it's somewhat imprecise: on !SMP && !DEBUG_MUTEXES we might return
a false '1'. Which happens to work for the rtnl usecase - but might not
in other cases.
Ingo
next prev parent reply other threads:[~2009-11-04 15:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-04 15:25 [RFC,PATCH] mutex: mutex_is_owner() helper Eric Dumazet
2009-11-04 15:40 ` Ingo Molnar [this message]
2009-11-04 17:19 ` Eric Dumazet
2009-11-09 18:56 ` Peter Zijlstra
2009-11-09 23:21 ` Eric Dumazet
2009-11-10 9:41 ` Peter Zijlstra
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=20091104154015.GA32567@elte.hu \
--to=mingo@elte.hu \
--cc=a.p.zijlstra@chello.nl \
--cc=davem@davemloft.net \
--cc=eric.dumazet@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/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;
as well as URLs for NNTP newsgroup(s).