Skip to contentSkip to conversation

docbook: some kernel-locking fixes

PATCH In review Randy Dunlap 2 participants 2 messages Apr 2, 2008 – Apr 3, 2008 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 docbook: some kernel-locking fixes

From: Matti Linnanvuori <[email protected]>

Fix a wrong path. Add a chapter about try functions.

http://bugzilla.kernel.org/show_bug.cgi?id=9011

---
 Documentation/DocBook/kernel-locking.tmpl |   25 +++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
Documentation/DocBook/kernel-locking.tmpl +24 -1
@@ -290,7 +290,7 @@
      <para>
        If you have a data structure which is only ever accessed from
        user context, then you can use a simple semaphore
-       (<filename>linux/asm/semaphore.h</filename>) to protect it.  This 
+       (<filename>include/asm/semaphore.h</filename>) to protect it.  This
        is the most trivial case: you initialize the semaphore to the number 
        of resources available (usually 1), and call
        <function>down_interruptible()</function> to grab the semaphore, and 
@@ -703,6 +703,29 @@
 </sect1>
 </chapter>
 
+<chapter id="try-variants">
+ <title>The try variants</title>
+
+  <para>
+    <function>spin_trylock()</function> does not spin but returns non-zero if
+    it acquires the spinlock on the first try or 0 if not.
+  </para>
+
+  <para>
+    <function>mutex_trylock()</function> does not suspend your task
+    but returns non-zero if it could lock the mutex on the first try
+    or 0 if not.
+  </para>
+
+  <para>
+    <function>down_trylock()</function> does not suspend your task
+    but returns 0 if it could get the semaphore on the first try or
+    non-zero if not. The return value is the inverse of that of
+    <function>spin_trylock()</function> and <function>mutex_trylock()
+    </function>.
+  </para>
+</chapter>
+
   <chapter id="Examples">
    <title>Common Examples</title>
     <para>

---

#1 lore raw
Quoted 13 lines · On Thursday 03 April 2008 07:47:50 Randy Dunlap wrote:

From: Matti Linnanvuori <[email protected]> +<chapter id="try-variants">
+ <title>The try variants</title>

Documentation/DocBook/kernel-locking.tmpl +10 -0
+
+  <para>
+    <function>spin_trylock()</function> does not spin but returns non-zero
+    if it acquires the spinlock on the first try or 0 if not.
+  </para>
+
+  <para>
+    <function>mutex_trylock()</function> does not suspend your task
+    but returns non-zero if it could lock the mutex on the first try
+    or 0 if not.

Documentation/DocBook/kernel-locking.tmpl line 727

Quoted 10 lines
Documentation/DocBook/kernel-locking.tmpl +10 -0
+  </para>
+
+  <para>
+    <function>down_trylock()</function> does not suspend your task
+    but returns 0 if it could get the semaphore on the first try or
+    non-zero if not. The return value is the inverse of that of
+    <function>spin_trylock()</function> and <function>mutex_trylock()
+    </function>.
+  </para>
+</chapter>

OK, other than documenting the inconsistent horror of down_trylock, I don't like this patch. This document is not about documenting the functions, but providing an overview and pointing to them (where you can read to your heart's content).

This is a worthy addition, but it's a paragraph, not a chapter. Unless you want to document why you would use the trylock variants (can mutex_trylock and down_trylock be used from interrupt context? Or are they only useful to avoid deadlock? How are they actually used in the kernel?)

Thanks,
Rusty.