Skip to content

Commit

Permalink
重新启用 inline state 选项
Browse files Browse the repository at this point in the history
  • Loading branch information
tearshark committed Dec 15, 2023
1 parent ef9d716 commit 8e5b74b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ endif()


if(${LIBRF_COMPILER_SETTING} STREQUAL "msvc")
option(LIBRF_INLINE_STATE "Enable Inline state" OFF)
option(LIBRF_INLINE_STATE "Enable Inline state" ON)
elseif ("${LIBRF_COMPILER_SETTING}" STREQUAL "clang_on_msvc")
option(LIBRF_INLINE_STATE "Enable Inline state" OFF)
option(LIBRF_INLINE_STATE "Enable Inline state" ON)
elseif(${LIBRF_COMPILER_SETTING} STREQUAL "clang")
option(LIBRF_INLINE_STATE "Enable Inline state" OFF)
option(LIBRF_INLINE_STATE "Enable Inline state" ON)
elseif(${LIBRF_COMPILER_SETTING} STREQUAL "gcc")
option(LIBRF_INLINE_STATE "Enable Inline state" OFF)
else()
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmark_async_mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void resumable_main_benchmark_mem(bool wait_key)
}

//clang : 平均 256 字节
//msvc : 平均 320 字节(vs2022,17.7.4)
//msvc : 平均 304 字节(vs2022,17.7.4)

#if LIBRF_TUTORIAL_STAND_ALONE
int main()
Expand Down
4 changes: 2 additions & 2 deletions include/librf/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#ifndef RESUMEF_INLINE_STATE
#if defined(__clang__) || defined(_MSC_VER)
/* #undef RESUMEF_INLINE_STATE */
#define RESUMEF_INLINE_STATE 1
#else
/* #undef RESUMEF_INLINE_STATE */
#define RESUMEF_INLINE_STATE 0
#endif //defined(__clang__) || defined(_MSC_VER)
#endif //RESUMEF_INLINE_STATE

Expand Down
3 changes: 2 additions & 1 deletion include/librf/src/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ namespace librf
char* ptr = reinterpret_cast<char*>(h.address()) - _State_size;
return reinterpret_cast<state_type*>(ptr);
#elif defined(_MSC_VER)
char* ptr = reinterpret_cast<char*>(this) - _State_size;
auto h = coroutine_handle<promise_type>::from_promise(*this);
char* ptr = reinterpret_cast<char*>(h.address()) - _State_size;
return reinterpret_cast<state_type*>(ptr);
#else
#error "Unknown compiler"
Expand Down
5 changes: 4 additions & 1 deletion include/librf/src/promise.inl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ namespace librf
char* ptr = reinterpret_cast<char*>(h.address()) - _State_size;
return reinterpret_cast<state_type*>(ptr);
#elif defined(_MSC_VER)
char* ptr = reinterpret_cast<char*>(this) - _State_size;
auto h = coroutine_handle<promise_type>::from_promise(*reinterpret_cast<promise_type*>(this));
char* ptr = reinterpret_cast<char*>(h.address()) - _State_size;
return reinterpret_cast<state_type*>(ptr);
//char* ptr = reinterpret_cast<char*>(this) - _State_size;
//return reinterpret_cast<state_type*>(ptr);
#else
#error "Unknown compiler"
#endif
Expand Down
6 changes: 3 additions & 3 deletions tutorial/test_async_memory_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ future_t<int64_t> resumeable_get_long(int64_t x, int64_t y)

std::cout << " frame ptr=" << frame_ptr << "," << (void*)&frame_ptr << 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;
std::cout << " promise ptr=" << promise << "," << (void*)&promise << ",offset=" << ((char*)promise - (char*)frame_ptr) << std::endl;
std::cout << " handle ptr=" << handler.address() << "," << (void*)&handler << ",offset=" << ((char*)handler.address() - (char*)frame_ptr) << std::endl;
std::cout << " state ptr=" << state << "," << (void*)&state << ",offset=" << ((char*)state - (char*)frame_ptr) << std::endl;
std::cout << " parent ptr=" << state->get_parent() << std::endl;

std::cout << " x=" << x << ", &x=" << std::addressof(x) << std::endl;
Expand Down

0 comments on commit 8e5b74b

Please sign in to comment.