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

@@ -3,3 +3,5 @@
################################################################################

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

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

@@ -34,7 +34,7 @@ namespace resumef
inline void operator + (_Ty && t_)
{
typedef typename std::conditional<
decltype(std::_IsCallable(t_, 0))::value,
std::is_callable_v<_Ty>,
ctx_task_t<_Ty>,
task_t<_Ty> >::type task_type;
return new_task(new task_type(std::forward<_Ty>(t_)));

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

@@ -13,5 +13,11 @@ namespace std
{
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

@@ -46,9 +46,9 @@ namespace resumef
template<class _Ty>
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<>
struct remove_future<void>
@@ -162,22 +162,11 @@ namespace resumef
inline future_vt operator ()() const
{
co_await _f;
_val.get() = ignore_type(); //让外面感知到optional已经赋值了
_val.get() = std::ignore; //让外面感知到optional已经赋值了
_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>
inline void when_one__(scheduler & s, const detail::when_impl_ptr & e, _Tup & t)
{
@@ -262,16 +251,16 @@ namespace resumef
return when_all(*this_scheduler(), std::forward<_Fty>(f)...);
}
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>;
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>())>
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);
}
@@ -295,16 +284,16 @@ namespace resumef
return when_any(*this_scheduler(), std::forward<_Fty>(f)...);
}
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>;
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>())>
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);
}

+ 5
- 1
vs_proj/librf.vcxproj View File

@@ -91,6 +91,7 @@
<AdditionalIncludeDirectories>..\librf;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/await /std:c++latest </AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -104,8 +105,10 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;RESUMEF_DEBUG_COUNTER=0;RESUMEF_ENABLE_MULT_SCHEDULER=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\librf;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/await /std:c++latest </AdditionalOptions>
<AdditionalOptions>/await</AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpplatest</LanguageStandard>
<MinimalRebuild />
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -123,6 +126,7 @@
<AdditionalIncludeDirectories>..\librf;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/await /std:c++latest </AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

Loading…
Cancel
Save