Browse Source

整理代码

tags/v2.9.7
tearshark 6 years ago
parent
commit
a4061d38d0
5 changed files with 26 additions and 25 deletions
  1. 2
    0
      .gitignore
  2. 1
    1
      librf/src/scheduler.h
  3. 6
    0
      librf/src/utils.h
  4. 12
    23
      librf/src/when.h
  5. 5
    1
      vs_proj/librf.vcxproj

+ 2
- 0
.gitignore View File

################################################################################ ################################################################################


/vs_proj/x64 /vs_proj/x64
/vs_proj/.vs
/vs_proj/librf.vcxproj.user

+ 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<
decltype(std::_IsCallable(t_, 0))::value,
std::is_callable_v<_Ty>,
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_)));

+ 6
- 0
librf/src/utils.h View File

{ {
return false_type(); return false_type();
} }
template<typename _Function>
using is_callable = decltype(_IsCallable(std::declval<_Function>(), 0));
template<typename _Function>
_INLINE_VAR constexpr bool is_callable_v = is_callable<_Function>::value;
} }

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

template<class _Ty> template<class _Ty>
struct remove_future struct remove_future
{ {
using type = _Ty;
using value_type = _Ty;
using optional_type = std::optional<_Ty>;
using type = std::remove_reference_t<_Ty>;
using value_type = type;
using optional_type = std::optional<type>;
}; };
template<> template<>
struct remove_future<void> struct remove_future<void>
inline future_vt operator ()() const inline future_vt operator ()() const
{ {
co_await _f; co_await _f;
_val.get() = ignore_type(); //让外面感知到optional已经赋值了
_val.get() = std::ignore; //让外面感知到optional已经赋值了
_e->signal(); _e->signal();
} }
}; };
template<class... _Ty>
size_t sizeof_tuple(const std::tuple<_Ty...> & val)
{
return sizeof...(_Ty);
}
template<class _Cont>
size_t sizeof_tuple(const _Cont & val)
{
return val.typename size();
}
template<class _Tup, size_t _N> template<class _Tup, size_t _N>
inline void when_one__(scheduler & s, const detail::when_impl_ptr & e, _Tup & t) inline void when_one__(scheduler & s, const detail::when_impl_ptr & e, _Tup & t)
{ {
return when_all(*this_scheduler(), std::forward<_Fty>(f)...); return when_all(*this_scheduler(), std::forward<_Fty>(f)...);
} }
template<class _Iter, typename _Fty = decltype(*std::declval<_Iter>())> template<class _Iter, typename _Fty = decltype(*std::declval<_Iter>())>
auto when_all(scheduler & s, _Iter begin, _Iter end) -> future_t<std::vector<detail::remove_future_vt<decltype(*std::declval<_Iter>())> > >
auto when_all(scheduler & s, _Iter begin, _Iter end) -> future_t<std::vector<detail::remove_future_vt<_Fty> > >
{ {
using value_type = detail::remove_future_vt<decltype(*std::declval<_Iter>())>;
using value_type = detail::remove_future_vt<_Fty>;
using vector_type = std::vector<value_type>; using vector_type = std::vector<value_type>;
auto vals = std::make_shared<vector_type>(std::distance(begin, end)); auto vals = std::make_shared<vector_type>(std::distance(begin, end));
return detail::when_range(std::distance(begin, end), vals, s, begin, end);
return detail::when_range(vals->size(), vals, s, begin, end);
} }
template<class _Iter, typename _Fty = decltype(*std::declval<_Iter>())> template<class _Iter, typename _Fty = decltype(*std::declval<_Iter>())>
auto when_all(_Iter begin, _Iter end) -> future_t<std::vector<detail::remove_future_vt<decltype(*std::declval<_Iter>())> > >
auto when_all(_Iter begin, _Iter end) -> future_t<std::vector<detail::remove_future_vt<_Fty> > >
{ {
return when_all(*this_scheduler(), begin, end); return when_all(*this_scheduler(), begin, end);
} }
return when_any(*this_scheduler(), std::forward<_Fty>(f)...); return when_any(*this_scheduler(), std::forward<_Fty>(f)...);
} }
template<class _Iter, typename _Fty = decltype(*std::declval<_Iter>())> template<class _Iter, typename _Fty = decltype(*std::declval<_Iter>())>
auto when_any(scheduler & s, _Iter begin, _Iter end) -> future_t<std::vector<detail::remove_future_ot<decltype(*std::declval<_Iter>())> > >
auto when_any(scheduler & s, _Iter begin, _Iter end) -> future_t<std::vector<detail::remove_future_ot<_Fty> > >
{ {
using value_type = detail::remove_future_ot<decltype(*std::declval<_Iter>())>;
using value_type = detail::remove_future_ot<_Fty>;
using vector_type = std::vector<value_type>; using vector_type = std::vector<value_type>;
auto vals = std::make_shared<vector_type>(std::distance(begin, end)); auto vals = std::make_shared<vector_type>(std::distance(begin, end));
return detail::when_range(std::distance(begin, end) ? 1 : 0, vals, s, begin, end);
return detail::when_range(vals->size() ? 1 : 0, vals, s, begin, end);
} }
template<class _Iter, typename _Fty = decltype(*std::declval<_Iter>())> template<class _Iter, typename _Fty = decltype(*std::declval<_Iter>())>
auto when_any(_Iter begin, _Iter end) -> future_t<std::vector<detail::remove_future_ot<decltype(*std::declval<_Iter>())> > >
auto when_any(_Iter begin, _Iter end) -> future_t<std::vector<detail::remove_future_ot<_Fty> > >
{ {
return when_any(*this_scheduler(), begin, end); return when_any(*this_scheduler(), begin, end);
} }

+ 5
- 1
vs_proj/librf.vcxproj View File

<AdditionalIncludeDirectories>..\librf;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\librf;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/await /std:c++latest </AdditionalOptions> <AdditionalOptions>/await /std:c++latest </AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;RESUMEF_DEBUG_COUNTER=0;RESUMEF_ENABLE_MULT_SCHEDULER=0;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_CONSOLE;RESUMEF_DEBUG_COUNTER=0;RESUMEF_ENABLE_MULT_SCHEDULER=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\librf;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\librf;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/await /std:c++latest </AdditionalOptions>
<AdditionalOptions>/await</AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpplatest</LanguageStandard>
<MinimalRebuild />
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<AdditionalIncludeDirectories>..\librf;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\librf;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/await /std:c++latest </AdditionalOptions> <AdditionalOptions>/await /std:c++latest </AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>

Loading…
Cancel
Save