6 #include <condition_variable> 19 std::condition_variable _condition;
20 std::deque<std::pair<std::shared_ptr<void>, std::function<void()>>> _queue;
22 std::atomic<size_t> _count;
25 void start(
const std::shared_ptr<void> &owner,
26 const std::function<
void()> &fnc);
27 void cancel(
const std::shared_ptr<void> &owner);
28 size_t count()
const {
return _count; }
32 static const std::shared_ptr<LoaderThread> &instance();
37 std::shared_ptr<T> data;
40 std::shared_ptr<Data> _data;
41 std::function<std::shared_ptr<T>()> _constructor;
44 _data = std::make_shared<Data>();
46 auto ctor = _constructor;
47 LoaderThread::instance()->start(_data, [d, ctor]() {
55 template <
class... Args>
Loader(
const Args &... args) {
56 _constructor = [args...]() {
return std::make_shared<T>(args...); };
62 std::shared_ptr<T> load() {
72 LoaderThread::instance()->cancel(_data);