This doesn't fully solve the issues with mutable statics in picodata/core. There are several more complex cases, as well as various usages in test code.
Usages of mutable statics are dangerous, because it's easy to create several simultaneous mutable references to them, which is instant UB. Most usages in the project are quite benign, but that also means that they are easy to refactor into a fully safe alternative, using either synchronization primitives or thread locals. Both of those solutions incur overhead on the order of several nanoseconds, which is negligible for our use cases. I use thread locals in cases where the contents are !Sync
, and thus cannot be put into a static.
This solves (some) of the warnings produced by the static_mut_refs
lint. Note that it becomes an error in the upcoming 2024 edition.
refactor: change metric&rpc handlers to use thread locals instead of static mut
refactor: change static mut PICO_SERVICE_PASSWORD to a Rc in thread local
refactor: don't use mutable statics in cas.rs
refactor: don't use static mut in GLOBAL_CONFIG
refactor: don't use static mut for ROOT logger and CLOCK cache
refactor: don't use static mut for STATIC_PROCS
refactor: replace some mutable statics with thread locals