lkml.org 
[lkml]   [2019]   [Sep]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: numlist_pop(): Re: [RFC PATCH v4 1/9] printk-rb: add a new printk ringbuffer implementation
On Tue, Aug 20, 2019 at 10:15:18AM +0200, Petr Mladek wrote:

> do {
> tail_id = atomic_long_read(&nl->tail_id);
>
> /*
> * Read might fail when the tail node has been removed
> * and reused in parallel.
> */
> if (!numlist_read(nl, tail_id, NULL, &next_id))
> continue;
>
> /* Make sure the node is not the only node on the list. */
> if (next_id == tail_id)
> return NULL;
>
> /* cC: Make sure the node is not busy. */
> if (nl->busy(tail_id, nl->busy_arg))
> return NULL;
>
> while (atomic_long_cmpxchg_relaxed(&nl->tail_id, tail_id, next_id) !=
> tail_id);

Both you and John should have a look at atomic*_try_cmpxchg*(); with
that you can write the above as:

tail_id = atomic_long_read(&nl->tai_id);
do {
...
} while (!atomic_long_try_cmpxchg_relaxed(&nl->tail_id, &tail_id, next_id));

And get better code-gen to boot.

\
 
 \ /
  Last update: 2019-09-04 14:20    [W:0.196 / U:0.696 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site