-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add methods to provide on spawn and on finish tasks to thread pool builder #54
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Most looks good, just one little nitpick.
For consistency, we always use explicit generic instead of "impl Trait in argument position" in spdlog-rs
.
spdlog/src/thread_pool.rs
Outdated
/// Provide a function that will be called on each thread of the thread pool | ||
/// immediately after it is spawned. This can, for example, be used to set | ||
/// core affinity for each thread. | ||
pub fn on_thread_spawn(&mut self, f: impl Fn() + Send + Sync + 'static) -> &mut Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn on_thread_spawn(&mut self, f: impl Fn() + Send + Sync + 'static) -> &mut Self { | |
pub fn on_thread_spawn<F>(&mut self, f: F) -> &mut Self | |
where | |
F: Fn() + Send + Sync + 'static | |
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
spdlog/src/thread_pool.rs
Outdated
|
||
/// Provide a function that will be called on each thread of the thread pool | ||
/// just before the thread finishes. | ||
pub fn on_thread_finish(&mut self, f: impl Fn() + Send + Sync + 'static) -> &mut Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn on_thread_finish(&mut self, f: impl Fn() + Send + Sync + 'static) -> &mut Self { | |
pub fn on_thread_finish<F>(&mut self, f: F) -> &mut Self | |
where | |
F: Fn() + Send + Sync + 'static | |
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Appreciate your work! ^^ PR merged and it will be included in v0.4.0 🎉 |
Following on from discussion in #51, this PR adds two methods to
ThreadPoolBuilder
:on_thread_spawn
andon_thread_finish
. These allow for functions to be provided that are called immediately after each pool thread is spawned and immediately before it finishes.An example of where these may be useful is for setting core affinity for each thread in the thread pool. This use case inspired the original PR (#51); the implementation in this PR is a completely general interface that also makes this possible.