Browse Source

将宏定义集中存放,以便于将来更好的支持module

tags/v2.9.7
tearshark 4 years ago
parent
commit
b6a8d6bb1a

+ 1
- 0
librf/librf_macro.h View File

#include "src/macro_def.inl"

+ 1
- 6
librf/src/asio_task_1.10.0.inl View File

private: private:
Allocator allocator_; 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 { namespace detail {



+ 0
- 5
librf/src/asio_task_1.12.0.inl View File

{ {
ASIO_CONSTEXPR rf_task_t() {} ASIO_CONSTEXPR rf_task_t() {}
}; };

#if defined(ASIO_HAS_CONSTEXPR) || defined(GENERATING_DOCUMENTATION)
constexpr rf_task_t<> rf_task; constexpr rf_task_t<> rf_task;
#elif defined(ASIO_MSVC)
__declspec(selectany) rf_task_t<> rf_task;
#endif


namespace librf { namespace librf {



+ 4
- 18
librf/src/def.h View File

#pragma once #pragma once
#define RESUMEF_LIB_INCLUDE 1
//#include <yvals.h>
#include <atomic> #include <atomic>
#include <chrono> #include <chrono>
#include <vector> #include <vector>
#include <functional> #include <functional>
#include <optional> #include <optional>
#include <thread> #include <thread>
#include <assert.h> #include <assert.h>
#include <experimental/coroutine> #include <experimental/coroutine>
//#include <experimental/generator>
#define LIB_RESUMEF_VERSION 200101 // 2.1.1
#define LIB_RESUMEF_VERSION 200102 // 2.1.2
namespace resumef namespace resumef
{ {
template<class... _Mutexes> template<class... _Mutexes>
using scoped_lock = std::scoped_lock<_Mutexes...>; using scoped_lock = std::scoped_lock<_Mutexes...>;
constexpr size_t _Version = LIB_RESUMEF_VERSION;
} }
#if RESUMEF_DEBUG_COUNTER #if RESUMEF_DEBUG_COUNTER
} }
} }
#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 "exception.inl"
#include "type_traits.inl" #include "type_traits.inl"
#define co_yield_void co_yield nullptr
#define co_return_void co_return nullptr
#include "macro_def.inl"

+ 15
- 15
librf/src/event.h View File

intptr_t _counter; intptr_t _counter;
lock_type _lock; lock_type _lock;
public: 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 //如果已经触发了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>> 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) decltype(auto) wait(callee_t&& awaker, dummy_t* dummy_ = nullptr)
event_impl_ptr _event; event_impl_ptr _event;
struct wait_all_ctx; struct wait_all_ctx;
public: public:
RF_API event_t(intptr_t initial_counter_ = 0);
event_t(intptr_t initial_counter_ = 0);
void signal() const void signal() const
{ {
RF_API future_t<bool>
future_t<bool>
wait() const; wait() const;
template<class _Rep, class _Period> template<class _Rep, class _Period>
future_t<bool> future_t<bool>
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: private:
template<class _Iter> template<class _Iter>
{ {
return wait_until_(clock_type::now() + dt); 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) 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)); 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) 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)); 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);
}; };
} }

+ 10
- 0
librf/src/macro_def.inl View File

#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

+ 12
- 21
librf/src/mutex.h View File

mutex_awaker_ptr _owner; mutex_awaker_ptr _owner;
lock_type _lock; lock_type _lock;
public: public:
RF_API mutex_impl();
mutex_impl();
//如果已经触发了awaker,则返回true //如果已经触发了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>> 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) decltype(auto) lock(callee_t&& awaker, dummy_t* dummy_ = nullptr)
private: private:
lock_impl_ptr _locker; lock_impl_ptr _locker;
public: public:
RF_API mutex_t();
mutex_t();
void unlock() const void unlock() const
{ {
} }
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> template<class _Rep, class _Period>
*/ */
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: private:
inline future_t<bool> try_lock_for_(const clock_type::duration& dt) const inline future_t<bool> try_lock_for_(const clock_type::duration& dt) const
{ {
return try_lock_until_(clock_type::now() + dt); 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
} }

+ 4
- 0
librf/src/promise.h View File

#pragma once #pragma once
#include "state.h" #include "state.h"


#pragma push_macro("new")
#undef new

namespace resumef namespace resumef
{ {
struct suspend_on_initial; struct suspend_on_initial;


} }


#pragma pop_macro("new")

+ 1
- 4
librf/src/promise.inl View File


#pragma once

#pragma once
#pragma once


namespace resumef namespace resumef
{ {

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

struct task_base_t struct task_base_t
{ {
task_base_t() = default; task_base_t() = default;
RF_API virtual ~task_base_t();
virtual ~task_base_t();
state_base_t* get_state() const state_base_t* get_state() const
{ {

+ 10
- 15
librf/src/scheduler.h View File

timer_mgr_ptr _timer; timer_mgr_ptr _timer;
RF_API void new_task(task_base_t* task);
void new_task(task_base_t* task);
//void cancel_all_task_(); //void cancel_all_task_();
public: 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_) inline void operator + (_Ty&& t_)
{ {
if constexpr (std::is_callable<_Ty>::value) if constexpr (std::is_callable<_Ty>::value)
friend struct task_base; friend struct task_base;
friend struct local_scheduler; friend struct local_scheduler;
protected: protected:
RF_API scheduler_t();
scheduler_t();
public: public:
RF_API ~scheduler_t();
~scheduler_t();
scheduler_t(scheduler_t&& right_) = delete; scheduler_t(scheduler_t&& right_) = delete;
scheduler_t& operator = (scheduler_t&& right_) = delete; scheduler_t& operator = (scheduler_t&& right_) = delete;
struct local_scheduler struct local_scheduler
{ {
RF_API local_scheduler();
RF_API ~local_scheduler();
local_scheduler();
~local_scheduler();
local_scheduler(local_scheduler&& right_) = delete; local_scheduler(local_scheduler&& right_) = delete;
local_scheduler& operator = (local_scheduler&& right_) = delete; local_scheduler& operator = (local_scheduler&& right_) = delete;
} }
#endif #endif
#if !defined(_DISABLE_RESUMEF_GO_MACRO)
#define go (*::resumef::this_scheduler()) +
#define GO (*::resumef::this_scheduler()) + [=]()mutable->resumef::future_t<>
#endif
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
} }

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

{ {
struct scheduler_t; 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_) inline future_t<> sleep_for_(const std::chrono::system_clock::duration& dt_, scheduler_t& scheduler_)
{ {

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

public: public:
timer_map_type _runing_timers; timer_map_type _runing_timers;
RF_API timer_manager();
RF_API ~timer_manager();
timer_manager();
~timer_manager();
template<class _Rep, class _Period, class _Cb> template<class _Rep, class _Period, class _Cb>
timer_target_ptr add(const std::chrono::duration<_Rep, _Period> & dt_, _Cb && cb_) timer_target_ptr add(const std::chrono::duration<_Rep, _Period> & dt_, _Cb && cb_)
return{ this, add(tp_, std::forward<_Cb>(cb_)) }; 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 inline bool empty() const
{ {
return _added_timers.empty() && _runing_timers.empty(); return _added_timers.empty() && _runing_timers.empty();
} }
RF_API void clear();
RF_API void update();
void clear();
void update();
template<class _Cb> template<class _Cb>
timer_target_ptr add_(const duration_type & dt_, _Cb && cb_) timer_target_ptr add_(const duration_type & dt_, _Cb && cb_)
return add_(std::make_shared<timer_target>(tp_, std::forward<_Cb>(cb_))); return add_(std::make_shared<timer_target>(tp_, std::forward<_Cb>(cb_)));
} }
private: 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); static void call_target_(const timer_target_ptr & sptr, bool canceld);
}; };

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

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;
#endif
constexpr bool is_callable_v = is_callable<_Function>::value;
} }

+ 4
- 12
librf/src/when.h View File

#pragma once #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> #include <any>
namespace resumef namespace resumef
{ {
using any_t = std::any; using any_t = std::any;
using std::any_cast; using std::any_cast;
} }
#endif
#include "_awaker.h" #include "_awaker.h"
#include "promise.h" #include "promise.h"
intptr_t _counter; intptr_t _counter;
lock_type _lock; lock_type _lock;
public: public:
RF_API when_impl(intptr_t initial_counter_);
when_impl(intptr_t initial_counter_);
RF_API void signal();
void signal();
//如果已经触发了awaker,则返回true //如果已经触发了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>> 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) auto wait(callee_t && awaker, dummy_t * dummy_ = nullptr)

+ 2
- 0
vs_proj/librf.vcxproj View File

</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\librf\librf.h" /> <ClInclude Include="..\librf\librf.h" />
<ClInclude Include="..\librf\librf_macro.h" />
<ClInclude Include="..\librf\src\asio_task.h" /> <ClInclude Include="..\librf\src\asio_task.h" />
<ClInclude Include="..\librf\src\awaitable.h" /> <ClInclude Include="..\librf\src\awaitable.h" />
<ClInclude Include="..\librf\src\channel.h" /> <ClInclude Include="..\librf\src\channel.h" />
<None Include="..\librf\src\asio_task_1.10.0.inl" /> <None Include="..\librf\src\asio_task_1.10.0.inl" />
<None Include="..\librf\src\asio_task_1.12.0.inl" /> <None Include="..\librf\src\asio_task_1.12.0.inl" />
<None Include="..\librf\src\exception.inl" /> <None Include="..\librf\src\exception.inl" />
<None Include="..\librf\src\macro_def.inl" />
<None Include="..\librf\src\promise.inl" /> <None Include="..\librf\src\promise.inl" />
<None Include="..\librf\src\state.inl" /> <None Include="..\librf\src\state.inl" />
<None Include="..\librf\src\type_traits.inl" /> <None Include="..\librf\src\type_traits.inl" />

+ 6
- 0
vs_proj/librf.vcxproj.filters View File

<ClInclude Include="..\librf\src\generator.h"> <ClInclude Include="..\librf\src\generator.h">
<Filter>librf\src</Filter> <Filter>librf\src</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\librf\librf_macro.h">
<Filter>librf</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\librf\src\asio_task_1.12.0.inl"> <None Include="..\librf\src\asio_task_1.12.0.inl">
<Filter>librf\src</Filter> <Filter>librf\src</Filter>
</None> </None>
<None Include="..\README.md" /> <None Include="..\README.md" />
<None Include="..\librf\src\macro_def.inl">
<Filter>librf\src</Filter>
</None>
</ItemGroup> </ItemGroup>
</Project> </Project>

Loading…
Cancel
Save