Bladeren bron

恢复新版本下的mutex功能,并完成相关范例

tags/v2.9.7
tearshark 4 jaren geleden
bovenliggende
commit
39356713cc
6 gewijzigde bestanden met toevoegingen van 21 en 26 verwijderingen
  1. 2
    2
      benchmark/benchmark_async_mem.cpp
  2. 4
    2
      librf/src/mutex.cpp
  3. 8
    1
      librf/src/state.h
  4. 1
    1
      librf/src/when.h
  5. 3
    2
      vs_proj/librf.cpp
  6. 3
    18
      vs_proj/librf.vcxproj

+ 2
- 2
benchmark/benchmark_async_mem.cpp Bestand weergeven

using namespace std::chrono; using namespace std::chrono;
resumef::state_t<void> st; resumef::state_t<void> st;
std::cout << sizeof(st) << " " << sizeof(resumef::promise_vt) << std::endl;
std::cout << sizeof(st) << " " << sizeof(resumef::promise_t<>) << std::endl;
for (size_t i = 0; i < N; ++i) for (size_t i = 0; i < N; ++i)
{ {
globalValue += i * k; globalValue += i * k;
co_yield k; co_yield k;
} }
return 0;
co_return 0;
}; };
} }

+ 4
- 2
librf/src/mutex.cpp Bestand weergeven

#include "mutex.h" #include "mutex.h"
#include <assert.h> #include <assert.h>
#include "scheduler.h" #include "scheduler.h"
#include "awaitable.h"
#include "state.inl"
namespace resumef namespace resumef
{ {
future_t<bool> mutex_t::lock() const future_t<bool> mutex_t::lock() const
{ {
promise_t<bool> awaitable;
awaitable_t<bool> awaitable;
auto awaker = std::make_shared<detail::mutex_awaker>( auto awaker = std::make_shared<detail::mutex_awaker>(
[st = awaitable._state](detail::mutex_impl * e) -> bool [st = awaitable._state](detail::mutex_impl * e) -> bool
future_t<bool> mutex_t::try_lock_until_(const clock_type::time_point & tp) const future_t<bool> mutex_t::try_lock_until_(const clock_type::time_point & tp) const
{ {
promise_t<bool> awaitable;
awaitable_t<bool> awaitable;
auto awaker = std::make_shared<detail::mutex_awaker>( auto awaker = std::make_shared<detail::mutex_awaker>(
[st = awaitable._state](detail::mutex_impl * e) -> bool [st = awaitable._state](detail::mutex_impl * e) -> bool

+ 8
- 1
librf/src/state.h Bestand weergeven

#endif #endif
bool _is_awaitor; bool _is_awaitor;
public: public:
state_future_t()
{
#if RESUMEF_DEBUG_COUNTER
_id = ++g_resumef_state_id;
#endif
_is_awaitor = false;
}
state_future_t(bool awaitor) state_future_t(bool awaitor)
{ {
#if RESUMEF_DEBUG_COUNTER #if RESUMEF_DEBUG_COUNTER
void set_exception(std::exception_ptr e); void set_exception(std::exception_ptr e);
template<class _Exp> template<class _Exp>
void throw_exception(_Exp e) const
void throw_exception(_Exp e)
{ {
set_exception(std::make_exception_ptr(std::move(e))); set_exception(std::make_exception_ptr(std::move(e)));
} }

+ 1
- 1
librf/src/when.h Bestand weergeven

template<class _Tup, class... _Fty> template<class _Tup, class... _Fty>
future_t<_Tup> when_all_count(size_t count, const std::shared_ptr<_Tup> & vals, scheduler_t & s, _Fty&&... f) future_t<_Tup> when_all_count(size_t count, const std::shared_ptr<_Tup> & vals, scheduler_t & s, _Fty&&... f)
{ {
promise_t<_Tup> awaitable;
awaitable_t<_Tup> awaitable;
when_impl_ptr _event = std::make_shared<when_impl>(count); when_impl_ptr _event = std::make_shared<when_impl>(count);
auto awaker = std::make_shared<when_awaker>( auto awaker = std::make_shared<when_awaker>(

+ 3
- 2
vs_proj/librf.cpp Bestand weergeven

//resumable_main_exception(); //resumable_main_exception();
//resumable_main_dynamic_go(); //resumable_main_dynamic_go();
//resumable_main_multi_thread(); //resumable_main_multi_thread();
resumable_main_timer();
//resumable_main_timer();
//resumable_main_benchmark_mem();
resumable_main_mutex();
/* /*
resumable_main_benchmark_mem(); resumable_main_benchmark_mem();
resumable_main_when_all(); resumable_main_when_all();
resumable_main_sleep(); resumable_main_sleep();
resumable_main_mutex();
resumable_main_event(); resumable_main_event();
resumable_main_event_timeout(); resumable_main_event_timeout();
resumable_main_channel(); resumable_main_channel();

+ 3
- 18
vs_proj/librf.vcxproj Bestand weergeven

<ItemGroup> <ItemGroup>
<ClCompile Include="..\benchmark\benchmark_asio_echo.cpp"> <ClCompile Include="..\benchmark\benchmark_asio_echo.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\benchmark\benchmark_async_mem.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\benchmark\benchmark_async_mem.cpp" />
<ClCompile Include="..\benchmark\benchmark_channel_passing_next.cpp"> <ClCompile Include="..\benchmark\benchmark_channel_passing_next.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\librf\src\mutex.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\librf\src\mutex.cpp" />
<ClCompile Include="..\librf\src\rf_task.cpp" /> <ClCompile Include="..\librf\src\rf_task.cpp" />
<ClCompile Include="..\librf\src\scheduler.cpp" /> <ClCompile Include="..\librf\src\scheduler.cpp" />
<ClCompile Include="..\librf\src\sleep.cpp" /> <ClCompile Include="..\librf\src\sleep.cpp" />
<ClCompile Include="..\tutorial\test_async_exception.cpp" /> <ClCompile Include="..\tutorial\test_async_exception.cpp" />
<ClCompile Include="..\tutorial\test_async_modern_cb.cpp" /> <ClCompile Include="..\tutorial\test_async_modern_cb.cpp" />
<ClCompile Include="..\tutorial\test_async_multi_thread.cpp" /> <ClCompile Include="..\tutorial\test_async_multi_thread.cpp" />
<ClCompile Include="..\tutorial\test_async_mutex.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\tutorial\test_async_mutex.cpp" />
<ClCompile Include="..\tutorial\test_async_resumable.cpp" /> <ClCompile Include="..\tutorial\test_async_resumable.cpp" />
<ClCompile Include="..\tutorial\test_async_routine.cpp" /> <ClCompile Include="..\tutorial\test_async_routine.cpp" />
<ClCompile Include="..\tutorial\test_async_sleep.cpp"> <ClCompile Include="..\tutorial\test_async_sleep.cpp">

Laden…
Annuleren
Opslaan