Skip to content

Commit b535556

Browse files
fix a few things here and there
1 parent 4273dfb commit b535556

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

include/nbl/system/IAsyncQueueDispatcher.h

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class IAsyncQueueDispatcherBase
5858

5959
protected:
6060
// the base class is not directly usable
61+
inline request_base_t() = default;
6162
inline ~request_base_t()
6263
{
6364
// fully cleaned up
@@ -114,6 +115,7 @@ class IAsyncQueueDispatcherBase
114115
}
115116

116117
// the base class is not directly usable
118+
inline future_base_t() = default;
117119
virtual inline ~future_base_t()
118120
{
119121
// non-cancellable future just need to get to this state, and cancellable will move here
@@ -127,7 +129,7 @@ class IAsyncQueueDispatcherBase
127129

128130
// this tells us whether an object with a lifetime has been constructed over the memory backing the future
129131
// also acts as a lock
130-
atomic_state_t<STATE,STATE::INITIAL> state= {};
132+
atomic_state_t<STATE,STATE::INITIAL> state = {};
131133
};
132134

133135
// not meant for direct usage
@@ -146,7 +148,7 @@ class IAsyncQueueDispatcherBase
146148
}
147149

148150
public:
149-
inline future_t() {}
151+
inline future_t() : future_base_t() {}
150152
inline ~future_t()
151153
{
152154
discard();
@@ -258,6 +260,8 @@ class IAsyncQueueDispatcherBase
258260
}
259261

260262
protected:
263+
// to get access to the below
264+
friend class IAsyncQueueDispatcherBase;
261265
// construct the retval element
262266
template <typename... Args>
263267
inline void construct(Args&&... args)
@@ -331,6 +335,21 @@ class IAsyncQueueDispatcherBase
331335
return false;
332336
}
333337
};
338+
339+
protected:
340+
template<typename T>
341+
class future_constructor_t final
342+
{
343+
future_t<T>* pFuture;
344+
public:
345+
inline future_constructor_t(future_base_t* _future_base) : pFuture(static_cast<future_t<T>*>(_future_base)) {}
346+
347+
template<typename... Args>
348+
inline void operator()(Args&&... args)
349+
{
350+
pFuture->construct(std::forward<Args>(args)...);
351+
}
352+
};
334353
};
335354

336355
inline void IAsyncQueueDispatcherBase::request_base_t::finalize(future_base_t* fut)
@@ -388,7 +407,9 @@ class IAsyncQueueDispatcher : public IThreadHandler<CRTP,InternalStateType>, pro
388407

389408
struct request_t : public request_base_t
390409
{
391-
request_metadata_t m_metadata;
410+
inline request_t() : request_base_t() {}
411+
412+
request_metadata_t m_metadata = {};
392413
};
393414

394415
private:
@@ -410,7 +431,7 @@ class IAsyncQueueDispatcher : public IThreadHandler<CRTP,InternalStateType>, pro
410431

411432
public:
412433
inline IAsyncQueueDispatcher() {}
413-
inline IAsyncQueueDispatcher(base_t::start_on_construction_t) : base_t(base_t::start_on_construction_t) {}
434+
inline IAsyncQueueDispatcher(base_t::start_on_construction_t) : base_t(base_t::start_on_construction) {}
414435

415436
using mutex_t = typename base_t::mutex_t;
416437
using lock_t = typename base_t::lock_t;
@@ -454,7 +475,7 @@ class IAsyncQueueDispatcher : public IThreadHandler<CRTP,InternalStateType>, pro
454475
inline void background_work() {}
455476

456477
private:
457-
template <typename... Args>
478+
template<typename... Args>
458479
void work(lock_t& lock, Args&&... optional_internal_state)
459480
{
460481
lock.unlock();
@@ -472,7 +493,7 @@ class IAsyncQueueDispatcher : public IThreadHandler<CRTP,InternalStateType>, pro
472493
if (req.wait())
473494
{
474495
// if the request supports cancelling and got cancelled, then `wait()` function may return false
475-
static_cast<CRTP*>(this)->process_request(req.m_metadata,optional_internal_state...);
496+
static_cast<CRTP*>(this)->process_request(nullptr/*TODO*/,req.m_metadata,optional_internal_state...);
476497
req.notify();
477498
}
478499
// wake the waiter up

include/nbl/system/atomic_state.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ class atomic_state_t
5151
}
5252
[[nodiscard]] inline bool waitAbortableTransition(const STATE to, const STATE from, const STATE abortState)
5353
{
54-
uint32_t expected = static_cast<uint32_t>(from);
54+
STATE expected = from;
5555
while (!tryTransition(to,expected))
5656
{
57-
state.wait(expected);
58-
if (expected==static_cast<uint32_t>(abortState))
57+
state.wait(static_cast<uint32_t>(expected));
58+
if (expected==abortState)
5959
return false;
6060
expected = from;
6161
}

0 commit comments

Comments
 (0)