Page MenuHomeFreeBSD

sound: Safely remove channel from list in one pass.
AcceptedPublic

Authored by dev_submerge.ch on Thu, Dec 26, 11:38 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Jan 3, 6:04 AM
Unknown Object (File)
Wed, Jan 1, 6:40 PM
Unknown Object (File)
Mon, Dec 30, 11:18 AM
Unknown Object (File)
Thu, Dec 26, 11:58 PM
Unknown Object (File)
Thu, Dec 26, 11:58 PM
Subscribers

Details

Summary

The CHN_REMOVE_SAFE() macro did two traversals of the channel list to
remove a channel, one to check whether the channel is an element of the
list, and a second traversal through SLIST_REMOVE(). Reduce this to one
traversal, while still preventing a NULL dereference in case the channel
in question is not present in the list.

While here, rename the macro arguments to something more descriptive.

MFC after: 1 week

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 61339
Build 58223: arc lint + arc unit

Event Timeline

I stumbled upon that repeated list traversal when reviewing D48185. The implementation is roughly based on SLIST_REMOVE(). Compared to CHN_REMOVE(), the difference in performance should be only minuscule, doing one additional NULL pointer check per iteration. Therefore we may want to consider using the safe variant everywhere.

Renaming the macro arguments improves readability a lot for me, but I'm open for suggestions. I tried to take a hint or two from the SLIST_*() macros.

LGTM. I was also about to recommend using the safe variant throughout sound(4), and just saw you mentioned it here as well. It's a good idea IMHO.

This revision is now accepted and ready to land.Fri, Dec 27, 7:40 PM