Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix handler list semaphore and constructor ordering #76

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tpwrules
Copy link

Avoids race conditions and crashes when adding/removing handler list items. See commits for details. Saves 1K flash on Cube Orange (as opposed to costing 2K if inlining isn't changed).

Needs testing on real hardware/applications.

Includes #75 .

tpwrules and others added 4 commits February 20, 2025 22:04
lcov 2.x, unlike lcov 1.x, gives errors like `geninfo: ERROR: mismatched
end line for _ZN12CRC_CRC_Test8TestBodyEv at
/home/runner/work/libcanard/libcanard/tests/test_crc.cpp:42: 42 -> 55`
for source files which contain gtest tests.

These files are removed from the coverage information in a later step,
but lcov now fails to create the initial coverage info because of them.

Fix this problem (and thus CI) by excluding the files from the initial
coverage info instead of removing them later. Note that the exclude
order is relevant to ensure all excludes trigger, avoiding errors that
some are unused. Verified that identical coverage stats are generated
for 2.x as compared to 1.x.
The Subscriber and Client subclasses need semaphores to protect their
static branch lists. The Subscriber previously had one, but it didn't do
anything because it wasn't static, and Client never had one.

Fix the issue by making the HandlerList semaphore protected and re-using
it.

Co-authored-by: Andrew Tridgell <andrew@tridgell.net>
The handler subclass must not exist in the handler list until after the
superclass constructor runs, and must be removed before the superclass
destructor runs. Outside of this time, the handler object identity is
the superclass, so a call to the handle_message method will cause a pure
virtual error and crash the program.

Fix the issue by adding/removing the object in the handler list in the
subclass when the vtable is set up right and the handle_message can
safely be called. Also wait until the branch list is set up so that the
handle_message method can actually find the object.

Co-authored-by: Andrew Tridgell <andrew@tridgell.net>
Mitigates flash impact of semaphore changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant