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

maint: Replace use of folly getCurrentThreadId with STL #1408

Closed

Conversation

ianthomas23
Copy link
Collaborator

Reference Issues/PRs

What does this implement or fix?

This is work to assist @jjerphan in removing use of folly in the ArcticDB code base.

The change here is to remove use of folly::getCurrentThreadID() in get_thread_id(), replacing it with use of std::this_thread::get_id().

Any other comments?

The folly implementation is much more complicated as there are different implementation for the 3 major OSes:

https://github.com/facebook/folly/blob/69a1b93df285457cd0799a6898e2e5390a09cd73/folly/system/ThreadId.cpp#L29-L37

The different implementations are not required as the STL C++11 solution should work on all OSes. I have kept the return type as uint64_t and hence am using the STL thread::hash specialisation to convert the implementation-specific thread_id to integer. It is possible for two thread IDs to have the same hash, but this has negligible mathematical probability, and also it doesn't matter of there are hash collisions as the only use of get_thread_id is in log messages.

Checklist

Checklist for code changes...
  • Have you updated the relevant docstrings, documentation and copyright notice?
  • Is this contribution tested against all ArcticDB's features?
  • Do all exceptions introduced raise appropriate error messages?
  • Are API changes highlighted in the PR description?
  • Is the PR labelled as enhancement or bug so it appears in autogenerated release notes?

@ianthomas23 ianthomas23 force-pushed the remove_folly_thread_id branch from 9ef489f to 551b256 Compare March 8, 2024 16:16
@ianthomas23 ianthomas23 changed the title main: Replace use of folly getCurrentThreadId with STL maint: Replace use of folly getCurrentThreadId with STL Mar 8, 2024
@jjerphan jjerphan mentioned this pull request Mar 11, 2024
17 tasks
@@ -67,7 +66,8 @@ struct StorageLockTimeout : public std::runtime_error {
};

inline uint64_t get_thread_id() {
return folly::getCurrentThreadID();
auto thread_id = std::this_thread::get_id();
return std::hash<std::thread::id>()(thread_id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function is only used in logging, so can return the std::thread::id directly provided fmt can handle it

@ianthomas23
Copy link
Collaborator Author

Closing this, I will replace it with another PR from a branch in this repo rather than my fork of it.

@ianthomas23 ianthomas23 deleted the remove_folly_thread_id branch March 13, 2024 11:18
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