From: Oleg Nesterov <oleg@tv-sign.ru>
To: Ingo Molnar <mingo@elte.hu>
Cc: lkml <linux-kernel@vger.kernel.org>,
Linus Torvalds <torvalds@osdl.org>, Andrew Morton <akpm@osdl.org>,
Arjan van de Ven <arjan@infradead.org>,
Nicolas Pitre <nico@cam.org>,
Jes Sorensen <jes@trained-monkey.org>,
Al Viro <viro@ftp.linux.org.uk>,
David Howells <dhowells@redhat.com>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
Christoph Hellwig <hch@infradead.org>, Andi Kleen <ak@suse.de>,
Russell King <rmk+lkml@arm.linux.org.uk>
Subject: Re: [patch 08/19] mutex subsystem, core
Date: Tue, 03 Jan 2006 21:00:24 +0300 [thread overview]
Message-ID: <43BABBB8.402E96A3@tv-sign.ru> (raw)
In-Reply-To: <20060103100807.GH23289@elte.hu>
Ingo Molnar wrote:
>
> mutex implementation, core files: just the basic subsystem, no users of it.
>
(on top of this patch)
'add_to_head' always declared and used along with 'struct waiter'.
I think it is better to hide 'add_to_head' in that struct.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
--- K/include/linux/mutex.h~1_HEAD 2006-01-03 22:35:10.000000000 +0300
+++ K/include/linux/mutex.h 2006-01-03 23:06:49.000000000 +0300
@@ -61,6 +61,7 @@ struct mutex {
* which resides on the blocked task's kernel stack:
*/
struct mutex_waiter {
+ int add_to_head;
struct list_head list;
struct thread_info *ti;
#ifdef CONFIG_DEBUG_MUTEXES
--- K/kernel/mutex.c~1_HEAD 2006-01-03 22:35:10.000000000 +0300
+++ K/kernel/mutex.c 2006-01-03 23:36:30.000000000 +0300
@@ -28,13 +28,19 @@
# include <asm/mutex.h>
#endif
+static inline void mutex_init_waiter(struct mutex_waiter *waiter)
+{
+ /* first time queue the waiter as FIFO: */
+ waiter->add_to_head = 0;
+}
+
/*
* Block on a lock - add ourselves to the list of waiters.
* Called with lock->wait_lock held.
*/
static inline void
add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
- struct thread_info *ti, int add_to_head __IP_DECL__)
+ struct thread_info *ti __IP_DECL__)
{
debug_mutex_add_waiter(lock, waiter, ti, ip);
@@ -44,10 +50,12 @@ add_waiter(struct mutex *lock, struct mu
* Add waiting tasks to the end of the waitqueue (FIFO),
* but add repeat waiters to the head (LIFO):
*/
- if (add_to_head)
+ if (waiter->add_to_head)
list_add(&waiter->list, &lock->wait_list);
else
list_add_tail(&waiter->list, &lock->wait_list);
+
+ waiter->add_to_head = 1;
}
/*
@@ -74,8 +82,8 @@ mutex_wakeup_waiter(struct mutex *lock _
*/
static inline int
__mutex_lock_common(struct mutex *lock, struct mutex_waiter *waiter,
- struct thread_info *ti, unsigned long task_state,
- const int add_to_head __IP_DECL__)
+ struct thread_info *ti, unsigned long task_state
+ __IP_DECL__)
{
struct task_struct *task = ti->task;
unsigned int old_val;
@@ -115,7 +123,7 @@ __mutex_lock_common(struct mutex *lock,
return 1;
}
- add_waiter(lock, waiter, ti, add_to_head __IP__);
+ add_waiter(lock, waiter, ti __IP__);
__set_task_state(task, task_state);
/*
@@ -133,19 +141,17 @@ static inline void __mutex_lock_nonatomi
{
struct thread_info *ti = current_thread_info();
struct mutex_waiter waiter;
- /* first time queue the waiter as FIFO: */
- int add_to_head = 0;
debug_mutex_init_waiter(&waiter);
+ mutex_init_waiter(&waiter);
+
spin_lock_mutex(&lock->wait_lock);
/* releases the internal lock: */
while (!__mutex_lock_common(lock, &waiter, ti,
- TASK_UNINTERRUPTIBLE, add_to_head __IP__)) {
+ TASK_UNINTERRUPTIBLE __IP__)) {
- /* start queueing the waiter as LIFO: */
- add_to_head = 1;
/* wait to be woken up: */
schedule();
@@ -162,23 +168,23 @@ __mutex_lock_interruptible_nonatomic(str
{
struct thread_info *ti = current_thread_info();
struct mutex_waiter waiter;
- int add_to_head = 0;
debug_mutex_init_waiter(&waiter);
+ mutex_init_waiter(&waiter);
+
spin_lock_mutex(&lock->wait_lock);
for (;;) {
/* releases the internal lock: */
if (__mutex_lock_common(lock, &waiter, ti,
- TASK_INTERRUPTIBLE, add_to_head __IP__))
+ TASK_INTERRUPTIBLE __IP__))
return 0;
/* break out on a signal: */
if (unlikely(signal_pending(ti->task)))
break;
- add_to_head = 1;
/* wait to be woken up: */
schedule();
next prev parent reply other threads:[~2006-01-03 16:44 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-03 10:08 Ingo Molnar
2006-01-03 13:15 ` Nick Piggin
2006-01-03 15:05 ` Ingo Molnar
2006-01-03 15:38 ` Linus Torvalds
2006-01-03 15:42 ` Ingo Molnar
2006-01-03 18:00 ` Oleg Nesterov [this message]
2006-01-03 16:49 ` Ingo Molnar
-- strict thread matches above, loose matches on Subject: below --
2006-01-03 16:46 Ingo Molnar
2006-01-03 15:58 Kai Geek
2006-01-02 16:34 Ingo Molnar
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=43BABBB8.402E96A3@tv-sign.ru \
--to=oleg@tv-sign.ru \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arjan@infradead.org \
--cc=dhowells@redhat.com \
--cc=hch@infradead.org \
--cc=jes@trained-monkey.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=nico@cam.org \
--cc=rmk+lkml@arm.linux.org.uk \
--cc=torvalds@osdl.org \
--cc=viro@ftp.linux.org.uk \
/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
all inboxes | Powered by JetHome®