Skip to content

Commit

Permalink
Return std::pair instead of an out pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
abellina committed May 22, 2024
1 parent 7ac4302 commit afd4cbe
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions cpp/src/io/utilities/config_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,27 +244,22 @@ CUDF_EXPORT std::mutex& host_mr_mutex()
}

// Must be called with the host_mr_mutex mutex held
CUDF_EXPORT rmm::host_async_resource_ref& make_host_mr(std::optional<host_mr_options> const& opts,
bool* did_configure = nullptr)
CUDF_EXPORT std::pair<rmm::host_async_resource_ref*, bool> make_host_mr(
std::optional<host_mr_options> const& opts)
{
static rmm::host_async_resource_ref* mr_ref = nullptr;
bool configured = false;
if (mr_ref == nullptr) {
configured = true;
mr_ref = &make_default_pinned_mr(opts ? opts->pool_size : std::nullopt);
}

// If the user passed an out param to detect whether this call configured a resource
// set the result
if (did_configure != nullptr) { *did_configure = configured; }

return *mr_ref;
return std::make_pair(mr_ref, configured);
}

// Must be called with the host_mr_mutex mutex held
CUDF_EXPORT rmm::host_async_resource_ref& host_mr()
{
static rmm::host_async_resource_ref mr_ref = make_host_mr(std::nullopt);
static rmm::host_async_resource_ref mr_ref = *std::get<0>(make_host_mr(std::nullopt));
return mr_ref;
}

Expand All @@ -285,9 +280,8 @@ rmm::host_async_resource_ref get_host_memory_resource()
bool config_default_host_memory_resource(host_mr_options const& opts)
{
std::scoped_lock lock{host_mr_mutex()};
auto did_configure = false;
make_host_mr(opts, &did_configure);
return did_configure;
auto configured = std::get<1>(make_host_mr(opts));
return configured;
}

} // namespace cudf::io

0 comments on commit afd4cbe

Please sign in to comment.