@@ -283,6 +283,29 @@ class MultiTimelineEventHandlerST final : core::Unmovable, core::Uncopyable
283
283
return sum;
284
284
}
285
285
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 (" \t m_timelines[{}].handler.getSemaphore()=" ,t).c_str () << tl.handler ->getSemaphore () << std::endl;
294
+ std::cout << std::format (" \t m_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 (" \t m_scratchWaitInfos[{}].semaphore=" ,s).c_str () << waitInfo.semaphore << std::endl;
302
+ std::cout << std::format (" \t m_scratchWaitInfos[{}].value={}" ,s,waitInfo.value ).c_str () << std::endl;
303
+ s++;
304
+ }
305
+ std::cout << " MultiTimelineEventHandlerST State END ===>" << std::endl;
306
+ }
307
+ #endif
308
+
286
309
inline bool latch (const ISemaphore::SWaitInfo& futureWait, Functor&& function)
287
310
{
288
311
auto found = m_timelines.find (futureWait.semaphore );
@@ -296,6 +319,7 @@ class MultiTimelineEventHandlerST final : core::Unmovable, core::Uncopyable
296
319
};
297
320
found = m_timelines.insert (found,std::move (newTimeline));
298
321
m_scratchWaitInfos.emplace_back (futureWait.semaphore ,0xdeadbeefBADC0FFEull );
322
+ assert (m_scratchWaitInfos.size () == m_timelines.size ());
299
323
}
300
324
assert (found->handler ->getSemaphore ()==futureWait.semaphore );
301
325
found->handler ->latch (futureWait.value ,std::move (function));
@@ -431,15 +455,15 @@ class MultiTimelineEventHandlerST final : core::Unmovable, core::Uncopyable
431
455
432
456
inline auto operator <=>(const STimeline& rhs) const
433
457
{
434
- return handler->getSemaphore ()- rhs.handler ->getSemaphore ();
458
+ return reinterpret_cast < const char *>( handler->getSemaphore ()) - reinterpret_cast < const char *>( rhs.handler ->getSemaphore () );
435
459
}
436
460
inline auto operator <=>(const ISemaphore* rhs) const
437
461
{
438
- return handler->getSemaphore ()- rhs;
462
+ return reinterpret_cast < const char *>( handler->getSemaphore ()) - reinterpret_cast < const char *>( rhs) ;
439
463
}
440
464
441
465
TimelineEventHandler* handler;
442
- size_t waitInfoIx;
466
+ mutable size_t waitInfoIx;
443
467
};
444
468
// We use a `set<>` instead of `unordered_set<>` because we assume you won't spam semaphores/timelines
445
469
// 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
453
477
// swap the mapping with the end scratch element
454
478
const auto & lastScratch = m_scratchWaitInfos.back ();
455
479
typename container_t ::iterator found = m_timelines.find (lastScratch.semaphore );
456
- // found->waitInfoIx = timeline->waitInfoIx;
480
+ found->waitInfoIx = timeline->waitInfoIx ;
457
481
m_scratchWaitInfos[timeline->waitInfoIx ] = lastScratch;
458
482
}
459
483
m_scratchWaitInfos.pop_back ();
0 commit comments