-
Notifications
You must be signed in to change notification settings - Fork 65
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
Fix std::future status query #596
base: branch-25.04
Are you sure you want to change the base?
Changes from all commits
70c1087
75f7a12
d30e0a0
c8f2e1b
25d8850
1691bd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -26,6 +26,7 @@ | |||
#include <kvikio/defaults.hpp> | ||||
#include <kvikio/file_handle.hpp> | ||||
#include <kvikio/file_utils.hpp> | ||||
#include "kvikio/utils.hpp" | ||||
|
||||
namespace kvikio { | ||||
|
||||
|
@@ -210,11 +211,11 @@ std::future<std::size_t> FileHandle::pread(void* buf, | |||
|
||||
// Shortcut that circumvent the threadpool and use the POSIX backend directly. | ||||
if (size < gds_threshold) { | ||||
auto task = [this, ctx, buf, size, file_offset]() -> std::size_t { | ||||
PushAndPopContext c(ctx); | ||||
return detail::posix_device_read(_fd_direct_off.fd(), buf, size, file_offset, 0); | ||||
}; | ||||
return std::async(std::launch::deferred, task); | ||||
PushAndPopContext c(ctx); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a note that this execution model provides API compatibility with the rest of the future-based APIs in the library while also ensuring that the future is actually immediately available since we don't want this call to be asynchronous. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. Done. kvikio/cpp/include/kvikio/utils.hpp Line 165 in b519cc2
|
||||
auto bytes_read = detail::posix_device_read(_fd_direct_off.fd(), buf, size, file_offset, 0); | ||||
// Maintain API consistency while making this trivial case synchronous. | ||||
// The result in the future is immediately available after the call. | ||||
return make_ready_future(bytes_read); | ||||
} | ||||
|
||||
// Let's synchronize once instead of in each task. | ||||
|
@@ -260,11 +261,11 @@ std::future<std::size_t> FileHandle::pwrite(void const* buf, | |||
|
||||
// Shortcut that circumvent the threadpool and use the POSIX backend directly. | ||||
if (size < gds_threshold) { | ||||
auto task = [this, ctx, buf, size, file_offset]() -> std::size_t { | ||||
PushAndPopContext c(ctx); | ||||
return detail::posix_device_write(_fd_direct_off.fd(), buf, size, file_offset, 0); | ||||
}; | ||||
return std::async(std::launch::deferred, task); | ||||
PushAndPopContext c(ctx); | ||||
auto bytes_write = detail::posix_device_write(_fd_direct_off.fd(), buf, size, file_offset, 0); | ||||
// Maintain API consistency while making this trivial case synchronous. | ||||
// The result in the future is immediately available after the call. | ||||
return make_ready_future(bytes_write); | ||||
} | ||||
|
||||
// Let's synchronize once instead of in each task. | ||||
|
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.
It is tempting to add the "can't copy" part to the code to improve type safety:
But this does not work.
For the non-copyable
gather_tasks
below, trying to copy construct results in compile error, but the type trait gives unexpected result.A simpler example:
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.
This is a good writeup: https://quuxplusone.github.io/blog/2020/02/05/vector-is-copyable-except-when-its-not/