@@ -5,7 +5,7 @@ | |||
支持以下平台和编译器: | |||
Windows: 使用VS2017/VS2019/clang 9 编译 | |||
Windows: 使用VS2017/VS2019编译(clang在兼容msvc模式下不支持异常,不再支持clang) | |||
Android: 使用NDK 20.1 自带的clang编译 | |||
Mac: 使用XCode 11.2.1 自带的apple-clang编译 | |||
Ubuntu: 使用GCC 10.0.1/clang 9 编译(2020-04-18:mutex ranged lock failed) |
@@ -46,9 +46,7 @@ future_t<> RunEchoSession(tcp::socket socket) | |||
std::array<char, BUF_SIZE> buffer; | |||
for(;;) | |||
{ | |||
#ifndef __clang__ | |||
try | |||
#endif | |||
{ | |||
bytes_transferred += co_await socket.async_read_some(asio::buffer(buffer.data() + bytes_transferred, buffer.size() - bytes_transferred), rf_task); | |||
if (bytes_transferred >= buffer.size()) | |||
@@ -59,13 +57,11 @@ future_t<> RunEchoSession(tcp::socket socket) | |||
g_echo_count.fetch_add(1, std::memory_order_release); | |||
} | |||
} | |||
#ifndef __clang__ | |||
catch (std::exception & e) | |||
{ | |||
std::cerr << e.what() << std::endl; | |||
break; | |||
} | |||
#endif | |||
} | |||
} | |||
@@ -80,19 +76,15 @@ void AcceptConnections(tcp::acceptor & acceptor, uarray<tcp::socket, _N> & socke | |||
{ | |||
for (;;) | |||
{ | |||
#ifndef __clang__ | |||
try | |||
#endif | |||
{ | |||
co_await acceptor.async_accept(socketes.c[idx], rf_task); | |||
go RunEchoSession(std::move(socketes.c[idx])); | |||
} | |||
#ifndef __clang__ | |||
catch (std::exception & e) | |||
{ | |||
std::cerr << e.what() << std::endl; | |||
} | |||
#endif | |||
} | |||
}; | |||
} | |||
@@ -154,9 +146,7 @@ future_t<> RunPipelineEchoClient(asio::io_service & ios, tcp::resolver::iterator | |||
{ | |||
std::shared_ptr<tcp::socket> sptr = std::make_shared<tcp::socket>(ios); | |||
#ifndef __clang__ | |||
try | |||
#endif | |||
{ | |||
co_await asio::async_connect(*sptr, ep, rf_task); | |||
@@ -166,28 +156,22 @@ future_t<> RunPipelineEchoClient(asio::io_service & ios, tcp::resolver::iterator | |||
for (auto & c : write_buff_) | |||
c = 'A' + rand() % 52; | |||
#ifndef __clang__ | |||
try | |||
#endif | |||
{ | |||
for (;;) | |||
{ | |||
co_await asio::async_write(*sptr, asio::buffer(write_buff_), rf_task); | |||
} | |||
} | |||
#ifndef __clang__ | |||
catch (std::exception & e) | |||
{ | |||
std::cerr << e.what() << std::endl; | |||
} | |||
#endif | |||
}; | |||
GO | |||
{ | |||
#ifndef __clang__ | |||
try | |||
#endif | |||
{ | |||
std::array<char, BUF_SIZE> read_buff_; | |||
for (;;) | |||
@@ -195,20 +179,16 @@ future_t<> RunPipelineEchoClient(asio::io_service & ios, tcp::resolver::iterator | |||
co_await sptr->async_read_some(asio::buffer(read_buff_), rf_task); | |||
} | |||
} | |||
#ifndef __clang__ | |||
catch (std::exception & e) | |||
{ | |||
std::cerr << e.what() << std::endl; | |||
} | |||
#endif | |||
}; | |||
} | |||
#ifndef __clang__ | |||
catch (std::exception & e) | |||
{ | |||
std::cerr << e.what() << std::endl; | |||
} | |||
#endif | |||
} | |||
#if _HAS_CXX17 | |||
@@ -220,9 +200,7 @@ future_t<> RunPingPongEchoClient(asio::io_service & ios, tcp::resolver::iterator | |||
std::array<char, BUF_SIZE> read_buff_; | |||
std::array<char, BUF_SIZE> write_buff_; | |||
#ifndef __clang__ | |||
try | |||
#endif | |||
{ | |||
co_await asio::async_connect(socket_, ep, rf_task); | |||
@@ -237,12 +215,10 @@ future_t<> RunPingPongEchoClient(asio::io_service & ios, tcp::resolver::iterator | |||
); | |||
} | |||
} | |||
#ifndef __clang__ | |||
catch (std::exception & e) | |||
{ | |||
std::cerr << e.what() << std::endl; | |||
} | |||
#endif | |||
} | |||
void resumable_main_benchmark_asio_client_with_rf(intptr_t nNum) |
@@ -6,7 +6,7 @@ | |||
#include "librf.h" | |||
const size_t N = 2000000; | |||
const size_t N = 10000000; | |||
const size_t LOOP_COUNT = 50; | |||
std::atomic<size_t> globalValue{0}; |
@@ -164,6 +164,7 @@ namespace resumef | |||
template<class _PromiseT, class _Timeout, typename = std::enable_if_t<traits::is_promise_v<_PromiseT>>> | |||
bool await_suspend2(coroutine_handle<_PromiseT> handler, const _Timeout& cb) | |||
{ | |||
(void)cb; | |||
detail::event_v2_impl* evt = _event; | |||
scoped_lock<detail::event_v2_impl::lock_type> lock_(evt->_lock); | |||
@@ -267,6 +268,7 @@ namespace resumef | |||
template<class _PromiseT, class _Timeout, typename = std::enable_if_t<traits::is_promise_v<_PromiseT>>> | |||
bool await_suspend2(coroutine_handle<_PromiseT> handler, const _Timeout& cb) | |||
{ | |||
(void)cb; | |||
using ref_lock_type = std::reference_wrapper<detail::event_v2_impl::lock_type>; | |||
std::vector<ref_lock_type> lockes; | |||
lockes.reserve(std::distance(_begin, _end)); | |||
@@ -394,6 +396,7 @@ namespace resumef | |||
template<class _PromiseT, class _Timeout, typename = std::enable_if_t<traits::is_promise_v<_PromiseT>>> | |||
bool await_suspend2(coroutine_handle<_PromiseT> handler, const _Timeout& cb) | |||
{ | |||
(void)cb; | |||
intptr_t count = std::distance(_begin, _end); | |||
using ref_lock_type = std::reference_wrapper<detail::event_v2_impl::lock_type>; |
@@ -210,6 +210,7 @@ namespace resumef | |||
template<class _PromiseT, class _Timeout, typename = std::enable_if_t<traits::is_promise_v<_PromiseT>>> | |||
bool await_suspend2(coroutine_handle<_PromiseT> handler, const _Timeout& cb) | |||
{ | |||
(void)cb; | |||
_PromiseT& promise = handler.promise(); | |||
auto* parent = promise.get_state(); | |||
_root = parent->get_root(); |
@@ -35,7 +35,7 @@ int main(int argc, const char* argv[]) | |||
(void)argc; | |||
(void)argv; | |||
//resumable_main_stop_token(); | |||
//resumable_main_mutex(); | |||
//return 0; | |||
//if (argc > 1) |
@@ -39,9 +39,7 @@ future_t<> test_channel_read(string_channel_t c) | |||
for (size_t i = 0; i < 10; ++i) | |||
{ | |||
#ifndef __clang__ | |||
try | |||
#endif | |||
{ | |||
//auto val = co_await c.read(); | |||
auto val = co_await c; //第二种从channel读出数据的方法。利用重载operator co_await(),而不是c是一个awaitable_t。 | |||
@@ -49,13 +47,11 @@ future_t<> test_channel_read(string_channel_t c) | |||
std::cout << val.value << ":"; | |||
std::cout << std::endl; | |||
} | |||
#ifndef __clang__ | |||
catch (resumef::channel_exception& e) | |||
{ | |||
//MAX_CHANNEL_QUEUE=0,并且先读后写,会触发read_before_write异常 | |||
std::cout << e.what() << std::endl; | |||
} | |||
#endif | |||
co_await sleep_for(50ms); | |||
} |
@@ -21,9 +21,7 @@ future_t<> test_channel_consumer(channel_t<std::string> c, size_t cnt) | |||
{ | |||
for (size_t i = 0; i < cnt; ++i) | |||
{ | |||
#ifndef __clang__ | |||
try | |||
#endif | |||
{ | |||
auto val = co_await c.read(); | |||
++gcounter; | |||
@@ -34,14 +32,12 @@ future_t<> test_channel_consumer(channel_t<std::string> c, size_t cnt) | |||
} | |||
#endif | |||
} | |||
#ifndef __clang__ | |||
catch (channel_exception& e) | |||
{ | |||
//MAX_CHANNEL_QUEUE=0,并且先读后写,会触发read_before_write异常 | |||
scoped_lock<std::mutex> __lock(cout_mutex); | |||
std::cout << e.what() << std::endl; | |||
} | |||
#endif | |||
#if OUTPUT_DEBUG | |||
co_await sleep_for(50ms); |
@@ -51,14 +51,11 @@ future_t<> test_signal_exception() | |||
{ | |||
for (intptr_t i = 10; i >= 0; --i) | |||
{ | |||
#ifndef __clang__ | |||
try | |||
#endif | |||
{ | |||
auto r = co_await async_signal_exception2(i); | |||
std::cout << "result is " << r << std::endl; | |||
} | |||
#ifndef __clang__ | |||
catch (const std::exception& e) | |||
{ | |||
std::cout << "exception signal : " << e.what() << std::endl; | |||
@@ -67,7 +64,6 @@ future_t<> test_signal_exception() | |||
{ | |||
std::cout << "exception signal : who knows?" << std::endl; | |||
} | |||
#endif | |||
} | |||
} | |||
@@ -123,9 +123,7 @@ static void example_librf() | |||
//支持librf的用法 | |||
GO | |||
{ | |||
#ifndef __clang__ | |||
try | |||
#endif | |||
{ | |||
int val = co_await add_async(1, 2, use_librf); | |||
std::cout << val << std::endl; | |||
@@ -138,7 +136,6 @@ static void example_librf() | |||
std::cout << result << std::endl; | |||
} | |||
#ifndef __clang__ | |||
catch (const std::exception & e) | |||
{ | |||
std::cout << "exception signal : " << e.what() << std::endl; | |||
@@ -147,7 +144,6 @@ static void example_librf() | |||
{ | |||
std::cout << "exception signal : who knows?" << std::endl; | |||
} | |||
#endif | |||
}; | |||
resumef::this_scheduler()->run_until_notask(); |
@@ -203,13 +203,13 @@ static void resumable_mutex_lock_range() | |||
void resumable_main_mutex() | |||
{ | |||
//std::cout << "begin resumable_mutex_synch()" << std::endl; | |||
//resumable_mutex_synch(); | |||
//std::cout << std::endl; | |||
std::cout << "begin resumable_mutex_synch()" << std::endl; | |||
resumable_mutex_synch(); | |||
std::cout << std::endl; | |||
//std::cout << "begin resumable_mutex_async()" << std::endl; | |||
//resumable_mutex_async(); | |||
//std::cout << std::endl; | |||
std::cout << "begin resumable_mutex_async()" << std::endl; | |||
resumable_mutex_async(); | |||
std::cout << std::endl; | |||
std::cout << "begin resumable_mutex_lock_range()" << std::endl; | |||
resumable_mutex_lock_range(); |
@@ -68,7 +68,7 @@ static void test_get_long_with_stop(int64_t val) | |||
int64_t result = co_await async_get_long_with_stop(val); | |||
std::cout << result << std::endl; | |||
} | |||
catch (std::logic_error& e) | |||
catch (const std::logic_error& e) | |||
{ | |||
std::cout << e.what() << std::endl; | |||
} |
@@ -34,7 +34,7 @@ | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>ClangCL</PlatformToolset> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>NotSet</CharacterSet> | |||
</PropertyGroup> | |||
@@ -46,7 +46,7 @@ | |||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | |||
<ConfigurationType>Application</ConfigurationType> | |||
<UseDebugLibraries>false</UseDebugLibraries> | |||
<PlatformToolset>ClangCL</PlatformToolset> | |||
<PlatformToolset>v142</PlatformToolset> | |||
<WholeProgramOptimization>true</WholeProgramOptimization> | |||
<CharacterSet>NotSet</CharacterSet> | |||
</PropertyGroup> | |||
@@ -138,6 +138,8 @@ | |||
<DisableSpecificWarnings>4834;4505</DisableSpecificWarnings> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration> | |||
<RuntimeTypeInfo>true</RuntimeTypeInfo> | |||
<ExceptionHandling>Async</ExceptionHandling> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> | |||
@@ -169,6 +171,8 @@ | |||
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration> | |||
<DisableSpecificWarnings>4834;4505</DisableSpecificWarnings> | |||
<FunctionLevelLinking>true</FunctionLevelLinking> | |||
<RuntimeTypeInfo>true</RuntimeTypeInfo> | |||
<ExceptionHandling>Async</ExceptionHandling> | |||
</ClCompile> | |||
<Link> | |||
<SubSystem>Console</SubSystem> |