All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] doc: add a chapter about trylock functions [Bug 9011]
@ 2008-05-04  7:32 Matti Linnanvuori
  0 siblings, 0 replies; 3+ messages in thread
From: Matti Linnanvuori @ 2008-05-04  7:32 UTC (permalink / raw)
  To: bugme-daemon; +Cc: linux-kernel

From: Matti Linnanvuori <mattilinnanvuori@yahoo.com>
 
Add a chapter about trylock functions.
http://bugzilla.kernel.org/show_bug.cgi?id=9011
 
Signed-off-by: Matti Linnanvuori <mattilinnanvuori@yahoo.com>
 
---
 
--- 
linux-2.6/Documentation/DocBook/kernel-locking.tmpl 2008-05-04 
09:22:20.782075500 +0300
+++ 
linux/Documentation/DocBook/kernel-locking.tmpl 2008-05-04 10:13:16.168549500 
+0300
@@ -702,6 +702,38 
@@
 
 </sect1>
 </chapter>
+<chapter 
id="trylock-functions">
+ <title>The trylock 
Functions</title>
+  <para>
+   There are functions that try 
to acquire a lock only once and immediately
+   return a value telling about 
success or failure to acquire the lock.
+   They can be used if you need no 
access to the data protected with the lock
+   when some other thread is 
holding the lock. You should acquire the lock
+   later if you then need 
access to the data protected with the lock.
+  </para>
+
+  
<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. This function can
+    be used in all contexts like 
<function>spin_lock</function>: you must have
+    disabled the 
contexts that might interrupt you and acquire the spin lock.
+  
</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. This function cannot be safely used in hardware or 
software 
+    interrupt contexts despite not sleeping.
+  
</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>. 
<function>down_trylock</function> can be used in all contexts.
+  
</para>
+</chapter>
 
   <chapter 
id="Examples">
    <title>Common 
Examples</title>



      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] doc: add a chapter about trylock functions [Bug 9011]
       [not found] <ca0148c30805130831h11fe0ca0qf501bd07d1141940@mail.gmail.com>
@ 2008-05-15  0:30 ` Rusty Russell
  2008-05-16 12:21   ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: Rusty Russell @ 2008-05-15  0:30 UTC (permalink / raw)
  To: Matti Linnanvuori; +Cc: Randy Dunlap, Andrew Morton, Ingo Molnar, linux-kernel

On Wednesday 14 May 2008 01:31:47 Matti Linnanvuori wrote:
> +    <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. This function cannot be safely used in hardware or
> +    software interrupt contexts despite not sleeping.

I know this is what the documentation says, but I can't see why.  Ingo?

Thanks,
Rusty.
PS. Patch fixed up and applied.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] doc: add a chapter about trylock functions [Bug 9011]
  2008-05-15  0:30 ` [patch] doc: add a chapter about trylock functions [Bug 9011] Rusty Russell
@ 2008-05-16 12:21   ` Peter Zijlstra
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2008-05-16 12:21 UTC (permalink / raw)
  To: Rusty Russell
  Cc: Matti Linnanvuori, Randy Dunlap, Andrew Morton, Ingo Molnar,
	linux-kernel

On Thu, 2008-05-15 at 10:30 +1000, Rusty Russell wrote:
> On Wednesday 14 May 2008 01:31:47 Matti Linnanvuori wrote:
> > +    <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. This function cannot be safely used in hardware or
> > +    software interrupt contexts despite not sleeping.
> 
> I know this is what the documentation says, but I can't see why.  Ingo?

because who would then own the lock?


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-05-16 12:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <ca0148c30805130831h11fe0ca0qf501bd07d1141940@mail.gmail.com>
2008-05-15  0:30 ` [patch] doc: add a chapter about trylock functions [Bug 9011] Rusty Russell
2008-05-16 12:21   ` Peter Zijlstra
2008-05-04  7:32 Matti Linnanvuori

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.