Page MenuHomeFreeBSD

signal: Add SIG_FOREACH and refactor issignal()
ClosedPublic

Authored by markj on Oct 12 2021, 9:10 PM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 19 2024, 10:10 PM
Unknown Object (File)
Feb 14 2024, 5:39 PM
Unknown Object (File)
Feb 10 2024, 9:38 PM
Unknown Object (File)
Feb 10 2024, 1:00 AM
Unknown Object (File)
Dec 20 2023, 7:22 AM
Unknown Object (File)
Dec 14 2023, 3:33 PM
Unknown Object (File)
Nov 5 2023, 3:53 PM
Unknown Object (File)
Oct 30 2023, 10:50 PM
Subscribers

Details

Summary

Add a SIG_FOREACH macro that can be used to iterate over a signal set.
This is a bit cleaner and more efficient than calling sig_ffs() in a
loop. The implementation is based on BIT_FOREACH_ISSET(), except
that the bitset limbs are always 32 bits wide, and signal sets are
1-indexed rather than 0-indexed like bitset(9) sets.

issignal() cannot really be modified to use SIG_FOREACH() directly.
Take this opportunity to split the function into two explicit loops.
I've always found this function hard to read and think that this change
is an improvement. The inner body of issignal() is unchanged, except
that sigprop() is only called when needed now.

Remove sig_ffs(), nothing uses it now.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 42094
Build 38982: arc lint + arc unit

Event Timeline

markj requested review of this revision.Oct 12 2021, 9:10 PM
sys/kern/kern_sig.c
3157

Isn't break equivalent to goto next there. Then this switch is same as the switch inside P_TRACED block above. Then, could you replace sigpending with a mask consisting only of SIGSTOP and use one switch?

sys/kern/kern_sig.c
3157

Oops, I had such a change stashed and forgot to add it. Yes, it is possible to merge the switch statements.

sys/kern/kern_sig.c
3157

Still please either use break in HANDLED case, or goto next in NEXT.

sys/kern/kern_sig.c
3157

break and goto next are not equivalent here. goto next reloads the sigpending set from the thread+process. "break" continues iteration within the already loaded sigpending set. SIGSTATUS_NEXT is returned only when nothing was done and the proc lock was not dropped.

sys/kern/kern_sig.c
3084

I suggest to move both sigqueue_delete calls to getsignal(), and replace all 'goto next' in this function by return (SIGSTATUS_NEXT);. Also I think that SIGSTATUS_NEXT is better named SIGSTATUS_IGNORE

3100

Why not call this function issignal? Then you do not need to change cursig() and it makes one less thing to track between older and newer branches.

markj marked 2 inline comments as done.

Apply feedback:

  • Remove the signal from td/proc sets in the outer function
  • SIGSTATUS_NEXT -> _IGNORE
  • Rename back to issignal(), the helper function is called sigprocess()
This revision is now accepted and ready to land.Oct 13 2021, 3:11 PM