diff --git a/dep/asio/CMakeLists.txt b/dep/asio/CMakeLists.txt index 64bfb87..0c2d40f 100644 --- a/dep/asio/CMakeLists.txt +++ b/dep/asio/CMakeLists.txt @@ -1,9 +1,11 @@ add_library(asio STATIC - ${CMAKE_CURRENT_LIST_DIR}/asio/asio/src/asio.cpp) + ${CMAKE_CURRENT_LIST_DIR}/asio/asio/src/asio.cpp + ${CMAKE_CURRENT_LIST_DIR}/include/boost/throw_exception.hpp) target_include_directories(asio PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/asio/asio/include) + ${CMAKE_CURRENT_LIST_DIR}/asio/asio/include + ${CMAKE_CURRENT_LIST_DIR}/include) target_compile_definitions(asio PUBLIC @@ -11,6 +13,15 @@ target_compile_definitions(asio -DASIO_SEPARATE_COMPILATION=1 -DASIO_NO_TYPEID=1) +if (CTI_CONTINUABLE_WITH_NO_EXCEPTIONS) + target_compile_definitions(asio + PUBLIC + -DASIO_NO_EXCEPTIONS=1 + -DASIO_HAS_BOOST_THROW_EXCEPTION=1) + + message(STATUS "ASIO: Disabled exceptions") +endif() + if(WIN32) target_compile_definitions(asio PUBLIC diff --git a/dep/asio/include/boost/throw_exception.hpp b/dep/asio/include/boost/throw_exception.hpp new file mode 100644 index 0000000..5aad775 --- /dev/null +++ b/dep/asio/include/boost/throw_exception.hpp @@ -0,0 +1,47 @@ + +/* + + /~` _ _ _|_. _ _ |_ | _ + \_,(_)| | | || ||_|(_||_)|(/_ + + https://github.com/Naios/continuable + v4.0.0 + + Copyright(c) 2015 - 2019 Denis Blank + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files(the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and / or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions : + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +**/ + +#ifndef CONTINUABLE_DETAIL_BOOST_THROW_EXCEPTION_HPP_INCLUDED +#define CONTINUABLE_DETAIL_BOOST_THROW_EXCEPTION_HPP_INCLUDED + +#if defined(ASIO_STANDALONE) && defined(ASIO_NO_EXCEPTIONS) +# include +# include + +namespace boost { +template +void throw_exception(Exception const& e) { + puts(e.what()); + std::abort(); +} +} // namespace boost +#endif + +#endif // CONTINUABLE_DETAIL_BOOST_THROW_EXCEPTION_HPP_INCLUDED diff --git a/include/continuable/detail/transforms/wait.hpp b/include/continuable/detail/transforms/wait.hpp index 0ab4db3..fbb4079 100644 --- a/include/continuable/detail/transforms/wait.hpp +++ b/include/continuable/detail/transforms/wait.hpp @@ -60,26 +60,24 @@ struct sync_trait> { using lock_t = std::unique_lock; using condition_variable_t = std::condition_variable; -template -auto wait_relaxed(continuable_base&& continuable) { +template ::result_t> +Result wait_relaxed(continuable_base&& continuable) { // Do an immediate unpack if the continuable is ready if (continuable.is_ready()) { return std::move(continuable).unpack(); } - constexpr auto hint = base::annotation_of(identify{}); - using result_t = typename sync_trait>::result_t; - (void)hint; - std::mutex cv_mutex; condition_variable_t cv; std::atomic_bool ready{false}; - result_t sync_result; + Result sync_result; std::move(continuable) .next([&](auto&&... args) { - sync_result = result_t::from(std::forward(args)...); + sync_result = typename Result::from( + std::forward(args)...); ready.store(true, std::memory_order_release); cv.notify_all(); @@ -124,19 +122,17 @@ struct wait_frame { Result sync_result; }; -template -auto wait_unsafe(continuable_base&& continuable, - Waiter&& waiter) { +template ::result_t> +Result wait_unsafe(continuable_base&& continuable, + Waiter&& waiter) { // Do an immediate unpack if the continuable is ready if (continuable.is_ready()) { return std::move(continuable).unpack(); } - constexpr auto hint = base::annotation_of(identify{}); - using result_t = typename sync_trait>::result_t; - (void)hint; - using frame_t = wait_frame; + using frame_t = wait_frame; auto frame = std::make_shared(); @@ -145,7 +141,7 @@ auto wait_unsafe(continuable_base&& continuable, if (auto locked = frame.lock()) { { std::lock_guard rw_lock(locked->rw_mutex); - locked->sync_result = result_t::from( + locked->sync_result = typename Result::from( std::forward(args)...); } @@ -164,7 +160,7 @@ auto wait_unsafe(continuable_base&& continuable, return ([&] { std::lock_guard rw_lock(frame->rw_mutex); - result_t cached = std::move(frame->sync_result); + Result cached = std::move(frame->sync_result); return cached; })(); }