using namespace std::chrono; | using namespace std::chrono; | ||||
using namespace std::literals; | using namespace std::literals; | ||||
const static auto MaxNum = 20000; | |||||
const static auto MaxNum = 100000; | |||||
const static auto LoopCount = 100; | |||||
using int_channel_ptr = std::shared_ptr<channel_t<intptr_t>>; | using int_channel_ptr = std::shared_ptr<channel_t<intptr_t>>; | ||||
static future_t<> passing_next(int_channel_ptr rd, int_channel_ptr wr) | |||||
static future_t<> passing_next(channel_t<intptr_t> rd, channel_t<intptr_t> wr) | |||||
{ | { | ||||
for (;;) | |||||
for (int i = 0; i < LoopCount; ++i) | |||||
{ | { | ||||
intptr_t value = co_await *rd; | |||||
co_await wr->write(value + 1); | |||||
intptr_t value = co_await rd; | |||||
co_await wr.write(value + 1); | |||||
} | } | ||||
} | } | ||||
for (int i = 0; i < MaxNum; ++i) | for (int i = 0; i < MaxNum; ++i) | ||||
{ | { | ||||
tail = std::make_shared<channel_t<intptr_t>>(1); | tail = std::make_shared<channel_t<intptr_t>>(1); | ||||
go passing_next(in, tail); | |||||
go passing_next(*in, *tail); | |||||
in = tail; | in = tail; | ||||
} | } | ||||
GO | GO | ||||
{ | { | ||||
for (;;) | |||||
for (int i = 0; i < LoopCount; ++i) | |||||
{ | { | ||||
auto tstart = high_resolution_clock::now(); | auto tstart = high_resolution_clock::now(); | ||||
#endif | #endif | ||||
} | } | ||||
local_scheduler::local_scheduler(scheduler_t& sch) | |||||
{ | |||||
#if RESUMEF_ENABLE_MULT_SCHEDULER | |||||
if (th_scheduler_ptr == nullptr) | |||||
{ | |||||
th_scheduler_ptr = &sch; | |||||
} | |||||
_scheduler_ptr = nullptr; | |||||
#endif | |||||
} | |||||
local_scheduler::~local_scheduler() | local_scheduler::~local_scheduler() | ||||
{ | { | ||||
#if RESUMEF_ENABLE_MULT_SCHEDULER | #if RESUMEF_ENABLE_MULT_SCHEDULER |
struct local_scheduler | struct local_scheduler | ||||
{ | { | ||||
local_scheduler(); | local_scheduler(); | ||||
local_scheduler(scheduler_t & sch); | |||||
~local_scheduler(); | ~local_scheduler(); | ||||
local_scheduler(local_scheduler&& right_) = delete; | local_scheduler(local_scheduler&& right_) = delete; |
#define OUTPUT_DEBUG 0 | #define OUTPUT_DEBUG 0 | ||||
future_t<> test_channel_consumer(const channel_t<std::string> & c, size_t cnt) | |||||
future_t<> test_channel_consumer(channel_t<std::string> c, size_t cnt) | |||||
{ | { | ||||
for (size_t i = 0; i < cnt; ++i) | for (size_t i = 0; i < cnt; ++i) | ||||
{ | { | ||||
} | } | ||||
} | } | ||||
future_t<> test_channel_producer(const channel_t<std::string> & c, size_t cnt) | |||||
future_t<> test_channel_producer(channel_t<std::string> c, size_t cnt) | |||||
{ | { | ||||
for (size_t i = 0; i < cnt; ++i) | for (size_t i = 0; i < cnt; ++i) | ||||
{ | { |
static scheduler_t* sch_in_main = nullptr; | static scheduler_t* sch_in_main = nullptr; | ||||
static std::atomic<scheduler_t*> sch_in_thread = nullptr; | static std::atomic<scheduler_t*> sch_in_thread = nullptr; | ||||
void run_in_thread(channel_t<bool>& c_done) | |||||
void run_in_thread(channel_t<bool> c_done) | |||||
{ | { | ||||
std::cout << "other thread = " << std::this_thread::get_id() << std::endl; | std::cout << "other thread = " << std::this_thread::get_id() << std::endl; | ||||
} | } | ||||
//这种情况下,会生成对应的 frame-context,一个promise_type被内嵌在frame-context里 | //这种情况下,会生成对应的 frame-context,一个promise_type被内嵌在frame-context里 | ||||
static future_t<> resumable_get_long(int64_t val, channel_t<bool> & c_done) | |||||
static future_t<> resumable_get_long(int64_t val, channel_t<bool> c_done) | |||||
{ | { | ||||
std::cout << "thread = " << std::this_thread::get_id() << ", value = " << val << std::endl; | std::cout << "thread = " << std::this_thread::get_id() << ", value = " << val << std::endl; | ||||