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

chore: specialize Atomic<std::shared_ptr<T>> #5133

Merged
merged 2 commits into from
Jan 26, 2024

Conversation

Nerixyz
Copy link
Contributor

@Nerixyz Nerixyz commented Jan 26, 2024

Since #5128 refactors message parsing, it would be nice to do that off the main thread. To do this safely, we can utilize the Atomic class to provide shared state for workers (similar to the MessageLayoutContext).

C++ 20 added std::atomic<std::shared_ptr<T>>. Not every standard library implementation has added this yet, so it's behind an #ifdef. To ensure sane use, Atomic<std::shared_ptr<T>> requires T to be const (otherwise the atomic is kinda useless). Since only the MSVC STL and GCC libstdc++ implement this and ship in compiler versions that have concepts, it's fine to require these too.

Neither implementation is lock-free, but both are better than using a std::mutex (e.g. the implementation in the STL spins on a single bit compared to a mutex which uses a shared read-write lock).

@pajlada pajlada merged commit 5cd4c51 into Chatterino:master Jan 26, 2024
20 checks passed
@Nerixyz Nerixyz deleted the chore/specialize-atomic branch January 26, 2024 20:55
devJimmyboy pushed a commit to devJimmyboy/chatterino7 that referenced this pull request Feb 11, 2024
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