linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: linux-iio <linux-iio@vger.kernel.org>,
	Jonathan Cameron <jic23@kernel.org>,
	Peter Meerwald <pmeerw@pmeerw.net>
Subject: Re: atomic use is not atomic?
Date: Tue, 8 Jun 2021 15:22:50 +0200	[thread overview]
Message-ID: <b79edabf-593f-81d3-0954-0557a7f73e57@metafoo.de> (raw)
In-Reply-To: <CAHp75VeC=trDNkhYbMpeCOYVRK124HPJNVX=tWmfy1Jh5akOzw@mail.gmail.com>

On 6/8/21 3:14 PM, Andy Shevchenko wrote:
> On Tue, Jun 8, 2021 at 3:44 PM Lars-Peter Clausen <lars@metafoo.de> wrote:
>> On 6/8/21 2:35 PM, Andy Shevchenko wrote:
>>> Hi!
>>>
>>> Can anybody explain this code [1] in terms of atomicity?
>>>
>>>     if (!atomic_read(&trig->use_count)) {
>>>       atomic_set(&trig->use_count, CONFIG_IIO_CONSUMERS_PER_TRIGGER);
>>>       ...
>>>     }
>>>
>>> AFAIU how atomics are supposed to work the above doesn't do anything
>>> atomically. I.o.w. use_count may be simple int with the same effect.
>>>
>> The operations here do not require atomic access, it is just operating
>> on a atomic type. The atomic access is the atomic_dec_and_test() in
>> iio_trigger_notify_done().
> So, between atomic_read and atomic_set somebody can call
> atomic_dec_and_test(), for example. Is it a problem to actually lose
> the value?
> Why are atomic types being used here when there is no atomicity guaranteed?

We know that if the value is zero that there are no more active 
consumers. Then we set the value to the number of consumers, and then 
launch the consumers, which will decrement the counter once they are done.


  reply	other threads:[~2021-06-08 13:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08 12:35 atomic use is not atomic? Andy Shevchenko
2021-06-08 12:44 ` Lars-Peter Clausen
2021-06-08 13:14   ` Andy Shevchenko
2021-06-08 13:22     ` Lars-Peter Clausen [this message]
2021-06-08 13:30       ` Andy Shevchenko
2021-06-08 16:00         ` Jonathan Cameron

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=b79edabf-593f-81d3-0954-0557a7f73e57@metafoo.de \
    --to=lars@metafoo.de \
    --cc=andy.shevchenko@gmail.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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;
as well as URLs for NNTP newsgroup(s).