feat remove async++

This commit is contained in:
tqcq
2024-04-30 23:35:36 +08:00
parent bb82578636
commit 1eb66fb4dc
33 changed files with 4 additions and 5072 deletions

View File

@@ -1,49 +0,0 @@
#include "sled/async/async.h"
#include "sled/synchronization/event.h"
#include "sled/system/thread_pool.h"
#include "sled/utility/move_on_copy.h"
// clang-format off
#include <async++.h>
namespace sled {
void
SleepWaitHandler(async::task_wait_handle t)
{
sled::Event event;
t.on_finish([&] { event.Set(); });
event.Wait(sled::Event::kForever);
}
FiberScheduler::FiberScheduler()
{
}
static ThreadPool thread_pool;
void
FiberScheduler::schedule(async::task_run_handle t)
{
auto move_on_copy = sled::MakeMoveOnCopy(t);
thread_pool.PostTask([move_on_copy] { move_on_copy.value.run(); });
}
}// namespace sled
// clang-format on
namespace async {
sled::FiberScheduler &
default_scheduler()
{
static sled::FiberScheduler scheduler;
return scheduler;
}
void
detail::wait_for_task(task_base *wait_task)
{
sled::SleepWaitHandler(task_wait_handle(wait_task));
}
}// namespace async

View File

@@ -1,33 +0,0 @@
#ifndef SLED_ASYNC_ASYNC_H
#define SLED_ASYNC_ASYNC_H
namespace sled {
class FiberScheduler;
}
namespace async {
sled::FiberScheduler &default_scheduler();
namespace detail {
class task_base;
void wait_for_task(task_base *wait_task);
}// namespace detail
}// namespace async
#define LIBASYNC_CUSTOM_WAIT_FOR_TASK
#define LIBASYNC_CUSTOM_DEFAULT_SCHEDULER
#include <async++.h>
namespace sled {
void SleepWaitHandler(async::task_wait_handle t);
class FiberScheduler {
public:
FiberScheduler();
void schedule(async::task_run_handle t);
};
}// namespace sled
#endif// SLED_ASYNC_ASYNC_H

View File

@@ -1,33 +0,0 @@
#include <sled/async/async.h>
#include <sled/log/log.h>
#include <sled/system/fiber/wait_group.h>
#include <sled/system/thread.h>
TEST_SUITE("Async")
{
TEST_CASE("task")
{
auto task1 = async::spawn([] { return 42; }).then([](int value) { return value * 3; }).then([](int value) {
CHECK_EQ(value, 126);
return value;
});
// task1.wait();
CHECK_EQ(126, task1.get());
}
TEST_CASE("parallel_for")
{
const int count = 1000;
std::vector<int> values(count);
async::parallel_for(async::irange(0, count), [&values](int x) {
CHECK_FALSE(values[x]);
values[x] = true;
});
for (int i = 0; i < count; i++) { CHECK(values[i]); }
}
TEST_CASE("parallel_reduce")
{
auto r = async::parallel_reduce(async::irange(1, 5), 0, [](int x, int y) { return x + y; });
}
}

View File

@@ -4,7 +4,6 @@
// thrid_party
#include "rx.h"
#include "sled/async/async.h"
#include "sled/nonstd/cxxopts.h"
#include "sled/nonstd/expected.h"
#include "sled/nonstd/fsm.h"