Skip to content

Commit

Permalink
Make legate::Time resilient to the post-shutdown destruction (#395)
Browse files Browse the repository at this point in the history
* Make legate::Time resilient to the post-shutdown destruction

* Update src/timing/timing.cc

Co-authored-by: Jacob Faibussowitsch <[email protected]>

---------

Co-authored-by: Jacob Faibussowitsch <[email protected]>
  • Loading branch information
magnatelee and Jacobfaib authored Feb 8, 2024
1 parent 1cd33cf commit b7260f2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/timing/timing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "timing/timing.h"

#include "core/runtime/detail/runtime.h"

#include "legion.h"

#include <optional>
Expand All @@ -20,18 +22,30 @@ namespace legate::timing {

class Time::Impl {
public:
explicit Impl(Legion::Future future) : future_{std::move(future)} {}
explicit Impl(Legion::Future future)
: future_{std::make_unique<Legion::Future>(std::move(future))}
{
}

~Impl()
{
if (!detail::Runtime::get_runtime()->initialized()) {
// Leak the Future handle if the runtime has already shut down, as there's no hope that
// this would be collected by the Legion runtime
static_cast<void>(future_.release());
}
}

[[nodiscard]] int64_t value()
{
if (!value_) {
value_ = future_.get_result<int64_t>();
value_ = future_->get_result<int64_t>();
}
return *value_;
}

private:
Legion::Future future_{};
std::unique_ptr<Legion::Future> future_{};
std::optional<int64_t> value_{std::nullopt};
};

Expand Down

0 comments on commit b7260f2

Please sign in to comment.