Browse Source

在实际项目中的一些改进

tags/v2.9.7
tearshark 5 years ago
parent
commit
df90f6ee80

+ 2
- 0
librf/src/def.h View File

#pragma once #pragma once
#define RESUMEF_LIB_INCLUDE 1
//#include <yvals.h> //#include <yvals.h>
#include <atomic> #include <atomic>
#include <memory> #include <memory>

+ 5
- 0
librf/src/rf_task.h View File

{ {
_future = std::move(_context()); _future = std::move(_context());
} }
ctx_task_t(const context_type & ctx)
: _context(ctx)
{
_future = std::move(_context());
}
}; };
} }

+ 1
- 1
librf/src/scheduler.h View File

inline void operator + (_Ty && t_) inline void operator + (_Ty && t_)
{ {
typedef typename std::conditional< typedef typename std::conditional<
std::is_callable_v<_Ty>,
std::is_callable<_Ty>::value,
ctx_task_t<_Ty>, ctx_task_t<_Ty>,
task_t<_Ty> >::type task_type; task_t<_Ty> >::type task_type;
return new_task(new task_type(std::forward<_Ty>(t_))); return new_task(new task_type(std::forward<_Ty>(t_)));

+ 4
- 4
librf/src/timer.h View File

public: public:
timer_handler() = default; timer_handler() = default;
timer_handler(const timer_handler &) = default; timer_handler(const timer_handler &) = default;
timer_handler(timer_handler && right_);
timer_handler(timer_handler && right_) noexcept;
timer_handler & operator = (const timer_handler &) = default; timer_handler & operator = (const timer_handler &) = default;
timer_handler & operator = (timer_handler && right_);
timer_handler & operator = (timer_handler && right_) noexcept;
timer_handler(timer_manager * manager_, const detail::timer_target_ptr & target_); timer_handler(timer_manager * manager_, const detail::timer_target_ptr & target_);
, _target(target_) , _target(target_)
{ {
} }
inline timer_handler::timer_handler(timer_handler && right_)
inline timer_handler::timer_handler(timer_handler && right_) noexcept
: _manager(std::move(right_._manager)) : _manager(std::move(right_._manager))
, _target(std::move(right_._target)) , _target(std::move(right_._target))
{ {
} }
inline timer_handler & timer_handler::operator = (timer_handler && right_)
inline timer_handler & timer_handler::operator = (timer_handler && right_) noexcept
{ {
if (this != &right_) if (this != &right_)
{ {

+ 4
- 3
librf/src/utils.h View File

namespace std namespace std
{ {
template<typename _Function> template<typename _Function>
inline auto _IsCallable(const _Function & _Func, int) -> decltype(_Func(), true_type())
inline auto _IsCallable(_Function && _Func, int) -> decltype(_Func(), true_type())
{ {
(_Func); (_Func);
return true_type(); return true_type();
} }
template<typename _Function> template<typename _Function>
inline false_type _IsCallable(const _Function &, ...)
inline false_type _IsCallable(_Function &&, ...)
{ {
return false_type(); return false_type();
} }
template<typename _Function> template<typename _Function>
using is_callable = decltype(_IsCallable(std::declval<_Function>(), 0)); using is_callable = decltype(_IsCallable(std::declval<_Function>(), 0));
#if _HAS_CXX17
template<typename _Function> template<typename _Function>
_INLINE_VAR constexpr bool is_callable_v = is_callable<_Function>::value; _INLINE_VAR constexpr bool is_callable_v = is_callable<_Function>::value;
#endif
} }

+ 7
- 7
tutorial/test_async_when_all.cpp View File

GO GO
{ {
co_await when_all(); co_await when_all();
std::cout << "zero!" << std::endl << std::endl;
std::cout << "when all: zero!" << std::endl << std::endl;
auto [a, b] = co_await when_all(my_sleep("a"), my_sleep_v("b")); auto [a, b] = co_await when_all(my_sleep("a"), my_sleep_v("b"));
b; //b is std::ignore
std::cout << a << std::endl << std::endl;
(void)b; //b is std::ignore
std::cout << "when all:" << a << std::endl << std::endl;
auto c = co_await my_sleep("c"); auto c = co_await my_sleep("c");
std::cout << c << std::endl << std::endl;
std::cout << "when all:" << c << std::endl << std::endl;
auto [d, e, f] = co_await when_all(my_sleep("d"), my_sleep_v("e"), my_sleep("f")); auto [d, e, f] = co_await when_all(my_sleep("d"), my_sleep_v("e"), my_sleep("f"));
e; //e is std::ignore
std::cout << d << "," << f << std::endl << std::endl;
(void)e; //e is std::ignore
std::cout << "when all:" << d << "," << f << std::endl << std::endl;
std::vector<future_t<int> > v{ my_sleep("g"), my_sleep("h"), my_sleep("i") }; std::vector<future_t<int> > v{ my_sleep("g"), my_sleep("h"), my_sleep("i") };
auto vals = co_await when_all(std::begin(v), std::end(v)); auto vals = co_await when_all(std::begin(v), std::end(v));
std::cout << vals[0] << "," << vals[1] << "," << vals[2] << "," << std::endl << std::endl;
std::cout << "when all:" << vals[0] << "," << vals[1] << "," << vals[2] << "," << std::endl << std::endl;
std::cout << "all range done!" << std::endl; std::cout << "all range done!" << std::endl;
}; };

+ 0
- 3
tutorial/test_async_yield_return.cpp View File

} }
*/ */
#define co_yield_void co_yield nullptr
#define co_return_void co_return nullptr
auto test_yield_void() auto test_yield_void()
{ {
std::cout << "block 1 will yield return" << std::endl; std::cout << "block 1 will yield return" << std::endl;

+ 2
- 3
vs_proj/librf.cpp View File

int main(int argc, const char * argv[]) int main(int argc, const char * argv[])
{ {
resumable_main_sleep();
//resumable_main_sleep();
//resumable_main_resumable(); //resumable_main_resumable();
/*
resumable_main_when_all(); resumable_main_when_all();
resumable_main_multi_thread(); resumable_main_multi_thread();
resumable_main_yield_return(); resumable_main_yield_return();
resumable_main_channel(); resumable_main_channel();
resumable_main_cb(); resumable_main_cb();
resumable_main_exception(); resumable_main_exception();
*/
return 0; return 0;
} }

Loading…
Cancel
Save