Fix the ci build when exceptions are disabled

This commit is contained in:
Denis Blank 2020-04-04 02:50:04 +02:00
parent c69385be5f
commit 0fb66a7eec
3 changed files with 73 additions and 19 deletions

View File

@ -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

View File

@ -0,0 +1,47 @@
/*
/~` _ _ _|_. _ _ |_ | _
\_,(_)| | | || ||_|(_||_)|(/_
https://github.com/Naios/continuable
v4.0.0
Copyright(c) 2015 - 2019 Denis Blank <denis.blank at outlook dot com>
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 <cstdio>
# include <cstdlib>
namespace boost {
template <typename Exception>
void throw_exception(Exception const& e) {
puts(e.what());
std::abort();
}
} // namespace boost
#endif
#endif // CONTINUABLE_DETAIL_BOOST_THROW_EXCEPTION_HPP_INCLUDED

View File

@ -60,26 +60,24 @@ struct sync_trait<identity<Args...>> {
using lock_t = std::unique_lock<std::mutex>;
using condition_variable_t = std::condition_variable;
template <typename Data, typename Annotation>
auto wait_relaxed(continuable_base<Data, Annotation>&& continuable) {
template <typename Data, typename Annotation,
typename Result = typename sync_trait<Annotation>::result_t>
Result wait_relaxed(continuable_base<Data, Annotation>&& 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<decltype(continuable)>{});
using result_t = typename sync_trait<std::decay_t<decltype(hint)>>::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<decltype(args)>(args)...);
sync_result = typename Result::from(
std::forward<decltype(args)>(args)...);
ready.store(true, std::memory_order_release);
cv.notify_all();
@ -124,8 +122,9 @@ struct wait_frame {
Result sync_result;
};
template <typename Data, typename Annotation, typename Waiter>
auto wait_unsafe(continuable_base<Data, Annotation>&& continuable,
template <typename Data, typename Annotation, typename Waiter,
typename Result = typename sync_trait<Annotation>::result_t>
Result wait_unsafe(continuable_base<Data, Annotation>&& continuable,
Waiter&& waiter) {
// Do an immediate unpack if the continuable is ready
@ -133,10 +132,7 @@ auto wait_unsafe(continuable_base<Data, Annotation>&& continuable,
return std::move(continuable).unpack();
}
constexpr auto hint = base::annotation_of(identify<decltype(continuable)>{});
using result_t = typename sync_trait<std::decay_t<decltype(hint)>>::result_t;
(void)hint;
using frame_t = wait_frame<result_t>;
using frame_t = wait_frame<Result>;
auto frame = std::make_shared<frame_t>();
@ -145,7 +141,7 @@ auto wait_unsafe(continuable_base<Data, Annotation>&& continuable,
if (auto locked = frame.lock()) {
{
std::lock_guard<std::mutex> rw_lock(locked->rw_mutex);
locked->sync_result = result_t::from(
locked->sync_result = typename Result::from(
std::forward<decltype(args)>(args)...);
}
@ -164,7 +160,7 @@ auto wait_unsafe(continuable_base<Data, Annotation>&& continuable,
return ([&] {
std::lock_guard<std::mutex> rw_lock(frame->rw_mutex);
result_t cached = std::move(frame->sync_result);
Result cached = std::move(frame->sync_result);
return cached;
})();
}