@@ -34,13 +34,10 @@ class TimelineEventHandlerBase : core::Unmovable, core::Uncopyable
34
34
core::smart_refctd_ptr<const ISemaphore> m_sema;
35
35
};
36
36
37
- template <typename Functor>
38
- class MultiTimelineEventHandlerST ;
39
-
40
37
// Could be made MT and relatively lockless, if only had a good lock-few circular buffer impl
41
38
// Not sure its worth the effort as anything using this will probably need to be lockful to be MT
42
39
template <typename Functor>
43
- class TimelineEventHandlerST final : TimelineEventHandlerBase
40
+ class TimelineEventHandlerST final : public TimelineEventHandlerBase
44
41
{
45
42
public:
46
43
// Theoretically could make a factory function cause passing a null semaphore is invalid, but counting on users to be relatively intelligent.
@@ -160,7 +157,8 @@ class TimelineEventHandlerST final : TimelineEventHandlerBase
160
157
inline void abortAll (Args&&... args) {abortOldest (~0ull ,std::forward<Args>(args)...);}
161
158
162
159
private:
163
- friend MultiTimelineEventHandlerST<Functor>;
160
+ // To get access to almost everything
161
+ template <typename Functor_, bool RefcountTheDevice> friend class MultiTimelineEventHandlerST ;
164
162
165
163
struct FunctorValuePair
166
164
{
@@ -227,21 +225,53 @@ class TimelineEventHandlerST final : TimelineEventHandlerBase
227
225
}
228
226
};
229
227
230
- //
231
- template <typename Functor>
228
+ // `RefcountTheDevice` should be false for any "internal user" of the Handler inside the Logical Device, such as the IQueue to avoid circular refs
229
+ /*
230
+ template<bool RefcountTheDevice>
231
+ class MultiTimelineEventHandlerBase : core::Unmovable, core::Uncopyable
232
+ {
233
+ public:
234
+ using device_ptr_t = std::conditional_t<RefcountTheDevice,core::smart_refctd_ptr<ILogicalDevice>,ILogicalDevice*>;
235
+ inline MultiTimelineEventHandlerBase(device_ptr_t&& device) : m_device(std::move(device)) {}
236
+
237
+ inline ILogicalDevice* getLogicalDevice() const {return m_device.get();}
238
+
239
+ protected:
240
+ template<typename Functor>
241
+ static inline auto getGreatestSignal(const TimelineEventHandlerST<Functor>* handler) {return handler->m_greatestSignal;}
242
+ template<typename Functor>
243
+ static inline auto getEmpty(const TimelineEventHandlerST<Functor>* handler) {return handler->m_cb.empty();}
244
+
245
+ device_ptr_t m_device;
246
+ };
247
+ */
248
+ template <typename Functor, bool RefcountTheDevice=true >
232
249
class MultiTimelineEventHandlerST final : core::Unmovable, core::Uncopyable
233
250
{
234
251
public:
235
252
using TimelineEventHandler = TimelineEventHandlerST<Functor>;
253
+ using device_ptr_t = std::conditional_t <RefcountTheDevice,core::smart_refctd_ptr<ILogicalDevice>,ILogicalDevice*>;
236
254
237
- inline MultiTimelineEventHandlerST (core::smart_refctd_ptr<ILogicalDevice>&& device) : m_device(std::move(device)) {}
255
+ inline MultiTimelineEventHandlerST (ILogicalDevice* device) : m_device(device) {}
256
+ MultiTimelineEventHandlerST (const MultiTimelineEventHandlerST&) = delete ;
238
257
inline ~MultiTimelineEventHandlerST ()
239
258
{
240
259
clear ();
241
260
}
242
261
243
- inline ILogicalDevice* getLogicalDevice () const {return m_device.get ();}
262
+ //
263
+ MultiTimelineEventHandlerST& operator =(const MultiTimelineEventHandlerST&) = delete ;
264
+
265
+ //
266
+ inline ILogicalDevice* getLogicalDevice () const
267
+ {
268
+ if constexpr (RefcountTheDevice)
269
+ return m_device.get ();
270
+ else
271
+ return m_device;
272
+ }
244
273
274
+ //
245
275
inline const auto & getTimelines () const {return m_timelines;}
246
276
247
277
// all the members are counteparts of the single timeline version
@@ -258,7 +288,7 @@ class MultiTimelineEventHandlerST final : core::Unmovable, core::Uncopyable
258
288
auto found = m_timelines.find (futureWait.semaphore );
259
289
if (found==m_timelines.end ())
260
290
{
261
- if (futureWait.semaphore ->getOriginDevice ()!=m_device. get ())
291
+ if (futureWait.semaphore ->getOriginDevice ()!=getLogicalDevice ())
262
292
return false ;
263
293
STimeline newTimeline = {
264
294
.handler = new TimelineEventHandler (core::smart_refctd_ptr<const ISemaphore>(futureWait.semaphore )),
@@ -441,7 +471,7 @@ class MultiTimelineEventHandlerST final : core::Unmovable, core::Uncopyable
441
471
442
472
container_t m_timelines;
443
473
core::vector<ISemaphore::SWaitInfo> m_scratchWaitInfos;
444
- core::smart_refctd_ptr<ILogicalDevice> m_device;
474
+ device_ptr_t m_device;
445
475
};
446
476
447
477
}
0 commit comments