@@ -0,0 +1 @@ | |||
#include "src/macro_def.inl" |
@@ -25,12 +25,7 @@ namespace asio { | |||
private: | |||
Allocator allocator_; | |||
}; | |||
//constexpr rf_task_t<> rf_task; | |||
#pragma warning(push) | |||
#pragma warning(disable : 4592) | |||
__declspec(selectany) rf_task_t<> rf_task; | |||
#pragma warning(pop) | |||
constexpr rf_task_t<> rf_task; | |||
namespace detail { | |||
@@ -11,12 +11,7 @@ namespace asio { | |||
{ | |||
ASIO_CONSTEXPR rf_task_t() {} | |||
}; | |||
#if defined(ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION) | |||
constexpr rf_task_t<> rf_task; | |||
#elif defined(ASIO_MSVC) | |||
__declspec(selectany) rf_task_t<> rf_task; | |||
#endif | |||
namespace librf { | |||
@@ -1,8 +1,5 @@ | |||
#pragma once | |||
#define RESUMEF_LIB_INCLUDE 1 | |||
//#include <yvals.h> | |||
#include <atomic> | |||
#include <chrono> | |||
#include <vector> | |||
@@ -14,13 +11,10 @@ | |||
#include <functional> | |||
#include <optional> | |||
#include <thread> | |||
#include <assert.h> | |||
#include <experimental/coroutine> | |||
//#include <experimental/generator> | |||
#define LIB_RESUMEF_VERSION 200101 // 2.1.1 | |||
#define LIB_RESUMEF_VERSION 200102 // 2.1.2 | |||
namespace resumef | |||
{ | |||
@@ -49,6 +43,8 @@ namespace resumef | |||
template<class... _Mutexes> | |||
using scoped_lock = std::scoped_lock<_Mutexes...>; | |||
constexpr size_t _Version = LIB_RESUMEF_VERSION; | |||
} | |||
#if RESUMEF_DEBUG_COUNTER | |||
@@ -79,16 +75,6 @@ namespace resumef | |||
} | |||
} | |||
#if defined(RESUMEF_DLL_EXPORT) | |||
# define RF_API __declspec(dllexport) | |||
#elif defined(RESUMEF_DLL_IMPORT) | |||
# define RF_API __declspec(dllimport) | |||
#else | |||
# define RF_API | |||
#endif | |||
#include "exception.inl" | |||
#include "type_traits.inl" | |||
#define co_yield_void co_yield nullptr | |||
#define co_return_void co_return nullptr | |||
#include "macro_def.inl" |
@@ -20,13 +20,13 @@ namespace resumef | |||
intptr_t _counter; | |||
lock_type _lock; | |||
public: | |||
RF_API event_impl(intptr_t initial_counter_); | |||
event_impl(intptr_t initial_counter_); | |||
RF_API void signal(); | |||
RF_API void reset(); | |||
void signal(); | |||
void reset(); | |||
//如果已经触发了awaker,则返回true | |||
RF_API bool wait_(const event_awaker_ptr& awaker); | |||
bool wait_(const event_awaker_ptr& awaker); | |||
template<class callee_t, class dummy_t = std::enable_if<!std::is_same<std::remove_cv_t<callee_t>, event_awaker_ptr>::value>> | |||
decltype(auto) wait(callee_t&& awaker, dummy_t* dummy_ = nullptr) | |||
@@ -54,7 +54,7 @@ namespace resumef | |||
event_impl_ptr _event; | |||
struct wait_all_ctx; | |||
public: | |||
RF_API event_t(intptr_t initial_counter_ = 0); | |||
event_t(intptr_t initial_counter_ = 0); | |||
void signal() const | |||
{ | |||
@@ -67,7 +67,7 @@ namespace resumef | |||
RF_API future_t<bool> | |||
future_t<bool> | |||
wait() const; | |||
template<class _Rep, class _Period> | |||
future_t<bool> | |||
@@ -170,10 +170,10 @@ namespace resumef | |||
RF_API event_t(const event_t&) = default; | |||
RF_API event_t(event_t&&) = default; | |||
RF_API event_t& operator = (const event_t&) = default; | |||
RF_API event_t& operator = (event_t&&) = default; | |||
event_t(const event_t&) = default; | |||
event_t(event_t&&) = default; | |||
event_t& operator = (const event_t&) = default; | |||
event_t& operator = (event_t&&) = default; | |||
private: | |||
template<class _Iter> | |||
@@ -191,23 +191,23 @@ namespace resumef | |||
{ | |||
return wait_until_(clock_type::now() + dt); | |||
} | |||
RF_API future_t<bool> wait_until_(const clock_type::time_point& tp) const; | |||
future_t<bool> wait_until_(const clock_type::time_point& tp) const; | |||
RF_API static future_t<intptr_t> wait_any_(std::vector<event_impl_ptr>&& evts); | |||
static future_t<intptr_t> wait_any_(std::vector<event_impl_ptr>&& evts); | |||
inline static future_t<intptr_t> wait_any_for_(const clock_type::duration& dt, std::vector<event_impl_ptr>&& evts) | |||
{ | |||
return wait_any_until_(clock_type::now() + dt, std::forward<std::vector<event_impl_ptr>>(evts)); | |||
} | |||
RF_API static future_t<intptr_t> wait_any_until_(const clock_type::time_point& tp, std::vector<event_impl_ptr>&& evts); | |||
static future_t<intptr_t> wait_any_until_(const clock_type::time_point& tp, std::vector<event_impl_ptr>&& evts); | |||
RF_API static future_t<bool> wait_all_(std::vector<event_impl_ptr>&& evts); | |||
static future_t<bool> wait_all_(std::vector<event_impl_ptr>&& evts); | |||
inline static future_t<bool> wait_all_for_(const clock_type::duration& dt, std::vector<event_impl_ptr>&& evts) | |||
{ | |||
return wait_all_until_(clock_type::now() + dt, std::forward<std::vector<event_impl_ptr>>(evts)); | |||
} | |||
RF_API static future_t<bool> wait_all_until_(const clock_type::time_point& tp, std::vector<event_impl_ptr>&& evts); | |||
static future_t<bool> wait_all_until_(const clock_type::time_point& tp, std::vector<event_impl_ptr>&& evts); | |||
}; | |||
} |
@@ -0,0 +1,10 @@ | |||
#pragma once | |||
#define co_yield_void co_yield nullptr | |||
#define co_return_void co_return nullptr | |||
#define resumf_guard_lock(lker) (lker).lock(); resumef::scoped_lock<resumef::mutex_t> __resumf_guard##lker##__(std::adopt_lock, (lker)) | |||
#if !defined(_DISABLE_RESUMEF_GO_MACRO) | |||
#define go (*::resumef::this_scheduler()) + | |||
#define GO (*::resumef::this_scheduler()) + [=]()mutable->resumef::future_t<> | |||
#endif |
@@ -20,12 +20,12 @@ namespace resumef | |||
mutex_awaker_ptr _owner; | |||
lock_type _lock; | |||
public: | |||
RF_API mutex_impl(); | |||
mutex_impl(); | |||
//如果已经触发了awaker,则返回true | |||
RF_API bool lock_(const mutex_awaker_ptr& awaker); | |||
RF_API bool try_lock_(const mutex_awaker_ptr& awaker); | |||
RF_API void unlock(); | |||
bool lock_(const mutex_awaker_ptr& awaker); | |||
bool try_lock_(const mutex_awaker_ptr& awaker); | |||
void unlock(); | |||
template<class callee_t, class dummy_t = std::enable_if<!std::is_same<std::remove_cv_t<callee_t>, mutex_awaker_ptr>::value>> | |||
decltype(auto) lock(callee_t&& awaker, dummy_t* dummy_ = nullptr) | |||
@@ -50,7 +50,7 @@ namespace resumef | |||
private: | |||
lock_impl_ptr _locker; | |||
public: | |||
RF_API mutex_t(); | |||
mutex_t(); | |||
void unlock() const | |||
{ | |||
@@ -58,10 +58,8 @@ namespace resumef | |||
} | |||
RF_API future_t<bool> | |||
lock() const; | |||
RF_API bool | |||
try_lock() const; | |||
future_t<bool> lock() const; | |||
bool try_lock() const; | |||
/* | |||
template<class _Rep, class _Period> | |||
@@ -79,22 +77,15 @@ namespace resumef | |||
*/ | |||
RF_API mutex_t(const mutex_t&) = default; | |||
RF_API mutex_t(mutex_t&&) = default; | |||
RF_API mutex_t& operator = (const mutex_t&) = default; | |||
RF_API mutex_t& operator = (mutex_t&&) = default; | |||
mutex_t(const mutex_t&) = default; | |||
mutex_t(mutex_t&&) = default; | |||
mutex_t& operator = (const mutex_t&) = default; | |||
mutex_t& operator = (mutex_t&&) = default; | |||
private: | |||
inline future_t<bool> try_lock_for_(const clock_type::duration& dt) const | |||
{ | |||
return try_lock_until_(clock_type::now() + dt); | |||
} | |||
RF_API future_t<bool> try_lock_until_(const clock_type::time_point& tp) const; | |||
future_t<bool> try_lock_until_(const clock_type::time_point& tp) const; | |||
}; | |||
#if _HAS_CXX17 | |||
#define resumf_guard_lock(lker) (lker).lock(); resumef::scoped_lock<resumef::mutex_t> __resumf_guard##lker##__(std::adopt_lock, (lker)) | |||
#else | |||
#define resumf_guard_lock(lker) (lker).lock(); resumef::scoped_lock<resumef::mutex_t> __resumf_guard##lker##__((lker), std::adopt_lock) | |||
#endif | |||
} |
@@ -1,6 +1,9 @@ | |||
#pragma once | |||
#include "state.h" | |||
#pragma push_macro("new") | |||
#undef new | |||
namespace resumef | |||
{ | |||
struct suspend_on_initial; | |||
@@ -88,3 +91,4 @@ namespace resumef | |||
} | |||
#pragma pop_macro("new") |
@@ -1,7 +1,4 @@ | |||
| |||
#pragma once | |||
#pragma once | |||
#pragma once | |||
namespace resumef | |||
{ |
@@ -11,7 +11,7 @@ namespace resumef | |||
struct task_base_t | |||
{ | |||
task_base_t() = default; | |||
RF_API virtual ~task_base_t(); | |||
virtual ~task_base_t(); | |||
state_base_t* get_state() const | |||
{ |
@@ -30,16 +30,16 @@ namespace resumef | |||
timer_mgr_ptr _timer; | |||
RF_API void new_task(task_base_t* task); | |||
void new_task(task_base_t* task); | |||
//void cancel_all_task_(); | |||
public: | |||
RF_API void run_one_batch(); | |||
RF_API void run_until_notask(); | |||
RF_API void run(); | |||
//RF_API void break_all(); | |||
void run_one_batch(); | |||
void run_until_notask(); | |||
void run(); | |||
//void break_all(); | |||
template<class _Ty, typename = std::enable_if_t<std::is_callable<_Ty>::value || is_future_v<_Ty> || is_generator_v<_Ty> >> | |||
template<class _Ty, typename = std::enable_if_t<std::is_callable_v<_Ty> || is_future_v<_Ty> || is_generator_v<_Ty> >> | |||
inline void operator + (_Ty&& t_) | |||
{ | |||
if constexpr (std::is_callable<_Ty>::value) | |||
@@ -68,9 +68,9 @@ namespace resumef | |||
friend struct task_base; | |||
friend struct local_scheduler; | |||
protected: | |||
RF_API scheduler_t(); | |||
scheduler_t(); | |||
public: | |||
RF_API ~scheduler_t(); | |||
~scheduler_t(); | |||
scheduler_t(scheduler_t&& right_) = delete; | |||
scheduler_t& operator = (scheduler_t&& right_) = delete; | |||
@@ -82,8 +82,8 @@ namespace resumef | |||
struct local_scheduler | |||
{ | |||
RF_API local_scheduler(); | |||
RF_API ~local_scheduler(); | |||
local_scheduler(); | |||
~local_scheduler(); | |||
local_scheduler(local_scheduler&& right_) = delete; | |||
local_scheduler& operator = (local_scheduler&& right_) = delete; | |||
@@ -103,10 +103,5 @@ namespace resumef | |||
} | |||
#endif | |||
#if !defined(_DISABLE_RESUMEF_GO_MACRO) | |||
#define go (*::resumef::this_scheduler()) + | |||
#define GO (*::resumef::this_scheduler()) + [=]()mutable->resumef::future_t<> | |||
#endif | |||
//-------------------------------------------------------------------------------------------------- | |||
} |
@@ -8,7 +8,7 @@ namespace resumef | |||
{ | |||
struct scheduler_t; | |||
RF_API future_t<> sleep_until_(const std::chrono::system_clock::time_point& tp_, scheduler_t& scheduler_); | |||
future_t<> sleep_until_(const std::chrono::system_clock::time_point& tp_, scheduler_t& scheduler_); | |||
inline future_t<> sleep_for_(const std::chrono::system_clock::duration& dt_, scheduler_t& scheduler_) | |||
{ |
@@ -87,8 +87,8 @@ namespace resumef | |||
public: | |||
timer_map_type _runing_timers; | |||
RF_API timer_manager(); | |||
RF_API ~timer_manager(); | |||
timer_manager(); | |||
~timer_manager(); | |||
template<class _Rep, class _Period, class _Cb> | |||
timer_target_ptr add(const std::chrono::duration<_Rep, _Period> & dt_, _Cb && cb_) | |||
@@ -111,14 +111,14 @@ namespace resumef | |||
return{ this, add(tp_, std::forward<_Cb>(cb_)) }; | |||
} | |||
RF_API bool stop(const timer_target_ptr & sptr); | |||
bool stop(const timer_target_ptr & sptr); | |||
inline bool empty() const | |||
{ | |||
return _added_timers.empty() && _runing_timers.empty(); | |||
} | |||
RF_API void clear(); | |||
RF_API void update(); | |||
void clear(); | |||
void update(); | |||
template<class _Cb> | |||
timer_target_ptr add_(const duration_type & dt_, _Cb && cb_) | |||
@@ -131,7 +131,7 @@ namespace resumef | |||
return add_(std::make_shared<timer_target>(tp_, std::forward<_Cb>(cb_))); | |||
} | |||
private: | |||
RF_API timer_target_ptr add_(const timer_target_ptr & sptr); | |||
timer_target_ptr add_(const timer_target_ptr & sptr); | |||
static void call_target_(const timer_target_ptr & sptr, bool canceld); | |||
}; | |||
@@ -17,8 +17,6 @@ namespace std | |||
template<typename _Function> | |||
using is_callable = decltype(_IsCallable(std::declval<_Function>(), 0)); | |||
#if _HAS_CXX17 | |||
template<typename _Function> | |||
_INLINE_VAR constexpr bool is_callable_v = is_callable<_Function>::value; | |||
#endif | |||
constexpr bool is_callable_v = is_callable<_Function>::value; | |||
} |
@@ -1,19 +1,11 @@ | |||
#pragma once | |||
#if RESUMEF_USE_BOOST_ANY | |||
#include <boost/any.hpp> | |||
namespace resumef | |||
{ | |||
using any_t = boost::any; | |||
using boost::any_cast; | |||
} | |||
#else | |||
#include <any> | |||
namespace resumef | |||
{ | |||
using any_t = std::any; | |||
using std::any_cast; | |||
} | |||
#endif | |||
#include "_awaker.h" | |||
#include "promise.h" | |||
@@ -45,12 +37,12 @@ namespace resumef | |||
intptr_t _counter; | |||
lock_type _lock; | |||
public: | |||
RF_API when_impl(intptr_t initial_counter_); | |||
when_impl(intptr_t initial_counter_); | |||
RF_API void signal(); | |||
void signal(); | |||
//如果已经触发了awaker,则返回true | |||
RF_API bool wait_(const when_awaker_ptr & awaker); | |||
bool wait_(const when_awaker_ptr & awaker); | |||
template<class callee_t, class dummy_t = std::enable_if<!std::is_same<std::remove_cv_t<callee_t>, when_awaker_ptr>::value>> | |||
auto wait(callee_t && awaker, dummy_t * dummy_ = nullptr) |
@@ -213,6 +213,7 @@ | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="..\librf\librf.h" /> | |||
<ClInclude Include="..\librf\librf_macro.h" /> | |||
<ClInclude Include="..\librf\src\asio_task.h" /> | |||
<ClInclude Include="..\librf\src\awaitable.h" /> | |||
<ClInclude Include="..\librf\src\channel.h" /> | |||
@@ -238,6 +239,7 @@ | |||
<None Include="..\librf\src\asio_task_1.10.0.inl" /> | |||
<None Include="..\librf\src\asio_task_1.12.0.inl" /> | |||
<None Include="..\librf\src\exception.inl" /> | |||
<None Include="..\librf\src\macro_def.inl" /> | |||
<None Include="..\librf\src\promise.inl" /> | |||
<None Include="..\librf\src\state.inl" /> | |||
<None Include="..\librf\src\type_traits.inl" /> |
@@ -177,6 +177,9 @@ | |||
<ClInclude Include="..\librf\src\generator.h"> | |||
<Filter>librf\src</Filter> | |||
</ClInclude> | |||
<ClInclude Include="..\librf\librf_macro.h"> | |||
<Filter>librf</Filter> | |||
</ClInclude> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<None Include="..\librf\src\asio_task_1.12.0.inl"> | |||
@@ -198,5 +201,8 @@ | |||
<Filter>librf\src</Filter> | |||
</None> | |||
<None Include="..\README.md" /> | |||
<None Include="..\librf\src\macro_def.inl"> | |||
<Filter>librf\src</Filter> | |||
</None> | |||
</ItemGroup> | |||
</Project> |