@@ -117,11 +117,11 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
117117 // / constructed.
118118 // / \param AsyncHandler is a SYCL asynchronous exception handler.
119119 // / \param PropList is a list of properties to use for queue construction.
120- queue_impl (device_impl &Device, const ContextImplPtr &Context,
120+ queue_impl (device_impl &Device, std::shared_ptr<context_impl> & &Context,
121121 const async_handler &AsyncHandler, const property_list &PropList,
122122 private_tag)
123- : MDevice(Device), MContext(Context), MAsyncHandler(AsyncHandler ),
124- MPropList (PropList),
123+ : MDevice(Device), MContext(std::move( Context)),
124+ MAsyncHandler (AsyncHandler), MPropList(PropList),
125125 MIsInorder(has_property<property::queue::in_order>()),
126126 MIsProfilingEnabled(has_property<property::queue::enable_profiling>()),
127127 MQueueID{
@@ -146,8 +146,8 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
146146 " Queue compute index must be a non-negative number less than "
147147 " device's number of available compute queue indices." );
148148 }
149- if (!Context ->isDeviceValid (Device)) {
150- if (Context ->getBackend () == backend::opencl)
149+ if (!MContext ->isDeviceValid (Device)) {
150+ if (MContext ->getBackend () == backend::opencl)
151151 throw sycl::exception (
152152 make_error_code (errc::invalid),
153153 " Queue cannot be constructed with the given context and device "
@@ -177,17 +177,13 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
177177 trySwitchingToNoEventsMode ();
178178 }
179179
180- sycl::detail::optional<event> getLastEvent ();
180+ queue_impl (device_impl &Device, context_impl &Context,
181+ const async_handler &AsyncHandler, const property_list &PropList,
182+ private_tag Tag)
183+ : queue_impl(Device, Context.shared_from_this(), AsyncHandler, PropList,
184+ Tag) {}
181185
182- // / Constructs a SYCL queue from adapter interoperability handle.
183- // /
184- // / \param UrQueue is a raw UR queue handle.
185- // / \param Context is a SYCL context to associate with the queue being
186- // / constructed.
187- // / \param AsyncHandler is a SYCL asynchronous exception handler.
188- queue_impl (ur_queue_handle_t UrQueue, const ContextImplPtr &Context,
189- const async_handler &AsyncHandler, private_tag tag)
190- : queue_impl(UrQueue, Context, AsyncHandler, {}, tag) {}
186+ sycl::detail::optional<event> getLastEvent ();
191187
192188 // / Constructs a SYCL queue from adapter interoperability handle.
193189 // /
@@ -196,27 +192,28 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
196192 // / constructed.
197193 // / \param AsyncHandler is a SYCL asynchronous exception handler.
198194 // / \param PropList is the queue properties.
199- queue_impl (ur_queue_handle_t UrQueue, const ContextImplPtr &Context,
195+ queue_impl (ur_queue_handle_t UrQueue, context_impl &Context,
200196 const async_handler &AsyncHandler, const property_list &PropList,
201197 private_tag)
202198 : MDevice([&]() -> device_impl & {
203199 ur_device_handle_t DeviceUr{};
204- const AdapterPtr &Adapter = Context-> getAdapter ();
200+ const AdapterPtr &Adapter = Context. getAdapter ();
205201 // TODO catch an exception and put it to list of asynchronous
206202 // exceptions
207203 Adapter->call <UrApiKind::urQueueGetInfo>(
208204 UrQueue, UR_QUEUE_INFO_DEVICE, sizeof (DeviceUr), &DeviceUr,
209205 nullptr );
210- device_impl *Device = Context-> findMatchingDeviceImpl (DeviceUr);
206+ device_impl *Device = Context. findMatchingDeviceImpl (DeviceUr);
211207 if (Device == nullptr ) {
212208 throw sycl::exception (
213209 make_error_code (errc::invalid),
214210 " Device provided by native Queue not found in Context." );
215211 }
216212 return *Device;
217213 }()),
218- MContext (Context), MAsyncHandler(AsyncHandler), MPropList(PropList),
219- MQueue (UrQueue), MIsInorder(has_property<property::queue::in_order>()),
214+ MContext (Context.shared_from_this()), MAsyncHandler(AsyncHandler),
215+ MPropList (PropList), MQueue(UrQueue),
216+ MIsInorder (has_property<property::queue::in_order>()),
220217 MIsProfilingEnabled (has_property<property::queue::enable_profiling>()),
221218 MQueueID{
222219 MNextAvailableQueueID.fetch_add (1 , std::memory_order_relaxed)} {
@@ -985,7 +982,7 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
985982 mutable std::mutex MMutex;
986983
987984 device_impl &MDevice;
988- const ContextImplPtr MContext;
985+ const std::shared_ptr<context_impl> MContext;
989986
990987 // / These events are tracked, but not owned, by the queue.
991988 std::vector<std::weak_ptr<event_impl>> MEventsWeak;
0 commit comments