Re: [PATCH 1/3] kernel.h: Add DO_ONCE statement expression macro

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 22 May 2009 08:30:22 am Joe Perches wrote:
> Add a DO_ONCE statement expression analogous to printk_once
> that executes any arbitrary statement exactly once.
>
> This will take the place of printk_once so that
> DO_ONCE(pr_<foo>) or any other statement performed
> a single time may be easily written.

If you're going to use a statement expression, was the intent to make
it usable for a test?  If so, you want something vaguely like:

#define DO_ONCE(x...) ({			\
	static bool __done = false;		\
	bool did = !__done;			\
	if (!__done) {				\
		x;				\
		__done = true;			\
	}					\
	did;					\
})

Otherwise, why not just use a normal do {} while (0) ?

Anyway, statements in macros leave me uncomfortable. I prefer explicit
ONCE() macro which can be tested.

Cheers,
Rusty.
--
To unsubscribe from this list: send the line "unsubscribe cpufreq" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Devel]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Forum]     [Linux SCSI]

  Powered by Linux