@@ -22,23 +22,23 @@ DeviceGlobalUSMMem::~DeviceGlobalUSMMem() {
22
22
// and the event. When asserts are enabled the values are set, so we check
23
23
// these here.
24
24
assert (MPtr == nullptr && " MPtr has not been cleaned up." );
25
- assert (! MInitEvent. has_value () && " MInitEvent has not been cleaned up." );
25
+ assert (MInitEvent == nullptr && " MInitEvent has not been cleaned up." );
26
26
}
27
27
28
28
OwnedUrEvent DeviceGlobalUSMMem::getInitEvent (adapter_impl &Adapter) {
29
29
std::lock_guard<std::mutex> Lock (MInitEventMutex);
30
+ if (MInitEvent == nullptr )
31
+ return OwnedUrEvent (Adapter);
32
+
30
33
// If there is a init event we can remove it if it is done.
31
- if (MInitEvent.has_value ()) {
32
- if (get_event_info<info::event::command_execution_status>(
33
- *MInitEvent, Adapter) == info::event_command_status::complete) {
34
- Adapter.call <UrApiKind::urEventRelease>(*MInitEvent);
35
- MInitEvent = {};
36
- return OwnedUrEvent (Adapter);
37
- } else {
38
- return OwnedUrEvent (*MInitEvent, Adapter);
39
- }
34
+ if (get_event_info<info::event::command_execution_status>(
35
+ MInitEvent, Adapter) == info::event_command_status::complete) {
36
+ Adapter.call <UrApiKind::urEventRelease>(MInitEvent);
37
+ MInitEvent = nullptr ;
38
+ return OwnedUrEvent (Adapter);
39
+ } else {
40
+ return OwnedUrEvent (MInitEvent, Adapter);
40
41
}
41
- return OwnedUrEvent (Adapter);
42
42
}
43
43
44
44
DeviceGlobalUSMMem &
@@ -158,14 +158,14 @@ void DeviceGlobalMapEntry::removeAssociatedResources(
158
158
if (USMPtrIt != MDeviceToUSMPtrMap.end ()) {
159
159
DeviceGlobalUSMMem &USMMem = USMPtrIt->second ;
160
160
detail::usm::freeInternal (USMMem.MPtr , CtxImpl);
161
- if (USMMem.MInitEvent . has_value () )
161
+ if (USMMem.MInitEvent != nullptr )
162
162
CtxImpl->getAdapter ().call <UrApiKind::urEventRelease>(
163
- * USMMem.MInitEvent );
163
+ USMMem.MInitEvent );
164
164
#ifndef NDEBUG
165
165
// For debugging we set the event and memory to some recognizable values
166
166
// to allow us to check that this cleanup happens before erasure.
167
167
USMMem.MPtr = nullptr ;
168
- USMMem.MInitEvent = {} ;
168
+ USMMem.MInitEvent = nullptr ;
169
169
#endif
170
170
MDeviceToUSMPtrMap.erase (USMPtrIt);
171
171
}
@@ -183,13 +183,13 @@ void DeviceGlobalMapEntry::cleanup() {
183
183
const context_impl *CtxImpl = USMPtrIt.first .second ;
184
184
DeviceGlobalUSMMem &USMMem = USMPtrIt.second ;
185
185
detail::usm::freeInternal (USMMem.MPtr , CtxImpl);
186
- if (USMMem.MInitEvent . has_value () )
187
- CtxImpl->getAdapter ().call <UrApiKind::urEventRelease>(* USMMem.MInitEvent );
186
+ if (USMMem.MInitEvent != nullptr )
187
+ CtxImpl->getAdapter ().call <UrApiKind::urEventRelease>(USMMem.MInitEvent );
188
188
#ifndef NDEBUG
189
189
// For debugging we set the event and memory to some recognizable values
190
190
// to allow us to check that this cleanup happens before erasure.
191
191
USMMem.MPtr = nullptr ;
192
- USMMem.MInitEvent = {} ;
192
+ USMMem.MInitEvent = nullptr ;
193
193
#endif
194
194
}
195
195
MDeviceToUSMPtrMap.clear ();
0 commit comments