diff --git a/src/Makefile_Cxx.am b/src/Makefile_Cxx.am index fc7c825def..b13880c674 100644 --- a/src/Makefile_Cxx.am +++ b/src/Makefile_Cxx.am @@ -16,9 +16,6 @@ bindings/cxx/eo_cxx/Eo.hh \ bindings/cxx/eo_cxx/eo_init.hh \ bindings/cxx/eo_cxx/eo_ops.hh \ bindings/cxx/eo_cxx/eo_wref.hh \ -bindings/cxx/eo_cxx/eo_future.hh \ -bindings/cxx/eo_cxx/eo_promise.hh \ -bindings/cxx/eo_cxx/eo_promise_meta.hh \ bindings/cxx/eo_cxx/eo_private.hh \ bindings/cxx/eo_cxx/efl_object_impl.hh @@ -247,8 +244,7 @@ tests_eina_cxx_eina_cxx_suite_DEPENDENCIES = @USE_EINA_INTERNAL_LIBS@ @USE_EO_IN tests_eo_cxx_eo_cxx_suite_SOURCES = \ tests/eo_cxx/eo_cxx_suite.cc \ -tests/eo_cxx/eo_cxx_suite.h \ -tests/eo_cxx/eo_cxx_test_promise.cc +tests/eo_cxx/eo_cxx_suite.h tests_eo_cxx_eo_cxx_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ -DTESTS_WD=\"`pwd`\" \ diff --git a/src/bindings/cxx/eo_cxx/Eo.hh b/src/bindings/cxx/eo_cxx/Eo.hh index bd60f69701..4a4da4c6ef 100644 --- a/src/bindings/cxx/eo_cxx/Eo.hh +++ b/src/bindings/cxx/eo_cxx/Eo.hh @@ -8,7 +8,6 @@ #include //#include //#include -#include #include #include diff --git a/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh b/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh index 5dac150b20..fc00db830e 100644 --- a/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh +++ b/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh @@ -7,7 +7,6 @@ #include #include #include -#include #include #include @@ -59,8 +58,6 @@ template struct out_traits> { typedef eina::optional type; }; template <> struct out_traits { typedef void*& type; }; -template -struct out_traits> { typedef efl::shared_future& type; }; template <> struct out_traits { typedef efl::eina::strbuf_wrapper& type; }; @@ -68,8 +65,6 @@ template struct inout_traits { typedef T& type; }; template <> struct inout_traits { typedef void* type; }; -template -struct inout_traits> { typedef efl::shared_future& type; }; template struct return_traits { typedef T type; }; @@ -142,10 +137,6 @@ void assign_out_impl(T& lhs, Eo const* rhs, tag { lhs._reset(const_cast(rhs)); } -template -void assign_out_impl(efl::shared_future& /*v*/, Efl_Future*, tag&, Efl_Future*>) -{ -} template void assign_out_impl(efl::eina::string_view& view, const char* string, Tag) { @@ -277,11 +268,6 @@ Eo const* convert_inout_impl(T v, tag { return v._eo_ptr(); } -template -Efl_Future* convert_inout_impl(efl::shared_future& /*v*/, tag, Efl_Future*>) -{ - return nullptr; -} } template @@ -545,11 +531,6 @@ inline const char* convert_to_c_impl(efl::eina::stringshare x, tag -Efl_Future* convert_to_c_impl(efl::shared_future const&, tagconst&>) -{ - std::abort(); -} template T* convert_to_c_impl(std::unique_ptr& v, tag>) { @@ -709,12 +690,6 @@ eina::accessor convert_to_return(Eina_Accessor* value, tag{ value }; } -template -efl::shared_future convert_to_return(Efl_Future* /*value*/, tag>) -{ - std::abort(); - return {}; -} // Eina_Value* inline efl::eina::value convert_to_return(Eina_Value* value, tag) { diff --git a/src/bindings/cxx/eo_cxx/eo_future.hh b/src/bindings/cxx/eo_cxx/eo_future.hh deleted file mode 100644 index 7ed77cf016..0000000000 --- a/src/bindings/cxx/eo_cxx/eo_future.hh +++ /dev/null @@ -1,505 +0,0 @@ -/// -/// @file eo_future.hh -/// - -#ifndef EFL_CXX_EO_FUTURE_HH -#define EFL_CXX_EO_FUTURE_HH - -#include - -#include -#include - -#include -#include - -#include -#include - -namespace efl { - -template -struct shared_future; - -namespace _impl { - -template -struct wait_state -{ - bool available = false; - bool has_failed = false; - std::mutex mutex; - std::condition_variable cv; - typename std::aligned_storage::type storage; - Eina_Error error; -}; - -inline void get_error_cb(void* data, Efl_Event const* event) -{ - wait_state<>* wait_state_ = static_cast*>(data); - Efl_Future_Event_Failure* info = static_cast(event->info); - std::unique_lock l(wait_state_->mutex); - wait_state_->error = info->error; - wait_state_->has_failed = true; - wait_state_->available = true; - wait_state_->cv.notify_one(); -} - -struct shared_future_common -{ - explicit shared_future_common(Efl_Future* future) - : _future(future) {} - shared_future_common() - : _future(nullptr) {} - ~shared_future_common() - { - if(_future) - efl_unref(_future); - } - shared_future_common(shared_future_common const& future) - : _future(efl_ref(future._future)) - { - } - shared_future_common& operator=(shared_future_common const& other) - { - _self_type tmp(other); - tmp.swap(*this); - return *this; - } - shared_future_common(shared_future_common&& future) - : _future(future._future) - { - future._future = nullptr; - } - shared_future_common& operator=(shared_future_common&& other) - { - other.swap(*this); - return *this; - } - void swap(shared_future_common& other) - { - std::swap(_future, other._future); - } - bool valid() const noexcept - { - return _future != nullptr; - } - void wait() const - { - if(eina_main_loop_is()) - throw std::runtime_error("Deadlock"); - - struct wait_state<> wait_state; - - efl::ecore::main_loop_thread_safe_call_async - ([&] - { - efl_future_then(this->_future, &wait_success, &wait_success, nullptr, &wait_state); - }); - - std::unique_lock lock(wait_state.mutex); - while(!wait_state.available) - wait_state.cv.wait(lock); - } - static void wait_success(void* data, Efl_Event const*) - { - wait_state<>* wait_state_ = static_cast*>(data); - std::unique_lock l(wait_state_->mutex); - wait_state_->available = true; - wait_state_->cv.notify_one(); - } - - typedef Efl_Future* native_handle_type; - native_handle_type native_handle() const noexcept { return _future; } - - typedef shared_future_common _self_type; - Efl_Future* _future; -}; - -template -struct shared_future_1_type : shared_future_common -{ - typedef shared_future_common _base_type; - - using _base_type::_base_type; - shared_future_1_type() = default; - shared_future_1_type(shared_future_common const& other) - : _base_type(other) {} - - T get() const - { - if(eina_main_loop_is()) - throw std::runtime_error("Deadlock"); - - struct wait_state wait_state; - - efl::ecore::main_loop_thread_safe_call_async - ([&] - { - efl_future_then(this->_future, &get_success, &_impl::get_error_cb, nullptr, &wait_state); - }); - - { - std::unique_lock lock(wait_state.mutex); - while(!wait_state.available) - wait_state.cv.wait(lock); - } - if(wait_state.has_failed) - EFL_CXX_THROW(eina::system_error(eina::error_code(wait_state.error, eina::eina_error_category()), "EFL Eina Error")); - return *static_cast(static_cast(&wait_state.storage)); - } - - static void get_success(void* data, Efl_Event const* event) - { - wait_state* wait_state_ = static_cast*>(data); - Efl_Future_Event_Success* info = static_cast(event->info); - - std::unique_lock l(wait_state_->mutex); - _impl::future_copy_traits::copy(static_cast(static_cast(&wait_state_->storage)), info); - wait_state_->available = true; - wait_state_->cv.notify_one(); - } - - typedef shared_future_1_type _self_type; -}; - -template -struct shared_race_future_1_type : shared_future_common -{ - typedef shared_future_common _base_type; - - using _base_type::_base_type; - shared_race_future_1_type(_base_type const& other) - : _base_type(other) {} - - T get() const - { - if(eina_main_loop_is()) - throw std::runtime_error("Deadlock"); - - struct wait_state wait_state; - - efl::ecore::main_loop_thread_safe_call_async - ([&] - { - efl_future_then(this->_future, &get_success, &_impl::get_error_cb, nullptr, &wait_state); - }); - - { - std::unique_lock lock(wait_state.mutex); - while(!wait_state.available) - wait_state.cv.wait(lock); - } - if(wait_state.has_failed) - EFL_CXX_THROW(eina::system_error(eina::error_code(wait_state.error, eina::eina_error_category()), "EFL Eina Error")); - return *static_cast(static_cast(&wait_state.storage)); - } - - static void get_success(void* data, Efl_Event const* event) - { - wait_state* wait_state_ = static_cast*>(data); - Efl_Future_Event_Success* info = static_cast(event->info); - - std::unique_lock l(wait_state_->mutex); - _impl::future_copy_traits::copy_race(static_cast(static_cast(&wait_state_->storage)), info); - wait_state_->available = true; - wait_state_->cv.notify_one(); - } - - typedef shared_race_future_1_type _self_type; -}; - -template -struct shared_future_varargs_type : shared_future_common -{ - typedef shared_future_common _base_type; - - using _base_type::_base_type; - shared_future_varargs_type() = default; - shared_future_varargs_type(_base_type const& other) - : _base_type(other) {} - - typedef std::tuple tuple_type; - - std::tuple get() const - { - if(eina_main_loop_is()) - throw std::runtime_error("Deadlock"); - - struct wait_state wait_state; - - efl::ecore::main_loop_thread_safe_call_async - ([&] - { - efl_future_then(this->_future, &get_success, &_impl::get_error_cb, nullptr, &wait_state); - }); - - { - std::unique_lock lock(wait_state.mutex); - while(!wait_state.available) - wait_state.cv.wait(lock); - } - if(wait_state.has_failed) - EFL_CXX_THROW(eina::system_error(eina::error_code(wait_state.error, eina::eina_error_category()), "EFL Eina Error")); - return *static_cast(static_cast(&wait_state.storage)); - } - - template - static void read_accessor(Eina_Accessor* accessor - , std::tuple::type...>& storage_tuple - , wait_state* wait_state - , std::false_type) - { - typedef typename std::tuple_element::type type; - void* value; - if(eina_accessor_data_get(accessor, N, &value)) - { - eina::copy_from_c_traits::copy_to_unitialized - (static_cast(static_cast(&std::get(storage_tuple))), value); - - _self_type::read_accessor(accessor, storage_tuple, wait_state - , std::integral_constant()); - } - else - { - std::abort(); - // some error - } - } - - template - static void read_accessor_end(std::tuple::type...>& storage_tuple - , wait_state* wait_state - , eina::index_sequence) - { - std::unique_lock l(wait_state->mutex); - - new (&wait_state->storage) tuple_type{(*static_cast::type*> - (static_cast(&std::get(storage_tuple))))...}; - - wait_state->available = true; - wait_state->cv.notify_one(); - } - - template - static void read_accessor(Eina_Accessor* - , std::tuple::type...>& storage_tuple - , wait_state* wait_state - , std::true_type) - { - _self_type::read_accessor_end(storage_tuple, wait_state, eina::make_index_sequence{}); - } - - static void get_success(void* data, Efl_Event const* event) - { - wait_state* wait_state_ = static_cast*>(data); - Efl_Future_Event_Success* info = static_cast(event->info); - - Eina_Accessor* accessor = static_cast(info->value); - std::tuple::type...> storage_tuple; - - _self_type::read_accessor<0u>(accessor, storage_tuple, wait_state_, std::false_type()); - } - - typedef shared_future_varargs_type _self_type; -}; - -} - -template -struct shared_future : private - std::conditional - < - sizeof...(Args) == 1 - , _impl::shared_future_1_type>::type> - , typename std::conditional - <_impl::is_progress>::type>::value - , typename std::conditional - - , _impl::shared_future_varargs_type - >::type - , _impl::shared_future_varargs_type - >::type - >::type -{ - typedef typename - std::conditional - < - sizeof...(Args) == 1 - , _impl::shared_future_1_type - , typename std::conditional - <_impl::is_progress>::type>::value - , typename std::conditional - - , _impl::shared_future_varargs_type - >::type - , _impl::shared_future_varargs_type - >::type - >::type - _base_type; - typedef typename _impl::progress_param::type progress_param_type; - typedef typename _impl::progress_type::type progress_type; - typedef typename _base_type::native_handle_type native_handle_type; - using _base_type::_base_type; - using _base_type::swap; - using _base_type::valid; - using _base_type::get; - using _base_type::wait; - using _base_type::native_handle; - - shared_future() = default; - template - shared_future(shared_future const& other - , typename std::enable_if<_impl::is_progress_param_compatible - ::type>::value>::type* = nullptr) - : _base_type(static_cast< _impl::shared_future_common const&>(other)) - { - } - - template - friend struct shared_future; -}; - -template -struct shared_race_future : private std::conditional>::type>, void>::type -{ - typedef typename std::conditional>::type>, void>::type _base_type; - - using _base_type::_base_type; - using _base_type::swap; - using _base_type::valid; - using _base_type::get; - using _base_type::wait; - using _base_type::native_handle; - typedef typename _base_type::native_handle_type native_handle_type; -}; - -namespace _impl { - -template -struct is_race_future : std::false_type {}; - -template -struct is_race_future> : std::true_type {}; - -} - -template