diff --git a/CMakeLists.txt b/CMakeLists.txt index 089454615e..52e613376e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,6 @@ include(BuildInfoGenerator) include(IncludeDirectories) include(TargetSettings) -include(PrecompiledHeaders) add_subdirectory(bcos-boostssl) add_subdirectory(bcos-framework) diff --git a/bcos-framework/CMakeLists.txt b/bcos-framework/CMakeLists.txt index d5aa1c7e3f..a37d3e4ac3 100644 --- a/bcos-framework/CMakeLists.txt +++ b/bcos-framework/CMakeLists.txt @@ -27,13 +27,7 @@ add_library(bcos-framework INTERFACE) target_include_directories(bcos-framework INTERFACE $ $) - -if (PRECOMPILED_HEADER) - target_link_libraries(bcos-framework INTERFACE bcos-task Microsoft.GSL::GSL precompiled-headers) - target_precompile_headers(bcos-framework REUSE_FROM precompiled-headers) -else() - target_link_libraries(bcos-framework INTERFACE bcos-task Microsoft.GSL::GSL fmt::fmt) -endif() +target_link_libraries(bcos-framework INTERFACE bcos-task Microsoft.GSL::GSL fmt::fmt) if (TESTS) enable_testing() diff --git a/bcos-framework/bcos-framework/ledger/LedgerInterface.h b/bcos-framework/bcos-framework/ledger/LedgerInterface.h index da86497aab..c55797e099 100644 --- a/bcos-framework/bcos-framework/ledger/LedgerInterface.h +++ b/bcos-framework/bcos-framework/ledger/LedgerInterface.h @@ -28,7 +28,6 @@ #include "../storage/StorageInterface.h" #include "LedgerTypeDef.h" #include -#include #include #include #include diff --git a/bcos-framework/bcos-framework/storage/LegacyStorageMethods.h b/bcos-framework/bcos-framework/storage/LegacyStorageMethods.h index 1e3d703f8e..4e1034b699 100644 --- a/bcos-framework/bcos-framework/storage/LegacyStorageMethods.h +++ b/bcos-framework/bcos-framework/storage/LegacyStorageMethods.h @@ -20,7 +20,7 @@ inline task::Task> tag_invoke(storage2::tag_t, std::exception_ptr> m_result; constexpr static bool await_ready() noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { m_storage.asyncGetRow(m_table, m_key, [this, handle](Error::UniquePtr error, std::optional entry) mutable { @@ -98,7 +98,7 @@ inline task::Task tag_invoke(storage2::tag_t /*unused* std::variant m_result; constexpr static bool await_ready() noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { m_storage.asyncSetRow( m_table, m_key, std::move(m_entry), [this, handle](Error::UniquePtr error) mutable { diff --git a/bcos-front/bcos-front/FrontImpl.h b/bcos-front/bcos-front/FrontImpl.h index df93ab2e00..19239433a3 100644 --- a/bcos-front/bcos-front/FrontImpl.h +++ b/bcos-front/bcos-front/FrontImpl.h @@ -40,7 +40,7 @@ class FrontImpl : public bcos::concepts::front::FrontBase {} constexpr bool await_ready() const noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { bcos::concepts::getRef(m_gateway).asyncGetPeers( [this, m_handle = handle](Error::Ptr error, const gateway::GatewayInfo::Ptr&, @@ -123,7 +123,7 @@ class FrontImpl : public bcos::concepts::front::FrontBase { constexpr bool await_ready() const { return false; } - void await_suspend(CO_STD::coroutine_handle::promise_type> handle) + void await_suspend(std::coroutine_handle::promise_type> handle) { FRONT_LOG(DEBUG) << "P2P client send message: " << m_moduleID << " | " << m_nodeID->hex() << " | " << m_requestBuffer.size(); diff --git a/bcos-ledger/src/libledger/LedgerMethods.cpp b/bcos-ledger/src/libledger/LedgerMethods.cpp index 5a932c9728..44a0b0dc32 100644 --- a/bcos-ledger/src/libledger/LedgerMethods.cpp +++ b/bcos-ledger/src/libledger/LedgerMethods.cpp @@ -22,7 +22,7 @@ bcos::task::Task bcos::ledger::prewriteBlockToStorage(LedgerInterface& led Error::Ptr m_error; constexpr static bool await_ready() noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { m_ledger.asyncPrewriteBlock( m_storage, std::move(m_transactions), std::move(m_block), @@ -74,7 +74,7 @@ bcos::task::Task bcos::ledger::tag_invoke( std::variant m_result; constexpr static bool await_ready() noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { m_ledger.asyncGetBlockDataByNumber(m_blockNumber, m_blockFlag, [this, handle](Error::Ptr error, bcos::protocol::Block::Ptr block) { @@ -113,7 +113,7 @@ bcos::task::Task bcos::ledger::tag_invoke( std::variant m_result; constexpr static bool await_ready() noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { m_ledger.asyncGetTotalTransactionCount( [this, handle](Error::Ptr error, int64_t total, int64_t failed, @@ -155,7 +155,7 @@ bcos::task::Task bcos::ledger::tag_invoke( std::variant m_result; constexpr static bool await_ready() noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { m_ledger.asyncGetBlockNumber( [this, handle](Error::Ptr error, bcos::protocol::BlockNumber blockNumber) { @@ -195,7 +195,7 @@ bcos::task::Task bcos::ledger::tag_invoke( std::variant m_result; constexpr static bool await_ready() noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { m_ledger.asyncGetBlockHashByNumber( m_blockNumber, [this, handle](Error::Ptr error, crypto::HashType hash) { @@ -236,7 +236,7 @@ bcos::task::Task bcos::ledger::tag_invoke( std::variant m_result; constexpr static bool await_ready() noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { m_ledger.asyncGetBlockNumberByHash( m_hash, [this, handle](bcos::Error::Ptr error, bcos::protocol::BlockNumber number) { @@ -275,7 +275,7 @@ bcos::task::Task> bcos::ledger::t std::variant> m_result; constexpr static bool await_ready() noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { m_ledger.asyncGetSystemConfigByKey( m_key, [this, handle](Error::Ptr error, std::string value, @@ -325,7 +325,7 @@ bcos::task::Task bcos::ledger::tag_invoke( std::variant m_result; constexpr static bool await_ready() noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { m_ledger.asyncGetNodeListByType( m_type, [this, handle](Error::Ptr error, @@ -485,7 +485,7 @@ bcos::task::Task bcos::ledger::tag std::variant m_result; constexpr static bool await_ready() noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { m_ledger.asyncGetTransactionReceiptByHash(m_hash, false, [this, handle](bcos::Error::Ptr error, @@ -526,7 +526,7 @@ bcos::task::Task bcos::ledger::tag_invoke( std::variant m_result; constexpr static bool await_ready() noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { m_ledger.asyncGetBatchTxsByHashList( std::move(m_hashes), false, [this, handle](auto&& error, auto&& txs, auto&&) { diff --git a/bcos-rpc/bcos-rpc/web3jsonrpc/endpoints/EthEndpoint.cpp b/bcos-rpc/bcos-rpc/web3jsonrpc/endpoints/EthEndpoint.cpp index decf6d9a53..80de36de15 100644 --- a/bcos-rpc/bcos-rpc/web3jsonrpc/endpoints/EthEndpoint.cpp +++ b/bcos-rpc/bcos-rpc/web3jsonrpc/endpoints/EthEndpoint.cpp @@ -351,7 +351,7 @@ task::Task EthEndpoint::getCode(const Json::Value& request, Json::Value& r std::string m_address; std::variant m_result{}; constexpr static bool await_ready() noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) noexcept + void await_suspend(std::coroutine_handle<> handle) noexcept { m_scheduler->getCode(m_address, [this, handle](auto&& error, auto&& code) { if (error) @@ -497,7 +497,7 @@ task::Task EthEndpoint::call(const Json::Value& request, Json::Value& resp bcos::protocol::Transaction::Ptr m_tx; std::variant m_result{}; constexpr static bool await_ready() noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) noexcept + void await_suspend(std::coroutine_handle<> handle) noexcept { m_scheduler.call(m_tx, [this, handle](Error::Ptr&& error, auto&& result) { if (error) diff --git a/bcos-sdk/bcos-cpp-sdk/tarsRPC/CoRPCClient.cpp b/bcos-sdk/bcos-cpp-sdk/tarsRPC/CoRPCClient.cpp index c7bf216b36..e787c839aa 100644 --- a/bcos-sdk/bcos-cpp-sdk/tarsRPC/CoRPCClient.cpp +++ b/bcos-sdk/bcos-cpp-sdk/tarsRPC/CoRPCClient.cpp @@ -4,10 +4,10 @@ class CoCallback : public bcos::sdk::Callback { private: - CO_STD::coroutine_handle<> m_handle; + std::coroutine_handle<> m_handle; public: - CoCallback(CO_STD::coroutine_handle<> handle) : m_handle(handle) {} + CoCallback(std::coroutine_handle<> handle) : m_handle(handle) {} void onMessage([[maybe_unused]] int seq) override { // Make sure we are in the io thread of tars! @@ -18,7 +18,7 @@ class CoCallback : public bcos::sdk::Callback bcos::sdk::async::Awaitable bcos::sdk::async::sendTransaction( RPCClient& rpcClient, const bcos::protocol::Transaction& transaction) { - return {[&](CO_STD::coroutine_handle<> handle) { + return {[&](std::coroutine_handle<> handle) { bcos::sdk::SendTransaction sendTransaction(rpcClient); sendTransaction.setCallback(std::make_shared(handle)); sendTransaction.send(transaction); @@ -29,7 +29,7 @@ bcos::sdk::async::Awaitable bcos::sdk::async::sendTr bcos::sdk::async::Awaitable bcos::sdk::async::call( RPCClient& rpcClient, const bcos::protocol::Transaction& transaction) { - return {[&](CO_STD::coroutine_handle<> handle) { + return {[&](std::coroutine_handle<> handle) { bcos::sdk::Call call(rpcClient); call.setCallback(std::make_shared(handle)); call.send(transaction); @@ -40,7 +40,7 @@ bcos::sdk::async::Awaitable bcos::sdk::async::call( bcos::sdk::async::Awaitable bcos::sdk::async::blockNumber( RPCClient& rpcClient) { - return {[&](CO_STD::coroutine_handle<> handle) { + return {[&](std::coroutine_handle<> handle) { bcos::sdk::BlockNumber blockNumber(rpcClient); blockNumber.setCallback(std::make_shared(handle)); blockNumber.send(); diff --git a/bcos-sdk/bcos-cpp-sdk/tarsRPC/CoRPCClient.h b/bcos-sdk/bcos-cpp-sdk/tarsRPC/CoRPCClient.h index d56acf37bb..71e8437cf6 100644 --- a/bcos-sdk/bcos-cpp-sdk/tarsRPC/CoRPCClient.h +++ b/bcos-sdk/bcos-cpp-sdk/tarsRPC/CoRPCClient.h @@ -1,9 +1,6 @@ #pragma once #include "RPCClient.h" -#include -#include -#include -#include +#include namespace bcos::sdk::async { @@ -12,14 +9,14 @@ template class Awaitable { private: - std::function)> m_applyCall; + std::function)> m_applyCall; std::optional m_handle; public: Awaitable(decltype(m_applyCall) applyCall) : m_applyCall(std::move(applyCall)) {} constexpr bool await_ready() const { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) { m_handle.emplace(m_applyCall(handle)); } + void await_suspend(std::coroutine_handle<> handle) { m_handle.emplace(m_applyCall(handle)); } Handle await_resume() { return std::move(*m_handle); } }; diff --git a/bcos-sync/bcos-sync/state/SyncPeerStatus.h b/bcos-sync/bcos-sync/state/SyncPeerStatus.h index 7b6c0035ec..cf2c62f1f5 100644 --- a/bcos-sync/bcos-sync/state/SyncPeerStatus.h +++ b/bcos-sync/bcos-sync/state/SyncPeerStatus.h @@ -77,8 +77,8 @@ class PeerStatus private: bcos::crypto::PublicPtr m_nodeId; - bcos::protocol::BlockNumber m_number; - bcos::protocol::BlockNumber m_archivedNumber; + bcos::protocol::BlockNumber m_number{}; + bcos::protocol::BlockNumber m_archivedNumber{}; bcos::crypto::HashType m_hash; bcos::crypto::HashType m_genesisHash; diff --git a/bcos-tars-protocol/bcos-tars-protocol/client/TxPoolServiceClient.h b/bcos-tars-protocol/bcos-tars-protocol/client/TxPoolServiceClient.h index f0b56df6c2..0045ede0d1 100644 --- a/bcos-tars-protocol/bcos-tars-protocol/client/TxPoolServiceClient.h +++ b/bcos-tars-protocol/bcos-tars-protocol/client/TxPoolServiceClient.h @@ -57,7 +57,7 @@ class TxPoolServiceClient : public bcos::txpool::TxPoolInterface m_handle.resume(); } - CO_STD::coroutine_handle<> m_handle; + std::coroutine_handle<> m_handle; std::variant m_submitResult; @@ -67,7 +67,7 @@ class TxPoolServiceClient : public bcos::txpool::TxPoolInterface struct Awaitable { constexpr bool await_ready() { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { m_callback->m_handle = handle; m_proxy->tars_set_timeout(600000)->async_submit(m_callback, diff --git a/bcos-txpool/bcos-txpool/txpool/storage/MemoryStorage.cpp b/bcos-txpool/bcos-txpool/txpool/storage/MemoryStorage.cpp index bf66b9016c..245d5c88e5 100644 --- a/bcos-txpool/bcos-txpool/txpool/storage/MemoryStorage.cpp +++ b/bcos-txpool/bcos-txpool/txpool/storage/MemoryStorage.cpp @@ -99,7 +99,7 @@ task::Task MemoryStorage::submitTransact struct Awaitable { [[maybe_unused]] constexpr bool await_ready() { return false; } - [[maybe_unused]] void await_suspend(CO_STD::coroutine_handle<> handle) + [[maybe_unused]] void await_suspend(std::coroutine_handle<> handle) { try { @@ -180,7 +180,7 @@ task::Task MemoryStorage::submitTransact struct Awaitable { [[maybe_unused]] constexpr bool await_ready() { return false; } - [[maybe_unused]] void await_suspend(CO_STD::coroutine_handle<> handle) + [[maybe_unused]] void await_suspend(std::coroutine_handle<> handle) { try { diff --git a/cmake/CompilerSettings.cmake b/cmake/CompilerSettings.cmake index d55cff939d..051f6fd207 100644 --- a/cmake/CompilerSettings.cmake +++ b/cmake/CompilerSettings.cmake @@ -107,7 +107,6 @@ if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR("${CMAKE_CXX_COMPILER_ID}" MATC add_compile_options(-fstack-protector-strong) add_compile_options(-fstack-protector) - add_compile_options(-fno-omit-frame-pointer) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.0) add_compile_options(-fcoroutines) @@ -116,7 +115,7 @@ if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR("${CMAKE_CXX_COMPILER_ID}" MATC add_compile_options(-fPIC) add_compile_options(-Wno-error=nonnull) - add_compile_options(-foptimize-sibling-calls) + # add_compile_options(-foptimize-sibling-calls) add_compile_options(-Wno-stringop-overflow) add_compile_options(-Wno-restrict) add_compile_options(-Wno-error=format-truncation) @@ -127,7 +126,11 @@ if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR("${CMAKE_CXX_COMPILER_ID}" MATC add_compile_options(-Wno-array-bounds) add_compile_options(-Wno-aggressive-loop-optimizations) endif() - # add_compile_options(-fconcepts-diagnostics-depth=10) + + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14.0) + set(CMAKE_CXX_STANDARD 23) + add_compile_options(-Wno-error=uninitialized) + endif() elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0) set(CMAKE_CXX_FLAGS_DEBUG "-O -g") @@ -172,7 +175,6 @@ if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR("${CMAKE_CXX_COMPILER_ID}" MATC endif() elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC") add_compile_definitions(NOMINMAX) - #add_definitions(-DUSE_STD_RANGES) add_compile_options(/std:c++latest) add_compile_options(-bigobj) diff --git a/cmake/Options.cmake b/cmake/Options.cmake index 0d589906aa..54e1332356 100644 --- a/cmake/Options.cmake +++ b/cmake/Options.cmake @@ -56,7 +56,6 @@ macro(configure_project) default_option(SANITIZE_ADDRESS OFF) default_option(SANITIZE_THREAD OFF) default_option(IPO OFF) - default_option(PRECOMPILED_HEADER OFF) if(IPO) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) endif() @@ -156,7 +155,6 @@ macro(print_config NAME) message("-- TESTS Build tests ${TESTS}") message("-- NATIVE Build native binary ${NATIVE}") message("-- IPO Enable IPO optimization ${IPO}") - message("-- PRECOMPILED_HEADER Enable precompiled header ${PRECOMPILED_HEADER}") message("-- SANITIZE_ADDRESS Enable sanitize ${SANITIZE_ADDRESS}") message("-- SANITIZE_THREAD Enable sanitize ${SANITIZE_THREAD}") message("-- TOOLCHAIN_FILE CMake toolchain file ${CMAKE_TOOLCHAIN_FILE}") diff --git a/cmake/PrecompiledHeaders.cmake b/cmake/PrecompiledHeaders.cmake deleted file mode 100644 index fb74029a87..0000000000 --- a/cmake/PrecompiledHeaders.cmake +++ /dev/null @@ -1,104 +0,0 @@ -if (PRECOMPILED_HEADER) - add_library(precompiled-headers INTERFACE) - target_precompile_headers(precompiled-headers - INTERFACE - # STL - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Boost - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # gsl - - - # fmt - - - # tbb - - - - - - - - - - - - - - # range - - ) - - include(GNUInstallDirs) - install(TARGETS precompiled-headers EXPORT fiscobcosTargets ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") - install(DIRECTORY "precompiled-headers" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" FILES_MATCHING PATTERN "*.h") -endif() \ No newline at end of file diff --git a/libtask/bcos-task/AwaitableValue.h b/libtask/bcos-task/AwaitableValue.h index 0c6bef4b38..6456130b60 100644 --- a/libtask/bcos-task/AwaitableValue.h +++ b/libtask/bcos-task/AwaitableValue.h @@ -1,6 +1,6 @@ #pragma once -#include "Coroutine.h" +#include #include namespace bcos::task @@ -13,7 +13,7 @@ class [[nodiscard]] AwaitableValue AwaitableValue() = default; AwaitableValue(Value&& value) : m_value(std::forward(value)) {} constexpr static bool await_ready() noexcept { return true; } - constexpr static bool await_suspend([[maybe_unused]] CO_STD::coroutine_handle<> handle) noexcept + constexpr static bool await_suspend([[maybe_unused]] std::coroutine_handle<> handle) noexcept { return false; } @@ -30,7 +30,7 @@ struct [[nodiscard]] AwaitableValue { AwaitableValue() = default; static constexpr bool await_ready() noexcept { return true; } - static constexpr bool await_suspend([[maybe_unused]] CO_STD::coroutine_handle<> handle) noexcept + static constexpr bool await_suspend([[maybe_unused]] std::coroutine_handle<> handle) noexcept { return false; } diff --git a/libtask/bcos-task/Coroutine.h b/libtask/bcos-task/Coroutine.h deleted file mode 100644 index e4388affd4..0000000000 --- a/libtask/bcos-task/Coroutine.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#if !__cpp_impl_coroutine -#include -namespace CO_STD = std::experimental; -#else -#include -namespace CO_STD = std; -#endif \ No newline at end of file diff --git a/libtask/bcos-task/Generator.h b/libtask/bcos-task/Generator.h index 8ba59c8647..9cb550e30f 100644 --- a/libtask/bcos-task/Generator.h +++ b/libtask/bcos-task/Generator.h @@ -1,16 +1,26 @@ #pragma once -// Fork from https://open-std.org/JTC1/SC22/WG21/docs/papers/2020/p2168r0.pdf -// Can be replace with std::generator +#include -#include "Coroutine.h" +#if __cpp_lib_generator >= 202207L +#include +namespace bcos::task +{ +template +using Generator = std::generator; +} +#else +#include #include #include +#include #include - namespace bcos::task { -template > +// Fork from https://open-std.org/JTC1/SC22/WG21/docs/papers/2020/p2168r0.pdf +// Can be replace with std::generator + +template , typename Alloc = void> class Generator { public: @@ -20,7 +30,7 @@ class Generator promise_type() : m_promise(this) {} Generator get_return_object() noexcept { - return Generator{CO_STD::coroutine_handle::from_promise(*this)}; + return Generator{std::coroutine_handle::from_promise(*this)}; } void unhandled_exception() @@ -34,21 +44,20 @@ class Generator void return_void() noexcept {} - CO_STD::suspend_always initial_suspend() noexcept { return {}; } + std::suspend_always initial_suspend() noexcept { return {}; } // Transfers control back to the parent of a nested coroutine struct final_awaiter { bool await_ready() noexcept { return false; } - CO_STD::coroutine_handle<> await_suspend( - CO_STD::coroutine_handle h) noexcept + std::coroutine_handle<> await_suspend(std::coroutine_handle h) noexcept { auto& promise = h.promise(); auto parent = h.promise().m_parent; if (parent) { promise.m_promise = parent; - return CO_STD::coroutine_handle::from_promise(*parent); + return std::coroutine_handle::from_promise(*parent); } return std::noop_coroutine(); } @@ -57,12 +66,12 @@ class Generator final_awaiter final_suspend() noexcept { return {}; } - CO_STD::suspend_always yield_value(Ref&& x) noexcept + std::suspend_always yield_value(Ref&& x) noexcept { m_promise->m_value = std::addressof(x); return {}; } - CO_STD::suspend_always yield_value(Ref& x) noexcept + std::suspend_always yield_value(Ref& x) noexcept { m_promise->m_value = std::addressof(x); return {}; @@ -83,7 +92,7 @@ class Generator // set the parent, root and exceptions pointer and // resume the nested coroutine - CO_STD::coroutine_handle<> await_suspend( + std::coroutine_handle<> await_suspend( std::coroutine_handle handle) noexcept { auto& current = handle.promise(); @@ -156,7 +165,7 @@ class Generator class Iterator { - using coroutine_handle = CO_STD::coroutine_handle; + using coroutine_handle = std::coroutine_handle; public: using iterator_category = std::input_iterator_tag; @@ -165,7 +174,6 @@ class Generator using reference = Ref; using pointer = std::add_pointer_t; - Iterator() noexcept = default; Iterator& operator=(const Iterator&) = delete; Iterator(const Iterator&) = delete; Iterator(Iterator&& o) noexcept { std::swap(coro_, o.coro_); } @@ -225,4 +233,5 @@ class Generator std::coroutine_handle coro_; }; -} // namespace bcos::task \ No newline at end of file +} // namespace bcos::task +#endif \ No newline at end of file diff --git a/libtask/bcos-task/TBBScheduler.h b/libtask/bcos-task/TBBScheduler.h index 1d34a4c46e..546735675f 100644 --- a/libtask/bcos-task/TBBScheduler.h +++ b/libtask/bcos-task/TBBScheduler.h @@ -1,6 +1,6 @@ #pragma once -#include "Coroutine.h" #include +#include namespace bcos::task::tbb { @@ -14,9 +14,9 @@ class TBBScheduler TBBScheduler(oneapi::tbb::task_group& taskGroup) : m_taskGroup(taskGroup) {} constexpr static bool await_ready() noexcept { return false; } - void await_suspend([[maybe_unused]] CO_STD::coroutine_handle<> handle) noexcept + void await_suspend([[maybe_unused]] std::coroutine_handle<> handle) noexcept { - m_taskGroup.run([handle]() { const_cast&>(handle).resume(); }); + m_taskGroup.run([handle]() { const_cast&>(handle).resume(); }); } constexpr static void await_resume() noexcept {} }; diff --git a/libtask/bcos-task/Task.h b/libtask/bcos-task/Task.h index 9963238782..f8d28496cd 100644 --- a/libtask/bcos-task/Task.h +++ b/libtask/bcos-task/Task.h @@ -1,10 +1,9 @@ #pragma once -#include "Coroutine.h" #include "bcos-concepts/Exception.h" #include #include +#include #include -#include #include #include @@ -26,30 +25,30 @@ class [[nodiscard]] Task struct Continuation { - CO_STD::coroutine_handle<> handle; + std::coroutine_handle<> handle; VariantType value; }; template struct PromiseBase { - constexpr CO_STD::suspend_always initial_suspend() noexcept { return {}; } + constexpr std::suspend_always initial_suspend() noexcept { return {}; } constexpr auto final_suspend() noexcept { struct FinalAwaitable { constexpr bool await_ready() noexcept { return false; } - constexpr CO_STD::coroutine_handle<> await_suspend( - CO_STD::coroutine_handle handle) noexcept + constexpr std::coroutine_handle<> await_suspend( + std::coroutine_handle handle) noexcept { - CO_STD::coroutine_handle<> continuationHandle; + std::coroutine_handle<> continuationHandle; if (handle.promise().m_continuation) { continuationHandle = handle.promise().m_continuation->handle; } handle.destroy(); - return continuationHandle ? continuationHandle : CO_STD::noop_coroutine(); + return continuationHandle ? continuationHandle : std::noop_coroutine(); } constexpr void await_resume() noexcept {} }; @@ -57,8 +56,8 @@ class [[nodiscard]] Task } Task get_return_object() { - auto handle = CO_STD::coroutine_handle::from_promise( - *static_cast(this)); + auto handle = + std::coroutine_handle::from_promise(*static_cast(this)); return Task(handle); } void unhandled_exception() @@ -100,7 +99,7 @@ class [[nodiscard]] Task bool await_ready() const noexcept { return !m_handle || m_handle.done(); } template - CO_STD::coroutine_handle<> await_suspend(CO_STD::coroutine_handle handle) + std::coroutine_handle<> await_suspend(std::coroutine_handle handle) { m_continuation.handle = handle; m_handle.promise().m_continuation = std::addressof(m_continuation); @@ -124,12 +123,12 @@ class [[nodiscard]] Task } } - CO_STD::coroutine_handle m_handle; + std::coroutine_handle m_handle; Continuation m_continuation; }; Awaitable operator co_await() { return Awaitable(*static_cast(this)); } - explicit Task(CO_STD::coroutine_handle handle) : m_handle(handle) {} + explicit Task(std::coroutine_handle handle) : m_handle(handle) {} Task(const Task&) = delete; Task(Task&& task) noexcept : m_handle(task.m_handle) { task.m_handle = nullptr; } Task& operator=(const Task&) = delete; @@ -142,7 +141,7 @@ class [[nodiscard]] Task void start() { m_handle.resume(); } private: - CO_STD::coroutine_handle m_handle; + std::coroutine_handle m_handle; }; } // namespace bcos::task \ No newline at end of file diff --git a/libtask/tests/TestTask.cpp b/libtask/tests/TestTask.cpp index 33733059fa..ef5a7fddea 100644 --- a/libtask/tests/TestTask.cpp +++ b/libtask/tests/TestTask.cpp @@ -99,7 +99,7 @@ Task asyncLevel2(oneapi::tbb::task_group& taskGroup) { constexpr bool await_ready() const { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { std::cout << "Start run async thread: " << handle.address() << std::endl; taskGroup.run([this, m_handle = handle]() { @@ -169,7 +169,7 @@ struct SleepTask inline static oneapi::tbb::concurrent_vector> futures; constexpr static bool await_ready() { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { futures.emplace_back(std::async([m_handle = handle]() mutable { using namespace std::chrono_literals; @@ -207,10 +207,10 @@ struct ResumableTask ResumableTask& operator=(ResumableTask&&) = default; ~ResumableTask() noexcept = default; - CO_STD::coroutine_handle<> m_handle; + std::coroutine_handle<> m_handle; constexpr bool static await_ready() { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { std::cout << "Task suspend!" << std::endl; m_handle = handle; diff --git a/lightnode/bcos-lightnode/scheduler/SchedulerWrapperImpl.h b/lightnode/bcos-lightnode/scheduler/SchedulerWrapperImpl.h index 835eefae52..056994407e 100644 --- a/lightnode/bcos-lightnode/scheduler/SchedulerWrapperImpl.h +++ b/lightnode/bcos-lightnode/scheduler/SchedulerWrapperImpl.h @@ -29,14 +29,14 @@ class SchedulerWrapperImpl auto transactionImpl = std::make_shared( [&transaction]() { return const_cast(&transaction); }); - struct Awaitable : public CO_STD::suspend_always + struct Awaitable : public std::suspend_always { Awaitable(decltype(transactionImpl)& transactionImpl, SchedulerType& scheduler, std::remove_cvref_t& receipt) : m_transactionImpl(transactionImpl), m_scheduler(scheduler), m_receipt(receipt) {} - void await_suspend(CO_STD::coroutine_handle::promise_type> handle) + void await_suspend(std::coroutine_handle::promise_type> handle) { bcos::concepts::getRef(m_scheduler) .call(std::move(m_transactionImpl), diff --git a/lightnode/fisco-bcos-lightnode/client/P2PClientImpl.h b/lightnode/fisco-bcos-lightnode/client/P2PClientImpl.h index 42a059a149..480031c451 100644 --- a/lightnode/fisco-bcos-lightnode/client/P2PClientImpl.h +++ b/lightnode/fisco-bcos-lightnode/client/P2PClientImpl.h @@ -52,7 +52,7 @@ class P2PClientImpl {} constexpr bool await_ready() const { return false; } - void await_suspend(CO_STD::coroutine_handle::promise_type> handle) + void await_suspend(std::coroutine_handle::promise_type> handle) { LIGHTNODE_LOG(DEBUG) << "P2P client send message: " << m_moduleID << " | " << m_nodeID->hex() << " | " << m_requestBuffer.size(); @@ -112,7 +112,7 @@ class P2PClientImpl {} constexpr bool await_ready() const noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { bcos::concepts::getRef(m_gateway).asyncGetPeers( [this, m_handle = handle](Error::Ptr error, const gateway::GatewayInfo::Ptr&, @@ -212,7 +212,7 @@ class P2PClientImpl {} constexpr bool await_ready() const noexcept { return false; } - void await_suspend(CO_STD::coroutine_handle<> handle) + void await_suspend(std::coroutine_handle<> handle) { bcos::concepts::getRef(m_gateway).asyncGetPeers( [this, m_handle = handle](Error::Ptr error, const gateway::GatewayInfo::Ptr&, diff --git a/transaction-scheduler/bcos-transaction-scheduler/SchedulerParallelImpl.h b/transaction-scheduler/bcos-transaction-scheduler/SchedulerParallelImpl.h index d1d29d3aa0..4d84243676 100644 --- a/transaction-scheduler/bcos-transaction-scheduler/SchedulerParallelImpl.h +++ b/transaction-scheduler/bcos-transaction-scheduler/SchedulerParallelImpl.h @@ -40,7 +40,7 @@ struct ExecutionContext { ExecutionContext(int contextID, std::reference_wrapper transaction, std::reference_wrapper receipt, - std::optional coro, typename CoroType::Iterator iterator) + std::optional coro, std::optionalbegin())> iterator) : contextID(contextID), transaction(transaction), receipt(receipt), @@ -51,7 +51,7 @@ struct ExecutionContext std::reference_wrapper transaction; std::reference_wrapper receipt; std::optional coro; - typename CoroType::Iterator iterator; + std::optionalbegin())> iterator; }; template @@ -101,8 +101,8 @@ class ChunkStatus context.coro.emplace(transaction_executor::execute3Step(m_executor.get(), m_readWriteSetStorage, blockHeader, context.transaction.get(), context.contextID, ledgerConfig, task::tbb::syncWait)); - context.iterator = context.coro->begin(); - context.receipt.get() = *context.iterator; + context.iterator.emplace(context.coro->begin()); + context.receipt.get() = *(*context.iterator); } } @@ -119,9 +119,9 @@ class ChunkStatus << " transactions"; break; } - if (!context.receipt.get() && context.iterator != context.coro->end()) + if (!context.receipt.get() && *context.iterator != context.coro->end()) { - context.receipt.get() = *(++context.iterator); + context.receipt.get() = *(++(*context.iterator)); } } } @@ -132,9 +132,9 @@ class ChunkStatus ittapi::ITT_DOMAINS::instance().EXECUTE_CHUNK3); for (auto& context : m_contextRange) { - if (!context.receipt.get() && context.iterator != context.coro->end()) + if (!context.receipt.get() && *context.iterator != context.coro->end()) { - context.receipt.get() = *(++context.iterator); + context.receipt.get() = *(++(*context.iterator)); } } } diff --git a/transaction-scheduler/bcos-transaction-scheduler/SchedulerSerialImpl.h b/transaction-scheduler/bcos-transaction-scheduler/SchedulerSerialImpl.h index a729ea013b..4a1947833d 100644 --- a/transaction-scheduler/bcos-transaction-scheduler/SchedulerSerialImpl.h +++ b/transaction-scheduler/bcos-transaction-scheduler/SchedulerSerialImpl.h @@ -38,7 +38,7 @@ class SchedulerSerialImpl struct ExecutionContext { std::optional coro; - typename CoroType::Iterator iterator; + std::optionalbegin())> iterator; protocol::TransactionReceipt::Ptr receipt; }; @@ -76,8 +76,8 @@ class SchedulerSerialImpl coro.emplace( transaction_executor::execute3Step(executor, storage, blockHeader, transactions[i], i, ledgerConfig, task::tbb::syncWait)); - iterator = coro->begin(); - receipt = *iterator; + iterator.emplace(coro->begin()); + receipt = *(*iterator); } return range; }) & @@ -90,7 +90,7 @@ class SchedulerSerialImpl auto& [coro, iterator, receipt] = contexts[i]; if (!receipt) { - receipt = *(++iterator); + receipt = *(++(*iterator)); } } return range; @@ -104,7 +104,7 @@ class SchedulerSerialImpl auto& [coro, iterator, receipt] = contexts[i]; if (!receipt) { - receipt = *(++iterator); + receipt = *(++(*iterator)); } coro.reset(); } diff --git a/vcpkg.json b/vcpkg.json index cabc752df8..cbfc33f938 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -28,7 +28,6 @@ "boost-container-hash", "boost-multiprecision", "boost-program-options", - "boost-mp11", "ms-gsl", "tbb", {