From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754636AbYEDHcR (ORCPT ); Sun, 4 May 2008 03:32:17 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751795AbYEDHcG (ORCPT ); Sun, 4 May 2008 03:32:06 -0400 Received: from web52003.mail.re2.yahoo.com ([206.190.49.250]:38013 "HELO web52003.mail.re2.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751722AbYEDHcE (ORCPT ); Sun, 4 May 2008 03:32:04 -0400 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:Cc:MIME-Version:Content-Type:Message-ID; b=Fmb39AMLJLAUZuWlK5fJb453H/Z1RW1BKGxdMoOj+2RO6E7KEOhcoVw2Vu8DN+hdn36oU/R8ALYgoXWbZoixwGHbgUjWDktqdQZ8NqJ67tDlX4g8Rb18Mcpfk05LNil22UmUDdOgePsSIaXlXhsTOHRjEIB2ZvBiCMlmo/1phoE=; X-YMail-OSG: sFPwT8cVM1lcRFXiR_mSQVD11In0VXkxhSkqVYqx.JJ6Ps9DTiLOfjEOBEuTUYnfzUxRJT.M50g7hV325Q5DeFrITru6DOfiKeGrRSOUZNNTkJ_s_e4FD3E_5Q-- X-Mailer: YahooMailRC/975.23 YahooMailWebService/0.7.185 Date: Sun, 4 May 2008 00:32:02 -0700 (PDT) From: Matti Linnanvuori Subject: [patch] doc: add a chapter about trylock functions [Bug 9011] To: bugme-daemon@kernel-bugs.osdl.org Cc: linux-kernel@vger.kernel.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Message-ID: <352345.60081.qm@web52003.mail.re2.yahoo.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matti Linnanvuori Add a chapter about trylock functions. http://bugzilla.kernel.org/show_bug.cgi?id=9011 Signed-off-by: Matti Linnanvuori --- --- 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 @@ + + The trylock Functions + + 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. + + + + spin_trylock() 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 spin_lock: you must have + disabled the contexts that might interrupt you and acquire the spin lock. + + + + mutex_trylock() 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. + + + + down_trylock() 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 + spin_trylock() and mutex_trylock() + . down_trylock can be used in all contexts. + + Common Examples ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756960AbYEOAat (ORCPT ); Wed, 14 May 2008 20:30:49 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754001AbYEOAaj (ORCPT ); Wed, 14 May 2008 20:30:39 -0400 Received: from ozlabs.org ([203.10.76.45]:55406 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750864AbYEOAaj (ORCPT ); Wed, 14 May 2008 20:30:39 -0400 From: Rusty Russell To: "Matti Linnanvuori" Subject: Re: [patch] doc: add a chapter about trylock functions [Bug 9011] Date: Thu, 15 May 2008 10:30:18 +1000 User-Agent: KMail/1.9.9 Cc: "Randy Dunlap" , "Andrew Morton" , Ingo Molnar , linux-kernel@vger.kernel.org References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200805151030.18959.rusty@rustcorp.com.au> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday 14 May 2008 01:31:47 Matti Linnanvuori wrote: > + mutex_trylock() 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. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756497AbYEPMWI (ORCPT ); Fri, 16 May 2008 08:22:08 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753582AbYEPMV4 (ORCPT ); Fri, 16 May 2008 08:21:56 -0400 Received: from pentafluge.infradead.org ([213.146.154.40]:38808 "EHLO pentafluge.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751966AbYEPMVz (ORCPT ); Fri, 16 May 2008 08:21:55 -0400 Subject: Re: [patch] doc: add a chapter about trylock functions [Bug 9011] From: Peter Zijlstra To: Rusty Russell Cc: Matti Linnanvuori , Randy Dunlap , Andrew Morton , Ingo Molnar , linux-kernel@vger.kernel.org In-Reply-To: <200805151030.18959.rusty@rustcorp.com.au> References: <200805151030.18959.rusty@rustcorp.com.au> Content-Type: text/plain Date: Fri, 16 May 2008 14:21:25 +0200 Message-Id: <1210940485.7886.29.camel@twins> Mime-Version: 1.0 X-Mailer: Evolution 2.22.1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2008-05-15 at 10:30 +1000, Rusty Russell wrote: > On Wednesday 14 May 2008 01:31:47 Matti Linnanvuori wrote: > > + mutex_trylock() 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?