Results 1 to 4 of 4
Hi all.
Throughout the kernel I keep on finding code like this:
Code:
include/linux/preempt.h
46 #define preempt_enable()
47 do {
48 preempt_enable_no_resched();
49 preempt_check_resched();
50 } while (0)
why is ...
- 08-04-2011 #1Just Joined!
- Join Date
- Jan 2008
- Posts
- 13
I don't understand why the kernel contains code like this.
Hi all.
Throughout the kernel I keep on finding code like this:
why is this within a do-while loop, even though its expression is evaluated to false. This code will only execute once.Code:include/linux/preempt.h 46 #define preempt_enable() 47 do { 48 preempt_enable_no_resched(); 49 preempt_check_resched(); 50 } while (0)
Really weird. Could it redundant code? i.e the programmers couldn't be bothered to remove the do while? or could it be for testing etc.
Thanks.
- 08-05-2011 #2
Have a look at this pdf. Page 4 seems to be relavent.
If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.
- 08-05-2011 #3Linux Newbie
- Join Date
- Mar 2010
- Posts
- 121
This is a fairly common way to define a macro, since it means the macro avoids several pitfalls of macros. Since all the macro code is within a block, it can go anywhere a single statement can, and since it requires a semicolon after it, it does not confuse some language constructs. It's basically a way for a macro to safely masquerade as a function call.
See this helpful page for details.
- 08-05-2011 #4
Excellent link. Thanks.
If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.


Reply With Quote
