Re: [PATCH 2/3] core: Convert printk_once to use DO_ONCE

From: Steven Rostedt
Date: Wed Oct 16 2013 - 08:59:49 EST


On Wed, 16 Oct 2013 13:53:56 +0200
Frederic Weisbecker <fweisbec@xxxxxxxxx> wrote:


> static int done;
>
> if (!done) {
> trace_printk(something);
> trace_printk(something else);
> trace_dump_stack();
> done = 1;
> }
>
> Having a DO_ONCE() would help a lot I think.
>
> Now we can rename it to __DO_ONCE() and put a big fat comment to avoid it
> to be misused.

I wonder if we should make it just ONCE(), with no arguments that
should go into an if statement.


if (ONCE())
do_this_function_once();


Where ONCE() is:

({
static int __once;
int __old_once = __once;

__once = 1;
__old_once;
})

Or the xchg version:

({
static int __once;

if (!__once)
xchg(&__once, 1);
else
1;
})

-- Steve
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/