Re: [PATCH v2 5/6] signal: sys_sigprocmask() needs retarget_shared_pending()

From: George Spelvin
Date: Tue Apr 26 2011 - 21:35:48 EST


> and notice how you now can do that helper function *WITHOUT* any
> conditionals, and just make it do
>
> sigprocmask(&clear, &set, NULL);
>
> which handles all cases correctly (just "andn clear" + "or set") with
> no if's or switch'es.

Gripe: Arrgh, apostrophe disease! Linus, youre picking up nasty habits.

Suggestion: Actually, the usual, more flexible implementation, is
"andn mask" + "xor set". That gives all 4 bit operations (nop, set,
clear, and toggle) unique bit combinations.

Not that it's of any use in many cases, but it has better hack value.

That would convert to:
switch (how) {
case SIG_BLOCK:
mask_bits = new_set;
set_bits = new_set;
break;
case SIG_UNBLOCK:
mask_bits = new_set;
set_bits = 0;
break
case SIG_SET:
mask_bits = low_bits | new_set;
set_bits = new_set;
break;
default:
return -EINVAL;
}

If you prefer separate set & clear fields, with both set meaning "toggle",
which admittedly is a more elegant representation, then it's
"andn (set|clear)" + "xor set".
--
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/