Browse Source

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

tags/v2.9.7
tearshark 4 years ago
parent
commit
39356713cc
6 changed files with 21 additions and 26 deletions
  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 View File

@@ -16,7 +16,7 @@ void resumable_main_benchmark_mem()
using namespace std::chrono;
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)
{
@@ -27,7 +27,7 @@ void resumable_main_benchmark_mem()
globalValue += i * k;
co_yield k;
}
return 0;
co_return 0;
};
}

+ 4
- 2
librf/src/mutex.cpp View File

@@ -1,6 +1,8 @@
#include "mutex.h"
#include <assert.h>
#include "scheduler.h"
#include "awaitable.h"
#include "state.inl"
namespace resumef
{
@@ -80,7 +82,7 @@ namespace resumef
future_t<bool> mutex_t::lock() const
{
promise_t<bool> awaitable;
awaitable_t<bool> awaitable;
auto awaker = std::make_shared<detail::mutex_awaker>(
[st = awaitable._state](detail::mutex_impl * e) -> bool
@@ -105,7 +107,7 @@ namespace resumef
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>(
[st = awaitable._state](detail::mutex_impl * e) -> bool

+ 8
- 1
librf/src/state.h View File

@@ -59,6 +59,13 @@ namespace resumef
#endif
bool _is_awaitor;
public:
state_future_t()
{
#if RESUMEF_DEBUG_COUNTER
_id = ++g_resumef_state_id;
#endif
_is_awaitor = false;
}
state_future_t(bool awaitor)
{
#if RESUMEF_DEBUG_COUNTER
@@ -83,7 +90,7 @@ namespace resumef
void set_exception(std::exception_ptr e);
template<class _Exp>
void throw_exception(_Exp e) const
void throw_exception(_Exp e)
{
set_exception(std::make_exception_ptr(std::move(e)));
}

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

@@ -171,7 +171,7 @@ namespace resumef
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)
{
promise_t<_Tup> awaitable;
awaitable_t<_Tup> awaitable;
when_impl_ptr _event = std::make_shared<when_impl>(count);
auto awaker = std::make_shared<when_awaker>(

+ 3
- 2
vs_proj/librf.cpp View File

@@ -40,7 +40,9 @@ int main(int argc, const char* argv[])
//resumable_main_exception();
//resumable_main_dynamic_go();
//resumable_main_multi_thread();
resumable_main_timer();
//resumable_main_timer();
//resumable_main_benchmark_mem();
resumable_main_mutex();
/*
resumable_main_benchmark_mem();
@@ -51,7 +53,6 @@ int main(int argc, const char* argv[])
resumable_main_when_all();
resumable_main_sleep();
resumable_main_mutex();
resumable_main_event();
resumable_main_event_timeout();
resumable_main_channel();

+ 3
- 18
vs_proj/librf.vcxproj View File

@@ -182,16 +182,11 @@
<ItemGroup>
<ClCompile Include="..\benchmark\benchmark_asio_echo.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="..\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)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\benchmark\benchmark_async_mem.cpp" />
<ClCompile Include="..\benchmark\benchmark_channel_passing_next.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
@@ -204,12 +199,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</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\scheduler.cpp" />
<ClCompile Include="..\librf\src\sleep.cpp" />
@@ -250,12 +240,7 @@
<ClCompile Include="..\tutorial\test_async_exception.cpp" />
<ClCompile Include="..\tutorial\test_async_modern_cb.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_routine.cpp" />
<ClCompile Include="..\tutorial\test_async_sleep.cpp">

Loading…
Cancel
Save