diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2017-09-26 00:00:00 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2017-09-26 00:00:00 +0300 |
commit | 3b1b08b521930a43210310065ddd33537f08010e (patch) | |
tree | e5c2b4ae74925d84f43b58130e8cbd915bec7684 /test/tests/coroutines.cpp | |
parent | 760a6d37f6ff42a948a1487ac6b1d7deb477195e (diff) |
Implemented refactor of async_file_handle on POSIX.
Reenabled Coroutines TS support which is now working very nicely.
Diffstat (limited to 'test/tests/coroutines.cpp')
-rw-r--r-- | test/tests/coroutines.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/test/tests/coroutines.cpp b/test/tests/coroutines.cpp index 61aee5a1..3a570d51 100644 --- a/test/tests/coroutines.cpp +++ b/test/tests/coroutines.cpp @@ -44,9 +44,9 @@ static inline void TestAsyncFileHandleCoroutines() // Launch 8 coroutines, each writing 4Kb of chars 0-8 to every 32Kb block auto coroutine = [&h](size_t no) -> std::future<void> { - alignas(4096) char buffer[4096]; - memset(buffer, (int) ('0' + no), 4096); - afio::async_file_handle::const_buffer_type bt{buffer}; + std::vector<char, afio::utils::page_allocator<char>> buffer(4096); + memset(buffer.data(), (int) ('0' + no), 4096); + afio::async_file_handle::const_buffer_type bt{buffer.data(), buffer.size()}; for(size_t n = 0; n < 128; n++) { // This will initiate the i/o, and suspend the coroutine until completion. @@ -92,18 +92,25 @@ static inline void TestPostSelfToRunCoroutines() #ifdef __cpp_coroutines namespace afio = AFIO_V2_NAMESPACE; afio::io_service service; + std::atomic<bool> ready(false); auto runthreadid = QUICKCPPLIB_NAMESPACE::utils::thread::this_thread_id(); auto coroutine = [&]() -> std::future<void> { auto thisthreadid = QUICKCPPLIB_NAMESPACE::utils::thread::this_thread_id(); BOOST_CHECK(thisthreadid != runthreadid); + ready = true; co_await afio::io_service::awaitable_post_to_self(service); thisthreadid = QUICKCPPLIB_NAMESPACE::utils::thread::this_thread_id(); BOOST_CHECK(thisthreadid == runthreadid); }; auto asynch = std::async(std::launch::async, coroutine); + while(!ready) + { + std::this_thread::yield(); + } while(!service.run()) ; - asynch.get().get(); + auto r = asynch.get(); + r.get(); #endif } |