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

Expose the flusher thread object to user in order to allow setting of thread name and thread affinity when needed #3009

Merged
merged 2 commits into from
Feb 14, 2024

Conversation

cohdan
Copy link
Contributor

@cohdan cohdan commented Feb 12, 2024

In our app there is a need to set the thread name and thread affinity for all spawned thread. In order to do so with the spdlog flusher thread, I had to expose the thread from the internal data structure (periodic_worker) via the registery. I thought this might be worthy of a merge back into the main stream.

… thread name and thread affinity when needed
@@ -38,6 +38,7 @@ class SPDLOG_API periodic_worker {
}
});
}
std::thread *get_thread() { return &worker_thread_; }
Copy link
Owner

Choose a reason for hiding this comment

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

why not return reference like in the rest of this pr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair question :)
To be honest I was just lazy to change some legacy APIs in my code. But that's not a good enough reason and indeed it makes no sense. I'll update the PR.

@@ -89,4 +89,9 @@ SPDLOG_INLINE void apply_logger_env_levels(std::shared_ptr<logger> logger) {
details::registry::instance().apply_logger_env_levels(std::move(logger));
}

SPDLOG_INLINE std::unique_ptr<spdlog::details::periodic_worker> &get_flusher()
{
return details::registry::instance().get_flusher();
Copy link
Owner

Choose a reason for hiding this comment

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

This change is not needed, as the registry can be accessed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not a must, I agree, but it allows to access directly from spdlog namespace (similar to spdlog::register_logger for example) which makes it neater IMHO.

Copy link
Owner

Choose a reason for hiding this comment

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

Better not add new api if not really necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok
uploaded a new PR without this.

Copy link
Owner

Choose a reason for hiding this comment

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

There is a missing mutex lock in the get_flusher()

Add

std::lock_guard<std::mutex> lock(flusher_mutex_);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. Fixed.

@gabime gabime merged commit fe79bfc into gabime:v1.x Feb 14, 2024
8 checks passed
gabime pushed a commit that referenced this pull request Mar 16, 2024
… thread name and thread affinity when needed (#3009)

* Expose the flusher thread object to user in order to allow setting of thread name and thread affinity when needed

* Code review fix - periodic_worker thread getter should return a reference and not a pointer
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