From: Roger Larsson <roger.larsson@norran.net>
To: Philipp Rumpf <prumpf@parcelfarce.linux.theplanet.co.uk>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: *_trylock return on success?
Date: Sat, 25 Nov 2000 20:03:49 +0100 [thread overview]
Message-ID: <00112520034902.01122@dox> (raw)
In-Reply-To: <00112516072500.01122@dox> <Pine.LNX.4.21.0011251547210.8818-100000@duckman.distro.conectiva> <20001125183036.Q2272@parcelfarce.linux.theplanet.co.uk>
In-Reply-To: <20001125183036.Q2272@parcelfarce.linux.theplanet.co.uk>
On Saturday 25 November 2000 19:30, Philipp Rumpf wrote:
> On Sat, Nov 25, 2000 at 03:49:25PM -0200, Rik van Riel wrote:
> > On Sat, 25 Nov 2000, Roger Larsson wrote:
> > > Questions:
> > > What are _trylocks supposed to return?
> >
> > It depends on the type of _trylock ;(
> >
> > > Does spin_trylock and down_trylock behave differently?
> > > Why isn't the expected return value documented?
> >
> > The whole trylock stuff is, IMHO, a big mess. When you
> > change from one type of trylock to another, you may be
> > forced to invert the logic of your code since the return
> > code from the different locks is different.
> >
> > For bitflags, for example, the trylock returns the state
> > the bit had before the lock (ie. 1 if the thing was already
> > locked).
>
> I assume you're talking about test_and_{set,clear}_bit here. Their return
> value isn't consistent with the other _trylock functions since they're not
> _trylock functions.
>
> I think the real problem is that people use test_and_set_bit for locks,
> which is almost never[1] a good idea. The overhead for a semaphore
> shouldn't be too much in most cases, and that way it is obvious what you
> want to do - and, hopefully, even more obvious if you end up with a
> semaphore that can be turned into a spinlock without further changes.
>
> > For spinlocks, it'll probably return something else ;/
>
> _trylock functions return 0 for success.
Not spin_trylock
Simple example code from
code from include/asm-mips/spinlock.h:65
#define spin_trylock(lock) (!test_and_set_bit(0,(lock)))
/RogerL
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> Please read the FAQ at http://www.tux.org/lkml/
--
--
Home page:
http://www.norran.net/nra02596/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2000-11-25 19:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-11-25 15:07 *_trylock return on success? Roger Larsson
2000-11-25 17:49 ` Rik van Riel
2000-11-25 18:30 ` Philipp Rumpf
2000-11-25 19:03 ` Roger Larsson [this message]
2000-11-25 19:22 ` Philipp Rumpf
2000-11-25 21:05 ` Roger Larsson
2000-11-28 1:07 ` Roger Larsson
2000-11-25 18:58 ` Roger Larsson
-- strict thread matches above, loose matches on Subject: below --
2000-12-04 19:46 george anzinger
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=00112520034902.01122@dox \
--to=roger.larsson@norran.net \
--cc=linux-kernel@vger.kernel.org \
--cc=prumpf@parcelfarce.linux.theplanet.co.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 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.