[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20091104154015.GA32567@elte.hu>
Date: Wed, 4 Nov 2009 16:40:15 +0100
From: Ingo Molnar <mingo@...e.hu>
To: Eric Dumazet <eric.dumazet@...il.com>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Linus Torvalds <torvalds@...ux-foundation.org>
Cc: "David S. Miller" <davem@...emloft.net>,
Linux Netdev List <netdev@...r.kernel.org>,
linux kernel <linux-kernel@...r.kernel.org>
Subject: Re: [RFC,PATCH] mutex: mutex_is_owner() helper
* Eric Dumazet <eric.dumazet@...il.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
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists