Add async library & move stuff from util to async
This commit is contained in:
parent
a6b931e8e2
commit
0d64e86ffe
7 changed files with 26 additions and 16 deletions
|
|
@ -21,7 +21,7 @@
|
|||
#include <psemek/pcg/random/uniform_sphere.hpp>
|
||||
#include <psemek/util/range.hpp>
|
||||
#include <psemek/util/clock.hpp>
|
||||
#include <psemek/util/threadpool.hpp>
|
||||
#include <psemek/async/threadpool.hpp>
|
||||
|
||||
using namespace psemek;
|
||||
|
||||
|
|
@ -216,7 +216,7 @@ struct cloud_app
|
|||
light_mesh.setup<geom::point<float, 3>>();
|
||||
|
||||
{
|
||||
util::threadpool bg("bg");
|
||||
async::threadpool bg("bg");
|
||||
|
||||
pcg::generator rng(pcg::random_device{});
|
||||
pcg::uniform_sphere_vector_distribution<float, 3> d;
|
||||
|
|
@ -251,7 +251,7 @@ struct cloud_app
|
|||
{
|
||||
for (std::size_t y = 0; y < cloud_data.height(); ++y)
|
||||
{
|
||||
bg.dispatch([&, z, y]{
|
||||
bg.post([&, z, y]{
|
||||
for (std::size_t x = 0; x < cloud_data.width(); ++x)
|
||||
{
|
||||
geom::vector<float, 3> p;
|
||||
|
|
|
|||
6
libs/async/CMakeLists.txt
Normal file
6
libs/async/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
file(GLOB_RECURSE PSEMEK_ASYNC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "include/*.hpp")
|
||||
file(GLOB_RECURSE PSEMEK_ASYNC_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "source/*.cpp")
|
||||
|
||||
add_library(psemek-async ${PSEMEK_ASYNC_HEADERS} ${PSEMEK_ASYNC_SOURCES})
|
||||
target_include_directories(psemek-async PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
target_link_libraries(psemek-async PUBLIC psemek-log psemek-util)
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/util/executor.hpp>
|
||||
#include <psemek/async/executor.hpp>
|
||||
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace psemek::util
|
||||
namespace psemek::async
|
||||
{
|
||||
|
||||
struct event_loop
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
#include <chrono>
|
||||
#include <memory>
|
||||
|
||||
namespace psemek::util
|
||||
namespace psemek::async
|
||||
{
|
||||
|
||||
namespace detail
|
||||
|
|
@ -64,12 +64,15 @@ namespace psemek::util
|
|||
struct future
|
||||
{
|
||||
future() = default;
|
||||
future(future&&) = default;
|
||||
|
||||
future(std::shared_ptr<detail::task_state<T>> state)
|
||||
: state_(std::move(state))
|
||||
, f_(state_->promise.get_future())
|
||||
{}
|
||||
|
||||
future & operator = (future&&) = default;
|
||||
|
||||
~future()
|
||||
{
|
||||
reset();
|
||||
|
|
@ -132,7 +135,7 @@ namespace psemek::util
|
|||
|
||||
struct executor
|
||||
{
|
||||
using task = movable_function<void()>;
|
||||
using task = util::movable_function<void()>;
|
||||
using clock = std::chrono::high_resolution_clock;
|
||||
|
||||
// Post the task for execution. Where and when will
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/async/executor.hpp>
|
||||
|
||||
#include <psemek/util/thread.hpp>
|
||||
#include <psemek/util/synchronyzed_queue.hpp>
|
||||
#include <psemek/util/movable_function.hpp>
|
||||
#include <psemek/util/executor.hpp>
|
||||
|
||||
#include <future>
|
||||
#include <vector>
|
||||
|
|
@ -11,7 +12,7 @@
|
|||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
namespace psemek::util
|
||||
namespace psemek::async
|
||||
{
|
||||
|
||||
struct threadpool
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
#include <psemek/util/event_loop.hpp>
|
||||
#include <psemek/async/event_loop.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace psemek::util
|
||||
namespace psemek::async
|
||||
{
|
||||
|
||||
auto event_loop::heap_compare()
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
#include <psemek/util/threadpool.hpp>
|
||||
#include <psemek/async/threadpool.hpp>
|
||||
|
||||
#include <psemek/util/unused.hpp>
|
||||
#include <psemek/util/to_string.hpp>
|
||||
#include <psemek/util/at_scope_exit.hpp>
|
||||
|
||||
#include <psemek/log/log.hpp>
|
||||
|
||||
namespace psemek::util
|
||||
namespace psemek::async
|
||||
{
|
||||
|
||||
namespace
|
||||
|
|
@ -20,8 +20,8 @@ namespace psemek::util
|
|||
{
|
||||
for (std::size_t th = 0; th < thread_count; ++th)
|
||||
{
|
||||
std::string tname = thread_count == 1 ? name : to_string(name, '#', th);
|
||||
threads_.emplace_back([this, tname = std::move(tname), th, thread_count]
|
||||
std::string tname = thread_count == 1 ? name : util::to_string(name, '#', th);
|
||||
threads_.emplace_back([this, tname = std::move(tname)]
|
||||
{
|
||||
log::register_thread(tname);
|
||||
for (bool running = true; running;)
|
||||
Loading…
Add table
Reference in a new issue