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

Remove static muts from logging package #175

Merged
merged 1 commit into from
Nov 11, 2024
Merged

Conversation

mciantyre
Copy link
Member

Upcoming clippy versions have more aggressive warnings about static mut, so I'm removing them from the logging package. The defmt frontend uses a custom static with interior mutability. The implementation is otherwise the same.

I refactored the rest of the package to use &'static muts produced by the static_cell package. This lets us remove the explicit uninitialized memory and the mutable statics. The details are unchanged.

Tested the rtic_logging example on an 1170EVK: logging frontend with both backends, and the defmt frontend with just the LPUART frontend.

Upcoming clippy versions have more agressive warnings about static mut,
so I'm removing them from the logging package. The defmt frontend uses a
custom static with interior mutability. The implementation is otherwise
the same.

I refactored the rest of the package to use `&'static mut`s produced by
the static_cell package. This lets us remove the explicit uninitialized
memory and the mutable statics. The details are unchanged.

Tested the rtic_logging example on an 1170EVK: logging frontend with
both backends, and the defmt frontend with just the LPUART frontend.
Copy link
Member

@teburd teburd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks quite clean for the most part, and removing the statics seems to have made things nicer.

The enum and match done with Inner in Poller feels like it should be a generic parameter off hand, and not something I really looked hard at before. But I guess if you want to, at run time, switch from uart to usb cdc it makes sense, though most of the time I'd think this is a compile time decision to make?

@mciantyre
Copy link
Member Author

It could be a compile-time decision, and most examples in this repo demonstrate backend selection based on a constant. But by representing a Poller with runtime dispatch, we enable a use-case where programs can select a logging backend during start-up (read a config from storage, check a GPIO, etc). These users don't need to propagate a backend type state around their interfaces.

Base automatically changed from doc-unsafe to main November 11, 2024 13:27
@mciantyre mciantyre merged commit 9ec1e55 into main Nov 11, 2024
62 checks passed
@mciantyre mciantyre deleted the logging-static-muts branch November 11, 2024 13:28
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.

2 participants