2020-08-01 07:02:54 +02:00
|
|
|
#include "evloop.hpp"
|
2020-08-09 17:29:37 +01:00
|
|
|
#include "html_fetch_task.hpp"
|
2020-08-09 19:26:18 +01:00
|
|
|
#include "eventia/eventia.hpp"
|
|
|
|
#include "eventia/timer.hpp"
|
2020-08-01 07:02:54 +02:00
|
|
|
|
2020-08-09 19:26:18 +01:00
|
|
|
#include "orotool_config.hpp"
|
|
|
|
#if THREADPOOL == THREADPOOL_TASKFLOW
|
|
|
|
# include <taskflow/taskflow.hpp>
|
|
|
|
#elif THREADPOOL == THREADPOOL_ROAR11
|
|
|
|
# include "roar11/ThreadPool.hpp"
|
|
|
|
#endif
|
2020-08-01 07:02:54 +02:00
|
|
|
|
2020-08-09 19:26:18 +01:00
|
|
|
#include <iostream>
|
2020-08-01 07:02:54 +02:00
|
|
|
|
2020-08-09 19:26:18 +01:00
|
|
|
#if THREADPOOL == THREADPOOL_TASKFLOW
|
|
|
|
namespace tf {
|
|
|
|
class Taskflow;
|
|
|
|
class Subflow;
|
|
|
|
} //namespace tf
|
|
|
|
#elif THREADPOOL == THREADPOOL_ROAR11
|
|
|
|
namespace roar11 {
|
|
|
|
class ThreadPool;
|
|
|
|
} //namespace roar11
|
|
|
|
#endif
|
2020-08-01 07:02:54 +02:00
|
|
|
|
2020-08-09 19:26:18 +01:00
|
|
|
namespace duck {
|
|
|
|
namespace {
|
2020-08-09 17:29:37 +01:00
|
|
|
#if THREADPOOL == THREADPOOL_ROAR11
|
2020-08-09 19:26:18 +01:00
|
|
|
typedef roar11::ThreadPool threadpool_type;
|
|
|
|
typedef roar11::ThreadPool subpool_type;
|
|
|
|
#elif THREADPOOL == THREADPOOL_TASKFLOW
|
|
|
|
typedef tf::Taskflow threadpool_type;
|
|
|
|
typedef tf::Subflow subpool_type;
|
2020-08-09 17:29:37 +01:00
|
|
|
#endif
|
2020-08-01 07:02:54 +02:00
|
|
|
|
2020-08-09 19:26:18 +01:00
|
|
|
//class KeepaliveTimer : public ev::timer {
|
|
|
|
//public:
|
|
|
|
// KeepaliveTimer (ev::loop_ref& loop, RunningPool::subpool_type*) {
|
|
|
|
// this->set(loop);
|
|
|
|
// this->set<KeepaliveTimer, &KeepaliveTimer::on_timer_ev>(this);
|
|
|
|
// ev::timer::start(5.0, 5.0);
|
|
|
|
// }
|
2020-08-01 07:02:54 +02:00
|
|
|
|
2020-08-09 19:26:18 +01:00
|
|
|
// void on_timer_ev() {
|
|
|
|
// }
|
|
|
|
//};
|
2020-08-09 17:29:37 +01:00
|
|
|
|
|
|
|
#if THREADPOOL == THREADPOOL_TASKFLOW
|
2020-08-09 19:26:18 +01:00
|
|
|
void join(tf::Executor& executor) {
|
|
|
|
executor.wait_for_all();
|
2020-08-09 17:29:37 +01:00
|
|
|
std::cout << "all tasks completed\n";
|
|
|
|
}
|
2020-08-09 19:26:18 +01:00
|
|
|
#else
|
|
|
|
void join(threadpool_type& pool) {
|
|
|
|
pool.join();
|
|
|
|
std::cout << "all tasks completed\n";
|
2020-08-01 07:24:45 +02:00
|
|
|
}
|
2020-08-09 19:26:18 +01:00
|
|
|
#endif
|
2020-08-01 07:24:45 +02:00
|
|
|
|
2020-08-09 19:26:18 +01:00
|
|
|
} //unnamed namespace
|
2020-08-01 07:24:45 +02:00
|
|
|
|
2020-08-01 07:02:54 +02:00
|
|
|
void test() {
|
2020-08-09 19:26:18 +01:00
|
|
|
roar11::ThreadPool pool(std::max(2U, std::thread::hardware_concurrency()) - 1);
|
|
|
|
eve::EvThreadPool worker;
|
|
|
|
pool.submit(worker.event_functor());
|
2020-08-09 17:29:37 +01:00
|
|
|
|
|
|
|
std::cout << "Instantiating html timer\n";
|
2020-08-09 19:26:18 +01:00
|
|
|
auto fetcher = worker.make_timer<HtmlFetchTimer>(&pool, "test_url_lol");
|
2020-08-09 17:29:37 +01:00
|
|
|
|
2020-08-09 19:26:18 +01:00
|
|
|
join(pool);
|
2020-08-01 07:02:54 +02:00
|
|
|
}
|
|
|
|
} //namespace duck
|