From: Daniel Walker <dwalker@mvista.com>
To: akpm@linux-foundation.org
Cc: mingo@elte.hu, linux-kernel@vger.kernel.org, linux@bohmer.net,
jonathan@jonmasters.org, matthias.kaehlcke@gmail.com,
kjwinchester@gmail.com, minyard@acm.org
Subject: [PATCH 3/4] docs: convert kref semaphore to mutex
Date: Fri, 21 Dec 2007 00:00:03 -0800 [thread overview]
Message-ID: <20071221205859.010632996@mvista.com> (raw)
In-Reply-To: 20071221205848.989157559@mvista.com
[-- Attachment #1: docs-kref-remove-semaphore-reference.patch --]
[-- Type: text/plain, Size: 2033 bytes --]
Just converting this documentation semaphore reference, since we don't
want to promote semaphore usage.
Signed-off-by: Daniel Walker <dwalker@mvista.com>
---
Documentation/kref.txt | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
Index: linux-2.6.23/Documentation/kref.txt
===================================================================
--- linux-2.6.23.orig/Documentation/kref.txt
+++ linux-2.6.23/Documentation/kref.txt
@@ -141,10 +141,10 @@ The last rule (rule 3) is the nastiest o
instance, you have a list of items that are each kref-ed, and you wish
to get the first one. You can't just pull the first item off the list
and kref_get() it. That violates rule 3 because you are not already
-holding a valid pointer. You must add locks or semaphores. For
-instance:
+holding a valid pointer. You must add a mutex (or some other lock).
+For instance:
-static DECLARE_MUTEX(sem);
+static DEFINE_MUTEX(mutex);
static LIST_HEAD(q);
struct my_data
{
@@ -155,12 +155,12 @@ struct my_data
static struct my_data *get_entry()
{
struct my_data *entry = NULL;
- down(&sem);
+ mutex_lock(&mutex);
if (!list_empty(&q)) {
entry = container_of(q.next, struct my_q_entry, link);
kref_get(&entry->refcount);
}
- up(&sem);
+ mutex_unlock(&mutex);
return entry;
}
@@ -174,9 +174,9 @@ static void release_entry(struct kref *r
static void put_entry(struct my_data *entry)
{
- down(&sem);
+ mutex_lock(&mutex);
kref_put(&entry->refcount, release_entry);
- up(&sem);
+ mutex_unlock(&mutex);
}
The kref_put() return value is useful if you do not want to hold the
@@ -191,13 +191,13 @@ static void release_entry(struct kref *r
static void put_entry(struct my_data *entry)
{
- down(&sem);
+ mutex_lock(&mutex);
if (kref_put(&entry->refcount, release_entry)) {
list_del(&entry->link);
- up(&sem);
+ mutex_unlock(&mutex);
kfree(entry);
} else
- up(&sem);
+ mutex_unlock(&mutex);
}
This is really more useful if you have to call other routines as part
--
next prev parent reply other threads:[~2007-12-21 21:13 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20071221205848.989157559@mvista.com>
2007-12-21 8:00 ` [PATCH 1/4] usb microtek: remove unused semaphore Daniel Walker
2007-12-21 8:00 ` [PATCH 2/4] prism54: remove questionable down_interruptible usage Daniel Walker
2007-12-21 8:00 ` Daniel Walker [this message]
2007-12-21 21:33 ` [PATCH 3/4] docs: convert kref semaphore to mutex Corey Minyard
2007-12-21 8:00 ` [PATCH 4/4] usb: libusual: locking cleanup Daniel Walker
2007-12-22 4:22 ` Andrew Morton
2007-12-22 6:24 ` Pete Zaitcev
2007-12-22 6:31 ` Andrew Morton
2007-12-22 17:01 ` Daniel Walker
2007-12-23 7:37 ` Pete Zaitcev
2007-12-23 16:46 ` Daniel Walker
2007-12-24 14:12 ` Pete Zaitcev
2007-12-24 16:04 ` Daniel Walker
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=20071221205859.010632996@mvista.com \
--to=dwalker@mvista.com \
--cc=akpm@linux-foundation.org \
--cc=jonathan@jonmasters.org \
--cc=kjwinchester@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@bohmer.net \
--cc=matthias.kaehlcke@gmail.com \
--cc=mingo@elte.hu \
--cc=minyard@acm.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