mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 08:46:44 +08:00
Fix the ci build when exceptions are disabled
This commit is contained in:
parent
c69385be5f
commit
0fb66a7eec
@ -1,9 +1,11 @@
|
|||||||
add_library(asio STATIC
|
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
|
target_include_directories(asio
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${CMAKE_CURRENT_LIST_DIR}/asio/asio/include)
|
${CMAKE_CURRENT_LIST_DIR}/asio/asio/include
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/include)
|
||||||
|
|
||||||
target_compile_definitions(asio
|
target_compile_definitions(asio
|
||||||
PUBLIC
|
PUBLIC
|
||||||
@ -11,6 +13,15 @@ target_compile_definitions(asio
|
|||||||
-DASIO_SEPARATE_COMPILATION=1
|
-DASIO_SEPARATE_COMPILATION=1
|
||||||
-DASIO_NO_TYPEID=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)
|
if(WIN32)
|
||||||
target_compile_definitions(asio
|
target_compile_definitions(asio
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
|||||||
47
dep/asio/include/boost/throw_exception.hpp
Normal file
47
dep/asio/include/boost/throw_exception.hpp
Normal 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
|
||||||
@ -60,26 +60,24 @@ struct sync_trait<identity<Args...>> {
|
|||||||
using lock_t = std::unique_lock<std::mutex>;
|
using lock_t = std::unique_lock<std::mutex>;
|
||||||
using condition_variable_t = std::condition_variable;
|
using condition_variable_t = std::condition_variable;
|
||||||
|
|
||||||
template <typename Data, typename Annotation>
|
template <typename Data, typename Annotation,
|
||||||
auto wait_relaxed(continuable_base<Data, Annotation>&& continuable) {
|
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
|
// Do an immediate unpack if the continuable is ready
|
||||||
if (continuable.is_ready()) {
|
if (continuable.is_ready()) {
|
||||||
return std::move(continuable).unpack();
|
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;
|
std::mutex cv_mutex;
|
||||||
condition_variable_t cv;
|
condition_variable_t cv;
|
||||||
std::atomic_bool ready{false};
|
std::atomic_bool ready{false};
|
||||||
result_t sync_result;
|
Result sync_result;
|
||||||
|
|
||||||
std::move(continuable)
|
std::move(continuable)
|
||||||
.next([&](auto&&... args) {
|
.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);
|
ready.store(true, std::memory_order_release);
|
||||||
cv.notify_all();
|
cv.notify_all();
|
||||||
@ -124,19 +122,17 @@ struct wait_frame {
|
|||||||
Result sync_result;
|
Result sync_result;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Data, typename Annotation, typename Waiter>
|
template <typename Data, typename Annotation, typename Waiter,
|
||||||
auto wait_unsafe(continuable_base<Data, Annotation>&& continuable,
|
typename Result = typename sync_trait<Annotation>::result_t>
|
||||||
Waiter&& waiter) {
|
Result wait_unsafe(continuable_base<Data, Annotation>&& continuable,
|
||||||
|
Waiter&& waiter) {
|
||||||
|
|
||||||
// Do an immediate unpack if the continuable is ready
|
// Do an immediate unpack if the continuable is ready
|
||||||
if (continuable.is_ready()) {
|
if (continuable.is_ready()) {
|
||||||
return std::move(continuable).unpack();
|
return std::move(continuable).unpack();
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr auto hint = base::annotation_of(identify<decltype(continuable)>{});
|
using frame_t = wait_frame<Result>;
|
||||||
using result_t = typename sync_trait<std::decay_t<decltype(hint)>>::result_t;
|
|
||||||
(void)hint;
|
|
||||||
using frame_t = wait_frame<result_t>;
|
|
||||||
|
|
||||||
auto frame = std::make_shared<frame_t>();
|
auto frame = std::make_shared<frame_t>();
|
||||||
|
|
||||||
@ -145,7 +141,7 @@ auto wait_unsafe(continuable_base<Data, Annotation>&& continuable,
|
|||||||
if (auto locked = frame.lock()) {
|
if (auto locked = frame.lock()) {
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> rw_lock(locked->rw_mutex);
|
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)...);
|
std::forward<decltype(args)>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +160,7 @@ auto wait_unsafe(continuable_base<Data, Annotation>&& continuable,
|
|||||||
|
|
||||||
return ([&] {
|
return ([&] {
|
||||||
std::lock_guard<std::mutex> rw_lock(frame->rw_mutex);
|
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;
|
return cached;
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user