Skip to contentSkip to conversation

signal: sys_sigprocmask() needs retarget_shared_pending()

PATCH George Spelvin 2 participants 2 messages Apr 27, 2011

lore
Share & tools
lore
#0 lore raw
Quoted 7 lines

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".

#1 lore raw
Quoted 5 lines · George Spelvin
Quoted 3 lines

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.

I didn't want to make C keywords into English words. So if it's about English words it's "no ifs or buts", but when talking about C keywords it's "if's or switch'es".

That's my stand, and I'll stick to it. At least until next time, when I might decide on yet another arbitrary rule ;)

Quoted 3 lines

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.

Yeah, we can do that too. I agree it is more flexible, although I don't think we'd ever need it.

And I'm not sure it's more "usual" - most drivers I've seen (where this kind of "clear/set mask" issue comes up pretty often) tend to use the simpler clear/set model, because it tends to make the usage more sensible. Most users simply don't tend to need the toggle operation.

But my grep-fu to actually show examples is weak. One example I found would be

- drivers/media/video/tw9910.c: tw9910_mask_set()

which uses that "andnot + or" model I suggested.

But I'm sure there are "andnot + xor" uses out there too.

And I don't actually mind either way. I'd certainly be perfectly ok with the andn/xor model. It's just the "how" model I detest.

Linus