-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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 StartThread type checking wrapper #8303
Conversation
include/rocksdb/env.h
Outdated
using FWType = FunctorWrapper<Args...>; | ||
StartThread( | ||
[](void* arg) { | ||
auto* functor = reinterpret_cast<FWType*>(arg); |
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.
Do not use reinterpret_cast to cast from void*
(in new code)
include/rocksdb/env.h
Outdated
// Start a new thread, invoking "function(args...)" within the new thread. | ||
// When "function(args...)" returns, the thread will be destroyed. | ||
template <typename FunctionT, typename... Args> | ||
auto WrapStartThread(FunctionT function, Args&&... args) -> |
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.
Why not just void
return type without all the type trait stuff? The definition is inline and always will be because it's such a general template, so bad instantiations will fail to compile based on the (small) function definition being ill-formed.
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.
I agree, but I thought the error message would be a little nicer if the compiler failed to substitute function
in the template at the entry to the WrapStartThread
(or StartThreadTypeSafe
) than if it failed to substitute a function in the constructor of std::function
. The only difference is the size of the error. If it's not that important, I'll delete it, of course:)
include/rocksdb/env.h
Outdated
// Start a new thread, invoking "function(args...)" within the new thread. | ||
// When "function(args...)" returns, the thread will be destroyed. | ||
template <typename FunctionT, typename... Args> | ||
auto WrapStartThread(FunctionT function, Args&&... args) -> |
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.
Being "wrapped" is an implementation detail. The key feature vs. StartThread
is type safety. Perhaps StartThreadTyped
@pdillinger has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
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.
👍
@pdillinger merged this pull request in 748e3ac. |
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.
Neat PR, thanks!
FunctorWrapper
to invoke the function with given parametersis_invocable
type traitWrapStartThread
which wrapsStartThread
with type checking coverWrapStartThread
in testutil/thread_local_test.cc
#8285