Browse Source

兼容gcc 10

tags/2.9.10
tearshark 4 years ago
parent
commit
7300bdd140

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

#pragma once #pragma once
#define LIB_RESUMEF_VERSION 20907 // 2.9.7
#define LIB_RESUMEF_VERSION 20908 // 2.9.8
namespace resumef namespace resumef
{ {

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

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

#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



using namespace resumef; using namespace resumef;


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

template<class _Ctype> template<class _Ctype>
static void callback_get_long(int64_t a, int64_t b, _Ctype&& cb) static void callback_get_long(int64_t a, int64_t b, _Ctype&& cb)
{ {
using promise_type = typename future_type::promise_type; using promise_type = typename future_type::promise_type;
using state_type = typename future_type::state_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); auto handler = coroutine_handle<promise_type>::from_address(frame_ptr);
promise_type* promise = &handler.promise(); promise_type* promise = &handler.promise();
state_type* state = handler.promise().get_state(); state_type* state = handler.promise().get_state();
std::cout << " future size=" << sizeof(future_type) << " / " << _Align_size<future_type>() << std::endl; 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 << " 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 << " 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 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 << " promise ptr=" << promise << "," << (void*)&promise << std::endl;
std::cout << " handle ptr=" << handler.address() << "," << (void*)&handler << std::endl; std::cout << " handle ptr=" << handler.address() << "," << (void*)&handler << std::endl;
std::cout << " state ptr=" << state << "," << (void*)&state << std::endl; std::cout << " state ptr=" << state << "," << (void*)&state << std::endl;
using promise_type = typename future_type::promise_type; using promise_type = typename future_type::promise_type;
using state_type = typename future_type::state_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); auto handler = coroutine_handle<promise_type>::from_address(frame_ptr);
promise_type * promise = &handler.promise(); promise_type * promise = &handler.promise();
state_type * state = handler.promise().get_state(); state_type * state = handler.promise().get_state();
std::cout << " future size=" << sizeof(future_type) << " / " << _Align_size<future_type>() << std::endl; 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 << " 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 << " 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 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 << " promise ptr=" << promise << "," << (void *)&promise << std::endl;
std::cout << " handle ptr=" << handler.address() << "," << (void*)&handler << std::endl; std::cout << " handle ptr=" << handler.address() << "," << (void*)&handler << std::endl;
std::cout << " state ptr=" << state << "," << (void*)&state << std::endl; std::cout << " state ptr=" << state << "," << (void*)&state << std::endl;


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


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


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


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

+ 8
- 4
tutorial/test_async_routine.cpp View File

using namespace resumef; using namespace resumef;
#ifndef __GNUC__ //GCC: 没有提供__builtin_coro_frame这样的内置函数
future_t<> test_routine_use_timer() future_t<> test_routine_use_timer()
{ {
using namespace std::chrono; using namespace std::chrono;
{ {
co_await resumef::sleep_for(100ms); co_await resumef::sleep_for(100ms);
std::cout << "timer after 100ms" << std::endl; 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;
} }
} }
std::cout << "test_routine_use_timer_2" << std::endl; std::cout << "test_routine_use_timer_2" << std::endl;
co_await test_routine_use_timer(); 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(); 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(); 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() void resumable_main_routine()
{ {
//go test_routine_use_timer_2(); //go test_routine_use_timer_2();
#ifndef __GNUC__ //GCC: 没有提供__builtin_coro_frame这样的内置函数
go test_routine_use_timer(); go test_routine_use_timer();
#endif //#ifndef __GNUC__
this_scheduler()->run_until_notask(); this_scheduler()->run_until_notask();
} }

+ 2
- 1
vs_proj/librf.vcxproj View File

</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>ClangCL</PlatformToolset>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ClInclude Include="..\librf\src\timer.h" /> <ClInclude Include="..\librf\src\timer.h" />
<ClInclude Include="..\librf\src\unix\clang_builtin.h" /> <ClInclude Include="..\librf\src\unix\clang_builtin.h" />
<ClInclude Include="..\librf\src\unix\coroutine.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.h" />
<ClInclude Include="..\librf\src\when_v2.h" /> <ClInclude Include="..\librf\src\when_v2.h" />
<ClInclude Include="..\librf\src\yield.h" /> <ClInclude Include="..\librf\src\yield.h" />

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

<ClInclude Include="..\librf\src\config.h"> <ClInclude Include="..\librf\src\config.h">
<Filter>librf\src</Filter> <Filter>librf\src</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\librf\src\unix\gcc_builtin.h">
<Filter>librf\src\unix</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\librf\src\asio_task_1.12.0.inl"> <None Include="..\librf\src\asio_task_1.12.0.inl">

Loading…
Cancel
Save