veeenu / hudhook

A videogame overlay framework written in Rust, supporting DirectX and OpenGL
MIT License
207 stars 30 forks source link

Review concurrency to address `static_mut_refs` lint #205

Open veeenu opened 1 month ago

veeenu commented 1 month ago

There is a new lint in nightly Clippy, static_mut_refs that is currently breaking our builds.

I wholeheartedly agree with it, I never liked having to have static mutables but unfortunately that seems to be a ubiquitous requirement for hudhook's use case.

So far, I haven't seen any reports to suggest that hudhook's clients willingly use more than one thread, and in the meantime I discovered that dear imgui itself is not thread safe.

For the time being, I will disable the lint to keep the project moving, but before long I want to evaluate different ways of managing the global state.

One possible avenue would be to move everything to Mutexes and just confine the imgui::Context into a static mut in pipeline.rs. This would add overhead in theory, though if everything keeps running from the same thread I don't see it being that impactful. Pipeline would then be the only entity responsible for passing &mut Context references around, so we can sort of stitch some form of ownership around it via other synchronization mechanisms.

Another possibility would be using thread locals but that would still require us to use mutable statics so it's not really a solution to our problem.

veeenu commented 1 month ago