@@ -50,7 +50,7 @@ event_impl::~event_impl() {
5050 getPlugin ().call <PiApiKind::piEventRelease>(MEvent);
5151}
5252
53- void event_impl::waitInternal () const {
53+ void event_impl::waitInternal () {
5454 if (!MHostEvent && MEvent) {
5555 getPlugin ().call <PiApiKind::piEventsWait>(1 , &MEvent);
5656 return ;
@@ -61,8 +61,11 @@ void event_impl::waitInternal() const {
6161 make_error_code (errc::invalid),
6262 " waitInternal method cannot be used for a discarded event." );
6363
64- while (MState != HES_Complete)
65- ;
64+ if (MState == HES_Complete)
65+ return ;
66+
67+ std::unique_lock lock (MMutex);
68+ cv.wait (lock, [this ] { return MState == HES_Complete; });
6669}
6770
6871void event_impl::setComplete () {
@@ -77,6 +80,7 @@ void event_impl::setComplete() {
7780#else
7881 MState.store (static_cast <int >(HES_Complete));
7982#endif
83+ cv.notify_all ();
8084 return ;
8185 }
8286
@@ -190,8 +194,7 @@ void event_impl::instrumentationEpilog(void *TelemetryEvent,
190194#endif
191195}
192196
193- void event_impl::wait (
194- std::shared_ptr<cl::sycl::detail::event_impl> Self) const {
197+ void event_impl::wait (std::shared_ptr<cl::sycl::detail::event_impl> Self) {
195198 if (MState == HES_Discarded)
196199 throw sycl::exception (make_error_code (errc::invalid),
197200 " wait method cannot be used for a discarded event." );
0 commit comments