Skip to content

Conversation

@cbjeukendrup
Copy link
Member

@cbjeukendrup cbjeukendrup commented Oct 26, 2025

99% of all Inject instances are accessed from one thread only, so no mutex is necessary at all.

For the few cases where a thread-safe Inject is necessary, this introduces ThreadSafeInject, which has its own mutex, rather than a global static one, which (I think) is better for performance, and avoids the need for a recursive mutex.

Closes #23805, which was never merged because we were not convinced enough of the practical need for it.

@cbjeukendrup cbjeukendrup force-pushed the inject_threadsafeinject branch from eb879cf to e0d9a7d Compare October 28, 2025 16:12
@cbjeukendrup cbjeukendrup changed the title Remove mutex from Inject and introduce ThreadSafeInject Make Inject non-lazy and thread-safe, and introduce LazyInject Oct 28, 2025
Comment on lines -95 to -98
namespace mu {
template<class I>
using Inject = kors::modularity::Inject<I>;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe this removal is a bit bold, but I think it's not good to reference mu namespace in framework, and typing muse:: is easy enough

99.999999% of all Inject instances are accessed from one thread only, so no mutex is necessary at all. 

For the few (yet to be discovered) cases where a thread-safe Inject *is* necessary, this introduces `ThreadSafeInject`, which has its own mutex, rather than a global static one, which (I think) is better for performance, and avoids the need for a recursive mutex.
@cbjeukendrup cbjeukendrup force-pushed the inject_threadsafeinject branch from e0d9a7d to 13fe622 Compare November 2, 2025 21:53
@cbjeukendrup cbjeukendrup changed the title Make Inject non-lazy and thread-safe, and introduce LazyInject Remove mutex from Inject and introduce ThreadSafeInject Nov 3, 2025
@igorkorsukov igorkorsukov merged commit 117cbc6 into musescore:master Nov 3, 2025
12 checks passed
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