Skip to content

Commit b1300b5

Browse files
committed
Fix TimelineEventHandler
1 parent efa763b commit b1300b5

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

include/nbl/video/TimelineEventHandlers.h

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,29 @@ class MultiTimelineEventHandlerST final : core::Unmovable, core::Uncopyable
283283
return sum;
284284
}
285285

286+
#ifdef DEBUG_PRINT_STATE
287+
inline void debugPrintState()
288+
{
289+
std::cout << "<=== MultiTimelineEventHandlerST State Begin" << std::endl;
290+
uint32_t t = 0u;
291+
for (const auto& tl : m_timelines)
292+
{
293+
std::cout << std::format("\tm_timelines[{}].handler.getSemaphore()=",t).c_str() << tl.handler->getSemaphore() << std::endl;
294+
std::cout << std::format("\tm_timelines[{}].waitInfoIx={}",t,tl.waitInfoIx).c_str() << std::endl;
295+
t++;
296+
}
297+
298+
uint32_t s = 0u;
299+
for (const auto& waitInfo : m_scratchWaitInfos)
300+
{
301+
std::cout << std::format("\tm_scratchWaitInfos[{}].semaphore=",s).c_str() << waitInfo.semaphore << std::endl;
302+
std::cout << std::format("\tm_scratchWaitInfos[{}].value={}",s,waitInfo.value).c_str() << std::endl;
303+
s++;
304+
}
305+
std::cout << "MultiTimelineEventHandlerST State END ===>" << std::endl;
306+
}
307+
#endif
308+
286309
inline bool latch(const ISemaphore::SWaitInfo& futureWait, Functor&& function)
287310
{
288311
auto found = m_timelines.find(futureWait.semaphore);
@@ -296,6 +319,7 @@ class MultiTimelineEventHandlerST final : core::Unmovable, core::Uncopyable
296319
};
297320
found = m_timelines.insert(found,std::move(newTimeline));
298321
m_scratchWaitInfos.emplace_back(futureWait.semaphore,0xdeadbeefBADC0FFEull);
322+
assert(m_scratchWaitInfos.size() == m_timelines.size());
299323
}
300324
assert(found->handler->getSemaphore()==futureWait.semaphore);
301325
found->handler->latch(futureWait.value,std::move(function));
@@ -431,15 +455,15 @@ class MultiTimelineEventHandlerST final : core::Unmovable, core::Uncopyable
431455

432456
inline auto operator<=>(const STimeline& rhs) const
433457
{
434-
return handler->getSemaphore()-rhs.handler->getSemaphore();
458+
return reinterpret_cast<const char*>(handler->getSemaphore()) - reinterpret_cast<const char*>(rhs.handler->getSemaphore());
435459
}
436460
inline auto operator<=>(const ISemaphore* rhs) const
437461
{
438-
return handler->getSemaphore()-rhs;
462+
return reinterpret_cast<const char*>(handler->getSemaphore()) - reinterpret_cast<const char*>(rhs);
439463
}
440464

441465
TimelineEventHandler* handler;
442-
size_t waitInfoIx;
466+
mutable size_t waitInfoIx;
443467
};
444468
// We use a `set<>` instead of `unordered_set<>` because we assume you won't spam semaphores/timelines
445469
// also we need to be able to continue iteration after an erasure of a single element
@@ -453,7 +477,7 @@ class MultiTimelineEventHandlerST final : core::Unmovable, core::Uncopyable
453477
// swap the mapping with the end scratch element
454478
const auto& lastScratch = m_scratchWaitInfos.back();
455479
typename container_t::iterator found = m_timelines.find(lastScratch.semaphore);
456-
// found->waitInfoIx = timeline->waitInfoIx;
480+
found->waitInfoIx = timeline->waitInfoIx;
457481
m_scratchWaitInfos[timeline->waitInfoIx] = lastScratch;
458482
}
459483
m_scratchWaitInfos.pop_back();

0 commit comments

Comments
 (0)