Distributed Ranges
Loading...
Searching...
No Matches
future.hpp
1// SPDX-FileCopyrightText: Intel Corporation
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#pragma once
6
7#include <memory>
8#include <sycl/sycl.hpp>
9
10#include <dr/sp/detail.hpp>
11
12namespace dr::sp {
13
14template <typename T, typename Event = sycl::event> class future {
15public:
16 using event_type = Event;
17
18 future(std::unique_ptr<T> &&value, const std::vector<Event> &events)
19 : value_(std::move(value)), events_(events) {}
20
21 future(T &&value, const std::vector<Event> &events)
22 : value_(new T(std::move(value))), events_(events) {}
23
24 void update(const Event &event) { events_.push_back(event); }
25
26 future(future &&) = default;
27 future &operator=(future &&) = default;
28
29 future(const future &) = delete;
30 future &operator=(const future &) = delete;
31
32 T get() {
33 wait();
34 return std::move(*value_);
35 }
36
37 std::vector<Event> events() const { return events_; }
38
39 T &value() const { return *value_; }
40
41 void wait() { __detail::wait(events_); }
42
43private:
44 std::unique_ptr<T> value_;
45 std::vector<Event> events_;
46};
47
48} // namespace dr::sp
Definition: future.hpp:14