Browse Source

兼容gcc 11.2/clang 14.0版本编译器

3.0.0
tearshark 1 year ago
parent
commit
3b42e893b3
5 changed files with 21 additions and 10 deletions
  1. 4
    4
      CMakeLists.txt
  2. 3
    3
      README.md
  3. 3
    3
      include/librf/librf.h
  4. 10
    0
      include/librf/src/channel_v2.inl
  5. 1
    0
      include/librf/src/timer.h

+ 4
- 4
CMakeLists.txt View File

@@ -30,22 +30,22 @@ else()
endif()
message(STATUS "LIBRF_COMPILER_SETTING=${LIBRF_COMPILER_SETTING}")
message(STATUS "CMAKE_CXX_COMPILER_VERSION=${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS "CMAKE_CXX_COMPILER_VERSION=${CMAKE_CXX_COMPILER_VERSION}")
if(${LIBRF_COMPILER_SETTING} STREQUAL "msvc")
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "19.30.0.0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++20 /EHsc") #VS2022
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++20 /EHsc /await") #VS2022
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /EHsc /await") #VS2019
endif()
elseif ("${LIBRF_COMPILER_SETTING}" STREQUAL "clang_on_msvc")
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "19.30.0.0")
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "12.0.0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++20 /EHsc") #VS2022
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /EHsc") #VS2019
endif()
elseif ("${LIBRF_COMPILER_SETTING}" STREQUAL "clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++2a -fcoroutines-ts -stdlib=libc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++2a -fcoroutines-ts -stdlib=libstdc++")
elseif ("${LIBRF_COMPILER_SETTING}" STREQUAL "gcc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++2a -fcoroutines -fconcepts-diagnostics-depth=8")
endif()

+ 3
- 3
README.md View File

@@ -8,10 +8,10 @@
Windows: 使用VS2017/VS2019编译(clang在兼容msvc模式下不支持异常,不再支持clang)
Android: 使用NDK 20.1 自带的clang编译
Mac: 使用XCode 11.2.1 自带的apple-clang编译
Ubuntu: 使用GCC 10.0.1/clang 9 编译(2020-04-18:mutex ranged lock failed)
Ubuntu: 使用GCC 11.2/clang 14 编译(2020-04-18:mutex ranged lock failed)
注意:GCC 10.0.1在C++ Coroutines上存在很多BUG,并且缺少对应的头文件
当前阶段不推荐使用GCC。
注意:GCC 10.0.1在C++ Coroutines上依然存在很多BUG。
当前阶段不推荐使用GCC(version 11.2以下)

<br>


+ 3
- 3
include/librf/librf.h View File

@@ -34,9 +34,7 @@
#include <thread>
#include <cassert>

#if defined(__clang__)
#include "src/unix/coroutine.h"
#elif __cpp_impl_coroutine
#if __cpp_impl_coroutine
#include <coroutine>
#ifdef _MSC_VER
extern "C" size_t _coro_frame_size();
@@ -59,6 +57,8 @@ extern "C" void _coro_resume_block();
#pragma intrinsic(_coro_cancel)
#pragma intrinsic(_coro_resume_block)
#endif
#elif defined(__clang__)
#include "src/unix/coroutine.h"
#else
#include <experimental/coroutine>
#endif

+ 10
- 0
include/librf/src/channel_v2.inl View File

@@ -341,6 +341,11 @@ namespace detail
, _value()
{}

read_awaiter(const read_awaiter&) = delete;
read_awaiter(read_awaiter&&) = default;
read_awaiter& operator=(const read_awaiter&) = delete;
read_awaiter& operator=(read_awaiter&&) = default;

~read_awaiter()
{//为了不在协程中也能正常使用
if (_channel != nullptr)
@@ -407,6 +412,11 @@ namespace detail
, _value(std::forward<U>(val))
{}

write_awaiter(const write_awaiter&) = delete;
write_awaiter(write_awaiter&&) = default;
write_awaiter& operator=(const write_awaiter&) = delete;
write_awaiter& operator=(write_awaiter&&) = default;

~write_awaiter()
{//为了不在协程中也能正常使用
if (_channel != nullptr)

+ 1
- 0
include/librf/src/timer.h View File

@@ -1,4 +1,5 @@
#pragma once
#include <memory>

namespace librf
{

Loading…
Cancel
Save