Browse Source

兼容gcc 10

tags/2.9.10
tearshark 4 years ago
parent
commit
7300bdd140

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

@@ -1,6 +1,6 @@
#pragma once
#define LIB_RESUMEF_VERSION 20907 // 2.9.7
#define LIB_RESUMEF_VERSION 20908 // 2.9.8
namespace resumef
{

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

@@ -150,7 +150,7 @@ namespace resumef
//msvc认为是constexpr表达式(不写还给警告),然而,clang不这么认为。
//放弃constexpr,反正合格的编译器都会优化掉这个if判断的。
if
#ifdef _MSC_VER
#if defined(_MSC_VER) && !defined(__clang__) && !defined(__GNUC__)
constexpr
#endif
(_offset_of(state_future_t, _is_future) - _offset_of(state_future_t, _has_value) == 1)

+ 14
- 0
librf/src/unix/gcc_builtin.h View File

@@ -0,0 +1,14 @@
#pragma once

#if 0

extern "C" void __builtin_coro_resume(void* addr);
extern "C" void __builtin_coro_destroy(void* addr);
extern "C" bool __builtin_coro_done(void* addr);
extern "C" void* __builtin_coro_promise(void* addr, const long unsigned int alignment, bool from_promise);
#pragma intrinsic(__builtin_coro_resume)
#pragma intrinsic(__builtin_coro_destroy)
#pragma intrinsic(__builtin_coro_done)
#pragma intrinsic(__builtin_coro_promise)

#endif

+ 11
- 6
tutorial/test_async_memory_layout.cpp View File

@@ -7,6 +7,8 @@

using namespace resumef;

#ifndef __GNUC__ //GCC: 没有提供__builtin_coro_frame这样的内置函数

template<class _Ctype>
static void callback_get_long(int64_t a, int64_t b, _Ctype&& cb)
{
@@ -51,7 +53,7 @@ future_t<int64_t> resumeable_get_long(int64_t x, int64_t y)
using promise_type = typename future_type::promise_type;
using state_type = typename future_type::state_type;

void* frame_ptr = __builtin_coro_frame();
void* frame_ptr = _coro_frame_ptr();
auto handler = coroutine_handle<promise_type>::from_address(frame_ptr);
promise_type* promise = &handler.promise();
state_type* state = handler.promise().get_state();
@@ -59,10 +61,10 @@ future_t<int64_t> resumeable_get_long(int64_t x, int64_t y)
std::cout << " future size=" << sizeof(future_type) << " / " << _Align_size<future_type>() << std::endl;
std::cout << " promise size=" << sizeof(promise_type) << " / " << _Align_size<promise_type>() << std::endl;
std::cout << " state size=" << sizeof(state_type) << " / "<< _Align_size<state_type>() << std::endl;
std::cout << " frame size=" << __builtin_coro_size() << ", alloc size=" << state->get_alloc_size() << std::endl;
std::cout << " frame size=" << _coro_frame_size() << ", alloc size=" << state->get_alloc_size() << std::endl;

std::cout << " frame ptr=" << frame_ptr << "," << (void*)&frame_ptr << std::endl;
std::cout << " frame end=" << (void*)((char*)(frame_ptr)+__builtin_coro_size()) << std::endl;
std::cout << " frame end=" << (void*)((char*)(frame_ptr)+_coro_frame_size()) << std::endl;
std::cout << " promise ptr=" << promise << "," << (void*)&promise << std::endl;
std::cout << " handle ptr=" << handler.address() << "," << (void*)&handler << std::endl;
std::cout << " state ptr=" << state << "," << (void*)&state << std::endl;
@@ -90,7 +92,7 @@ future_t<> resumable_get_long_2(int64_t a, int64_t b, int64_t c)
using promise_type = typename future_type::promise_type;
using state_type = typename future_type::state_type;

void* frame_ptr = __builtin_coro_frame();
void* frame_ptr = _coro_frame_ptr();
auto handler = coroutine_handle<promise_type>::from_address(frame_ptr);
promise_type * promise = &handler.promise();
state_type * state = handler.promise().get_state();
@@ -98,10 +100,10 @@ future_t<> resumable_get_long_2(int64_t a, int64_t b, int64_t c)
std::cout << " future size=" << sizeof(future_type) << " / " << _Align_size<future_type>() << std::endl;
std::cout << " promise size=" << sizeof(promise_type) << " / " << _Align_size<promise_type>() << std::endl;
std::cout << " state size=" << sizeof(state_type) << " / "<< _Align_size<state_type>() << std::endl;
std::cout << " frame size=" << __builtin_coro_size() << ", alloc size=" << state->get_alloc_size() << std::endl;
std::cout << " frame size=" << _coro_frame_size() << ", alloc size=" << state->get_alloc_size() << std::endl;

std::cout << " frame ptr=" << frame_ptr << ","<< (void*)&frame_ptr << std::endl;
std::cout << " frame end=" << (void *)((char*)(frame_ptr) + __builtin_coro_size()) << std::endl;
std::cout << " frame end=" << (void *)((char*)(frame_ptr) + _coro_frame_size()) << std::endl;
std::cout << " promise ptr=" << promise << "," << (void *)&promise << std::endl;
std::cout << " handle ptr=" << handler.address() << "," << (void*)&handler << std::endl;
std::cout << " state ptr=" << state << "," << (void*)&state << std::endl;
@@ -125,12 +127,15 @@ future_t<> resumable_get_long_2(int64_t a, int64_t b, int64_t c)

std::cout << __FUNCTION__ << " - end" << std::endl;
}
#endif //#ifndef __GNUC__

void resumable_main_layout()
{
std::cout << std::endl << __FUNCTION__ << " - begin" << std::endl;

#ifndef __GNUC__ //GCC: 没有提供__builtin_coro_frame这样的内置函数
go resumable_get_long_2(1, 2, 5);
#endif //#ifndef __GNUC__
resumef::this_scheduler()->run_until_notask();

std::cout << __FUNCTION__ << " - end" << std::endl;

+ 8
- 4
tutorial/test_async_routine.cpp View File

@@ -8,6 +8,7 @@
using namespace resumef;
#ifndef __GNUC__ //GCC: 没有提供__builtin_coro_frame这样的内置函数
future_t<> test_routine_use_timer()
{
using namespace std::chrono;
@@ -16,7 +17,7 @@ future_t<> test_routine_use_timer()
{
co_await resumef::sleep_for(100ms);
std::cout << "timer after 100ms" << std::endl;
std::cout << "1:frame=" << __builtin_coro_frame() << std::endl;
std::cout << "1:frame=" << _coro_frame_ptr() << std::endl;
}
}
@@ -25,16 +26,19 @@ future_t<> test_routine_use_timer_2()
std::cout << "test_routine_use_timer_2" << std::endl;
co_await test_routine_use_timer();
std::cout << "2:frame=" << __builtin_coro_frame() << std::endl;
std::cout << "2:frame=" << _coro_frame_ptr() << std::endl;
co_await test_routine_use_timer();
std::cout << "2:frame=" << __builtin_coro_frame() << std::endl;
std::cout << "2:frame=" << _coro_frame_ptr() << std::endl;
co_await test_routine_use_timer();
std::cout << "2:frame=" << __builtin_coro_frame() << std::endl;
std::cout << "2:frame=" << _coro_frame_ptr() << std::endl;
}
#endif //#ifndef __GNUC__
void resumable_main_routine()
{
//go test_routine_use_timer_2();
#ifndef __GNUC__ //GCC: 没有提供__builtin_coro_frame这样的内置函数
go test_routine_use_timer();
#endif //#ifndef __GNUC__
this_scheduler()->run_until_notask();
}

+ 2
- 1
vs_proj/librf.vcxproj View File

@@ -40,7 +40,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>ClangCL</PlatformToolset>
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
@@ -248,6 +248,7 @@
<ClInclude Include="..\librf\src\timer.h" />
<ClInclude Include="..\librf\src\unix\clang_builtin.h" />
<ClInclude Include="..\librf\src\unix\coroutine.h" />
<ClInclude Include="..\librf\src\unix\gcc_builtin.h" />
<ClInclude Include="..\librf\src\when.h" />
<ClInclude Include="..\librf\src\when_v2.h" />
<ClInclude Include="..\librf\src\yield.h" />

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

@@ -243,6 +243,9 @@
<ClInclude Include="..\librf\src\config.h">
<Filter>librf\src</Filter>
</ClInclude>
<ClInclude Include="..\librf\src\unix\gcc_builtin.h">
<Filter>librf\src\unix</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\librf\src\asio_task_1.12.0.inl">

Loading…
Cancel
Save