From 52a6339826027b923f5d51af3a17016a6a3861bb Mon Sep 17 00:00:00 2001 From: likepeng Date: Mon, 29 Jan 2024 16:48:25 +0800 Subject: [PATCH 01/12] fix windows compile error --- CMakeLists.txt | 4 ++++ templates/CMakeLists.txt | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc3e968..c62e552 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,7 @@ cmake_minimum_required(VERSION 3.10) +if (POLICY CMP0091) + cmake_policy(SET CMP0091 NEW) +endif() project(myframe VERSION 0.9.2) ### option @@ -22,6 +25,7 @@ else() set(CMAKE_CXX_STANDARD 17) message(STATUS "Set default cxx standard 17") endif() +add_compile_options("$<$:/source-charset:utf-8>") ### install path if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) diff --git a/templates/CMakeLists.txt b/templates/CMakeLists.txt index 189dd1c..c0e3861 100644 --- a/templates/CMakeLists.txt +++ b/templates/CMakeLists.txt @@ -1,13 +1,20 @@ cmake_minimum_required(VERSION 3.10) +if (POLICY CMP0091) + cmake_policy(SET CMP0091 NEW) +endif() project(@template_name@ VERSION 1.0.0) +#### cmake module +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") + #### compile option set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED YES) +set(CMAKE_C_VISIBILITY_PRESET hidden) +set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_POSITION_INDEPENDENT_CODE ON) - -#### cmake module -set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) +add_compile_options("$<$:/source-charset:utf-8>") #### deps lib find_package(myframe REQUIRED) From 565577fa8d0c0984b84435ce972c30241548991c Mon Sep 17 00:00:00 2001 From: likepeng Date: Wed, 31 Jan 2024 08:33:07 +0800 Subject: [PATCH 02/12] sub module remove glog --- myframe/CMakeLists.txt | 2 +- templates/template.cpp | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/myframe/CMakeLists.txt b/myframe/CMakeLists.txt index 14d8f71..0328dc2 100644 --- a/myframe/CMakeLists.txt +++ b/myframe/CMakeLists.txt @@ -20,7 +20,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads glog::glog - jsoncpp_lib + JsonCpp::JsonCpp ) set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION}) set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR}) diff --git a/templates/template.cpp b/templates/template.cpp index 86ed50e..1d75668 100644 --- a/templates/template.cpp +++ b/templates/template.cpp @@ -9,7 +9,6 @@ Author: likepeng #include #include -#include "myframe/log.h" #include "myframe/export.h" #include "myframe/msg.h" #include "myframe/actor.h" @@ -24,7 +23,6 @@ class @template_name@Actor : public myframe::Actor { void Proc(const std::shared_ptr& msg) override { /* print recv msg */ - LOG(INFO) << *msg << ": " << msg->GetData(); std::cout << *msg << ": " << msg->GetData() << std::endl; /* resp msg */ auto mailbox = GetMailbox(); @@ -49,7 +47,6 @@ class @template_name@Worker : public myframe::Worker { if (msg == nullptr) { break; } - LOG(INFO) << *msg << ": " << msg->GetData(); std::cout << *msg << ": " << msg->GetData() << std::endl; } std::this_thread::sleep_for(std::chrono::milliseconds(1000)); From fa5b04e5fb0d1399e449c012ba9e995e0d7b4ab0 Mon Sep 17 00:00:00 2001 From: likepeng Date: Sat, 17 Feb 2024 17:59:06 +0800 Subject: [PATCH 03/12] submodule use self export file --- CMakeLists.txt | 2 +- templates/CMakeLists.txt | 10 ++++++++-- templates/template.cpp | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c62e552..c75767d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,8 +16,8 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") ### compile option set(CMAKE_C_VISIBILITY_PRESET hidden) set(CMAKE_CXX_VISIBILITY_PRESET hidden) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) if (CMAKE_CXX_STANDARD_REQUIRED) message(STATUS "Set cxx standard ${CMAKE_CXX_STANDARD}") else() diff --git a/templates/CMakeLists.txt b/templates/CMakeLists.txt index c0e3861..dfca873 100644 --- a/templates/CMakeLists.txt +++ b/templates/CMakeLists.txt @@ -12,8 +12,8 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED YES) set(CMAKE_C_VISIBILITY_PRESET hidden) set(CMAKE_CXX_VISIBILITY_PRESET hidden) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_compile_options("$<$:/source-charset:utf-8>") #### deps lib @@ -26,7 +26,13 @@ add_library(${PROJECT_NAME} SHARED target_link_libraries(${PROJECT_NAME} myframe ) -target_compile_definitions(${PROJECT_NAME} PRIVATE myframe_EXPORTS) + +#### export +include (GenerateExportHeader) +generate_export_header (${PROJECT_NAME} + EXPORT_MACRO_NAME MYFRAME_SUBMODULE_EXPORT + EXPORT_FILE_NAME "${CMAKE_CURRENT_SOURCE_DIR}/export.h" +) #### install install(TARGETS ${PROJECT_NAME} diff --git a/templates/template.cpp b/templates/template.cpp index 1d75668..bcc46f7 100644 --- a/templates/template.cpp +++ b/templates/template.cpp @@ -9,7 +9,7 @@ Author: likepeng #include #include -#include "myframe/export.h" +#include "export.h" #include "myframe/msg.h" #include "myframe/actor.h" #include "myframe/worker.h" @@ -54,7 +54,7 @@ class @template_name@Worker : public myframe::Worker { }; /* create actor instance */ -extern "C" MYFRAME_EXPORT std::shared_ptr actor_create( +extern "C" MYFRAME_SUBMODULE_EXPORT std::shared_ptr actor_create( const std::string& actor_name) { if (actor_name == "@template_name@") { return std::make_shared<@template_name@Actor>(); @@ -63,7 +63,7 @@ extern "C" MYFRAME_EXPORT std::shared_ptr actor_create( } /* create worker instance */ -extern "C" MYFRAME_EXPORT std::shared_ptr worker_create( +extern "C" MYFRAME_SUBMODULE_EXPORT std::shared_ptr worker_create( const std::string& worker_name) { if (worker_name == "@template_name@") { return std::make_shared<@template_name@Worker>(); From 0c8651c8b2fc68017282b9ed0b1aecbd4da8a3d2 Mon Sep 17 00:00:00 2001 From: likepeng Date: Sun, 25 Feb 2024 12:15:14 +0800 Subject: [PATCH 04/12] fix linux compile error --- .github/workflows/linux.yml | 3 ++ .github/workflows/macos.yml | 2 + .github/workflows/windows.yml | 80 ++++++++++++++++++----------------- 3 files changed, 46 insertions(+), 39 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 02217cb..f71c5d2 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -43,6 +43,7 @@ jobs: if: steps.cache-jsoncpp.outputs.cache-hit != 'true' run: | cmake -S jsoncpp-1.9.5 -B build-jsoncpp \ + -DBUILD_SHARED_LIBS=ON \ -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/jsoncpp \ -DBUILD_OBJECT_LIBS=OFF \ @@ -69,6 +70,7 @@ jobs: if: steps.cache-glog.outputs.cache-hit != 'true' run: | cmake -S glog-0.6.0 -B build-glog \ + -DBUILD_SHARED_LIBS=ON \ -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/glog \ -DWITH_PKGCONFIG=OFF \ @@ -85,6 +87,7 @@ jobs: # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type run: | cmake -S . -B ${{github.workspace}}/build_${{matrix.build_type}} \ + -DBUILD_SHARED_LIBS=ON \ -DCMAKE_CXX_STANDARD=${{matrix.std}} \ -DCMAKE_CXX_STANDARD_REQUIRED=ON \ -DMYFRAME_USE_CV=OFF \ diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 40d0f70..c4db15d 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -43,6 +43,7 @@ jobs: if: steps.cache-jsoncpp.outputs.cache-hit != 'true' run: | cmake -S jsoncpp-1.9.5 -B build-jsoncpp \ + -DBUILD_SHARED_LIBS=ON \ -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/jsoncpp \ -DBUILD_OBJECT_LIBS=OFF \ @@ -94,6 +95,7 @@ jobs: if: steps.cache-glog.outputs.cache-hit != 'true' run: | cmake -S glog-0.6.0 -B build-glog \ + -DBUILD_SHARED_LIBS=ON \ -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ -DWITH_PKGCONFIG=OFF \ -DWITH_GTEST=OFF \ diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 3e27535..35d340d 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -47,16 +47,17 @@ jobs: if: steps.cache-jsoncpp.outputs.cache-hit != 'true' run: | cmake -S jsoncpp-1.9.5 -B build-jsoncpp ` - -A ${{matrix.arch}} ` - -DCMAKE_BUILD_TYPE=${{matrix.build_type}} ` - -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/jsoncpp ` - -DBUILD_OBJECT_LIBS=OFF ` - -DJSONCPP_WITH_TESTS=OFF ` - -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF ` - -DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF + -A ${{matrix.arch}} ` + -DBUILD_SHARED_LIBS=ON \ + -DCMAKE_BUILD_TYPE=${{matrix.build_type}} ` + -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/jsoncpp ` + -DBUILD_OBJECT_LIBS=OFF ` + -DJSONCPP_WITH_TESTS=OFF ` + -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF ` + -DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF cmake --build build-jsoncpp ` - --config ${{matrix.build_type}} ` - --target install + --config ${{matrix.build_type}} ` + --target install - name: Cache gflags id: cache-gflags @@ -75,12 +76,12 @@ jobs: if: steps.cache-gflags.outputs.cache-hit != 'true' run: | cmake -S gflags-2.2.2 -B build-gflags ` - -A ${{matrix.arch}} ` - -DBUILD_SHARED_LIBS=ON ` - -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/gflags + -A ${{matrix.arch}} ` + -DBUILD_SHARED_LIBS=ON ` + -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/gflags cmake --build build-gflags ` - --config ${{matrix.build_type}} ` - --target install + --config ${{matrix.build_type}} ` + --target install - name: Cache glog id: cache-glog @@ -99,39 +100,40 @@ jobs: if: steps.cache-glog.outputs.cache-hit != 'true' run: | cmake -S glog-0.6.0 -B build-glog ` - -A ${{matrix.arch}} ` - -DBUILD_SHARED_LIBS=ON ` - -DWITH_GTEST=OFF ` - -DWITH_PKGCONFIG=OFF ` - -DCMAKE_PREFIX_PATH="${{github.workspace}}/gflags" ` - -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/glog + -A ${{matrix.arch}} ` + -DBUILD_SHARED_LIBS=ON ` + -DWITH_GTEST=OFF ` + -DWITH_PKGCONFIG=OFF ` + -DCMAKE_PREFIX_PATH="${{github.workspace}}/gflags" ` + -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/glog cmake --build build-glog ` - --config ${{matrix.build_type}} ` - --target install + --config ${{matrix.build_type}} ` + --target install - name: Configure run: | cmake -S . -B build_${{matrix.build_type}} ` - -A ${{matrix.arch}} ` - -DMYFRAME_USE_CV=ON ` - -DBUILD_SHARED_LIBS=ON ` - -DCMAKE_CXX_EXTENSIONS=OFF ` - -DCMAKE_CXX_STANDARD=${{matrix.std}} ` - -DCMAKE_CXX_STANDARD_REQUIRED=ON ` - -DCMAKE_EXE_LINKER_FLAGS='/NOIMPLIB' ` - -DCMAKE_EXE_LINKER_FLAGS_RELEASE='/INCREMENTAL:NO /DEBUG' ` - -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/myframe ` - -DCMAKE_PREFIX_PATH="${{github.workspace}}/jsoncpp;${{github.workspace}}/glog;${{github.workspace}}/gflags" ` - -DCMAKE_MSVC_RUNTIME_LIBRARY='MultiThreaded$<$:Debug>DLL' ` - -G "${{matrix.generator}}" ` - -Werror + -A ${{matrix.arch}} ` + -DMYFRAME_USE_CV=ON ` + -DBUILD_SHARED_LIBS=ON ` + -DCMAKE_CXX_EXTENSIONS=OFF ` + -DCMAKE_CXX_STANDARD=${{matrix.std}} ` + -DCMAKE_CXX_STANDARD_REQUIRED=ON ` + -DCMAKE_EXE_LINKER_FLAGS='/NOIMPLIB' ` + -DCMAKE_EXE_LINKER_FLAGS_RELEASE='/INCREMENTAL:NO /DEBUG' ` + -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/myframe ` + -DCMAKE_PREFIX_PATH="${{github.workspace}}/jsoncpp;${{github.workspace}}/glog;${{github.workspace}}/gflags" ` + -DCMAKE_MSVC_RUNTIME_LIBRARY='MultiThreaded$<$:Debug>DLL' ` + -G "${{matrix.generator}}" ` + -Werror - name: Build - run: cmake --build build_${{matrix.build_type}} ` - --config ${{matrix.build_type}} + run: | + cmake --build build_${{matrix.build_type}} ` + --config ${{matrix.build_type}} - name: Install run: | cmake --build build_${{matrix.build_type}} ` - --config ${{matrix.build_type}} ` - --target install + --config ${{matrix.build_type}} ` + --target install From ce7dbce35f5ccef1b50aa18cca487430e2419289 Mon Sep 17 00:00:00 2001 From: likepeng Date: Sun, 25 Feb 2024 12:42:59 +0800 Subject: [PATCH 05/12] fix compile error2 --- .github/workflows/linux.yml | 3 ++- .github/workflows/macos.yml | 3 ++- .github/workflows/windows.yml | 5 +++-- templates/template.cpp | 6 ++++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index f71c5d2..0ffa9f4 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -44,9 +44,10 @@ jobs: run: | cmake -S jsoncpp-1.9.5 -B build-jsoncpp \ -DBUILD_SHARED_LIBS=ON \ + -DBUILD_STATIC_LIBS=OFF \ + -DBUILD_OBJECT_LIBS=OFF \ -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/jsoncpp \ - -DBUILD_OBJECT_LIBS=OFF \ -DJSONCPP_WITH_TESTS=OFF \ -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF \ -DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF \ diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index c4db15d..d35edd4 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -44,9 +44,10 @@ jobs: run: | cmake -S jsoncpp-1.9.5 -B build-jsoncpp \ -DBUILD_SHARED_LIBS=ON \ + -DBUILD_STATIC_LIBS=OFF \ + -DBUILD_OBJECT_LIBS=OFF \ -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/jsoncpp \ - -DBUILD_OBJECT_LIBS=OFF \ -DJSONCPP_WITH_TESTS=OFF \ -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF \ -DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF \ diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 35d340d..cd1a66d 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -48,10 +48,11 @@ jobs: run: | cmake -S jsoncpp-1.9.5 -B build-jsoncpp ` -A ${{matrix.arch}} ` - -DBUILD_SHARED_LIBS=ON \ + -DBUILD_SHARED_LIBS=ON ` + -DBUILD_STATIC_LIBS=OFF ` + -DBUILD_OBJECT_LIBS=OFF ` -DCMAKE_BUILD_TYPE=${{matrix.build_type}} ` -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/jsoncpp ` - -DBUILD_OBJECT_LIBS=OFF ` -DJSONCPP_WITH_TESTS=OFF ` -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF ` -DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF diff --git a/templates/template.cpp b/templates/template.cpp index bcc46f7..0bcd131 100644 --- a/templates/template.cpp +++ b/templates/template.cpp @@ -54,7 +54,8 @@ class @template_name@Worker : public myframe::Worker { }; /* create actor instance */ -extern "C" MYFRAME_SUBMODULE_EXPORT std::shared_ptr actor_create( +extern "C" MYFRAME_SUBMODULE_EXPORT std::shared_ptr +actor_create( const std::string& actor_name) { if (actor_name == "@template_name@") { return std::make_shared<@template_name@Actor>(); @@ -63,7 +64,8 @@ extern "C" MYFRAME_SUBMODULE_EXPORT std::shared_ptr actor_create } /* create worker instance */ -extern "C" MYFRAME_SUBMODULE_EXPORT std::shared_ptr worker_create( +extern "C" MYFRAME_SUBMODULE_EXPORT std::shared_ptr +worker_create( const std::string& worker_name) { if (worker_name == "@template_name@") { return std::make_shared<@template_name@Worker>(); From 209eafe0aa0f80ce83315dfde796af11498583cd Mon Sep 17 00:00:00 2001 From: likepeng Date: Mon, 11 Mar 2024 01:17:53 +0800 Subject: [PATCH 06/12] method Subscribe add msg type param --- myframe/actor.cpp | 7 ++++--- myframe/actor.h | 12 +++++++----- myframe/msg.h | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/myframe/actor.cpp b/myframe/actor.cpp index 870c17b..0c78bbc 100644 --- a/myframe/actor.cpp +++ b/myframe/actor.cpp @@ -71,18 +71,19 @@ int Actor::Timeout(const std::string& timer_name, int expired) { return timer_worker->SetTimeout(GetActorName(), timer_name, expired); } -bool Actor::Subscribe(const std::string& name) { +bool Actor::Subscribe(const std::string& addr, const std::string& msg_type) { auto ctx = ctx_.lock(); if (ctx == nullptr) { return false; } - if (name == GetActorName()) { + if (addr == GetActorName()) { return false; } auto msg = std::make_shared(); msg->SetType("SUBSCRIBE"); + msg->SetDesc(msg_type); auto mailbox = ctx->GetMailbox(); - mailbox->Send(name, msg); + mailbox->Send(addr, msg); return true; } diff --git a/myframe/actor.h b/myframe/actor.h index 7872f0b..876ef28 100644 --- a/myframe/actor.h +++ b/myframe/actor.h @@ -87,15 +87,17 @@ class MYFRAME_EXPORT Actor { int Timeout(const std::string& timer_name, int expired); /** - * Subscribe() - 订阅actor或者worker的消息 - * @name: 订阅actor或者worker的名称 + * Subscribe() - 订阅actor的消息 + * @addr: 订阅actor的地址 + * @msg_type: 订阅消息类型 * - * 被订阅的组件需要处理订阅消息,消息格式: + * 被订阅的组件需要在Proc函数中处理订阅消息,消息格式: * msg->GetType() == "SUBSCRIBE" 确认是订阅消息 - * msg->GetSrc() 确定是订阅组件名称 + * msg->GetDesc() == 确认消息类型 + * msg->GetSrc() 确定是订阅组件地址 * @return: 成功返回true,失败返回false */ - bool Subscribe(const std::string& name); + bool Subscribe(const std::string& addr, const std::string& msg_type = ""); /** * GetApp() - 获得应用实例 diff --git a/myframe/msg.h b/myframe/msg.h index 2242aa0..d0b3efb 100644 --- a/myframe/msg.h +++ b/myframe/msg.h @@ -47,7 +47,7 @@ class MYFRAME_EXPORT Msg final { /** * @brief 消息类型 - * @note 目前使用到的 "TEXT", "TIMER"; + * @note 目前使用到的 "TEXT", "TIMER", "SUBSCRIBE"; * 也可以自定义,用于区分传递给同一个actor的不同消息类型 * @return const std::string& 消息类型 */ From e47c6296ca0447edf51b58e4753bd0a2c1055d1b Mon Sep 17 00:00:00 2001 From: likepeng Date: Mon, 6 May 2024 20:40:29 +0800 Subject: [PATCH 07/12] add deps install cmake scripts --- .gitignore | 4 +++ 3rd/CMakeLists.txt | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 3rd/README.md | 2 ++ README.md | 14 +++++++++- 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 3rd/CMakeLists.txt create mode 100644 3rd/README.md diff --git a/.gitignore b/.gitignore index 3135705..856a5df 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,7 @@ launcher/launcher_config.h test/performance_test_config.h myframe/export.h myframe/config.h +3rd/pkg/ +3rd/src/ +3rd/build/ +output/ diff --git a/3rd/CMakeLists.txt b/3rd/CMakeLists.txt new file mode 100644 index 0000000..5f226dd --- /dev/null +++ b/3rd/CMakeLists.txt @@ -0,0 +1,67 @@ +cmake_minimum_required(VERSION 3.10) +if (POLICY CMP0091) + cmake_policy(SET CMP0091 NEW) +endif() +project(myframe_deps VERSION 1.0.0) + +include(ExternalProject) + +set(DEPS_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src) +set(DEPS_DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/pkg) + +ExternalProject_Add( + gflags + URL https://github.com/gflags/gflags/archive/refs/tags/v2.2.2.tar.gz + URL_MD5 1a865b93bacfa963201af3f75b7bd64c + DOWNLOAD_NAME "gflags.tar.gz" + PREFIX ${CMAKE_BINARY_DIR} + DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR} + SOURCE_DIR "${DEPS_SOURCE_DIR}/gflags" + UPDATE_COMMAND "" + PATCH_COMMAND "" + CMAKE_ARGS + -DBUILD_SHARED_LIBS=ON + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} +) + +ExternalProject_Add( + glog + URL https://github.com/google/glog/archive/refs/tags/v0.6.0.tar.gz + URL_MD5 c98a6068bc9b8ad9cebaca625ca73aa2 + DOWNLOAD_NAME "glog.tar.gz" + PREFIX ${CMAKE_BINARY_DIR} + DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR} + SOURCE_DIR "${DEPS_SOURCE_DIR}/glog" + UPDATE_COMMAND "" + PATCH_COMMAND "" + CMAKE_ARGS + -DBUILD_SHARED_LIBS=ON + -DCMAKE_BUILD_TYPE=Release + -DWITH_PKGCONFIG=OFF + -DWITH_GTEST=OFF + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} + -DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX} +) +ExternalProject_Add_StepDependencies(glog install gflags) + +ExternalProject_Add( + jsoncpp + URL https://github.com/open-source-parsers/jsoncpp/archive/refs/tags/1.9.5.tar.gz + URL_MD5 d6c8c609f2162eff373db62b90a051c7 + DOWNLOAD_NAME "jsoncpp.tar.gz" + PREFIX ${CMAKE_BINARY_DIR} + DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR} + SOURCE_DIR "${DEPS_SOURCE_DIR}/jsoncpp" + UPDATE_COMMAND "" + PATCH_COMMAND "" + CMAKE_ARGS + -DBUILD_SHARED_LIBS=ON + -DBUILD_STATIC_LIBS=OFF + -DBUILD_OBJECT_LIBS=OFF + -DCMAKE_BUILD_TYPE=Release + -DJSONCPP_WITH_TESTS=OFF + -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF + -DJSONCPP_WITH_PKGCONFIG_SUPPORT=OFF + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} +) diff --git a/3rd/README.md b/3rd/README.md new file mode 100644 index 0000000..8db965e --- /dev/null +++ b/3rd/README.md @@ -0,0 +1,2 @@ +# 3rd +该目录主要用于下载/构建/安装依赖包使用 diff --git a/README.md b/README.md index 43b735a..ae12259 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,23 @@ worker自驱动,可以通过消息与actor交互; | Windows | | macOS | -## 构建 +## github构建 * [github ci linux](.github/workflows/linux.yml) * [github ci windows](.github/workflows/windows.yml) * [github ci macOS](.github/workflows/macos.yml) +## 快速本地构建 +```sh +# 下载/构建/安装依赖库 +cd 3rd +cmake -S . -B build -DCMAKE_INSTALL_PREFIX=../output +cmake --build build -j +# 构建安装 +cd .. +cmake -S . -B build -DCMAKE_INSTALL_PREFIX=./output -DCMAKE_PREFIX_PATH=./output +cmake --build build -j --config Release --target install +``` + ### Hello,World 示例 ```c #include From e8cf2f6dfbf24d4c9b747f615aac02c5705ade0e Mon Sep 17 00:00:00 2001 From: likepeng Date: Wed, 8 May 2024 18:49:32 +0800 Subject: [PATCH 08/12] Optimize pointer access --- myframe/actor.cpp | 22 +++++++++------------- myframe/actor.h | 4 ++-- myframe/actor_context.cpp | 2 +- myframe/actor_context.h | 2 +- myframe/app.cpp | 1 - myframe/event.h | 2 +- myframe/worker.cpp | 22 +++++++++------------- myframe/worker.h | 4 ++-- myframe/worker_context.cpp | 1 + 9 files changed, 26 insertions(+), 34 deletions(-) diff --git a/myframe/actor.cpp b/myframe/actor.cpp index 0c78bbc..6af5a9f 100644 --- a/myframe/actor.cpp +++ b/myframe/actor.cpp @@ -33,11 +33,10 @@ const std::string& Actor::GetModName() const { bool Actor::IsFromLib() const { return is_from_lib_; } Mailbox* Actor::GetMailbox() { - auto ctx = ctx_.lock(); - if (ctx == nullptr) { + if (ctx_ == nullptr) { return nullptr; } - return ctx->GetMailbox(); + return ctx_->GetMailbox(); } const std::string& Actor::GetTypeName() const { return actor_name_; } @@ -53,12 +52,11 @@ void Actor::SetTypeName(const std::string& name) { actor_name_ = name; } void Actor::SetInstName(const std::string& name) { instance_name_ = name; } int Actor::Timeout(const std::string& timer_name, int expired) { - auto ctx = ctx_.lock(); - if (ctx == nullptr) { + if (ctx_ == nullptr) { LOG(ERROR) << "actor context is nullptr"; return -1; } - auto app = ctx->GetApp(); + auto app = ctx_->GetApp(); if (app == nullptr) { LOG(ERROR) << "app is nullptr"; return -1; @@ -72,8 +70,7 @@ int Actor::Timeout(const std::string& timer_name, int expired) { } bool Actor::Subscribe(const std::string& addr, const std::string& msg_type) { - auto ctx = ctx_.lock(); - if (ctx == nullptr) { + if (ctx_ == nullptr) { return false; } if (addr == GetActorName()) { @@ -82,12 +79,12 @@ bool Actor::Subscribe(const std::string& addr, const std::string& msg_type) { auto msg = std::make_shared(); msg->SetType("SUBSCRIBE"); msg->SetDesc(msg_type); - auto mailbox = ctx->GetMailbox(); + auto mailbox = ctx_->GetMailbox(); mailbox->Send(addr, msg); return true; } -void Actor::SetContext(std::shared_ptr c) { ctx_ = c; } +void Actor::SetContext(ActorContext* c) { ctx_ = c; } const Json::Value* Actor::GetConfig() const { return &config_; @@ -98,11 +95,10 @@ void Actor::SetConfig(const Json::Value& conf) { } std::shared_ptr Actor::GetApp() { - auto ctx = ctx_.lock(); - if (ctx == nullptr) { + if (ctx_ == nullptr) { return nullptr; } - return ctx->GetApp(); + return ctx_->GetApp(); } } // namespace myframe diff --git a/myframe/actor.h b/myframe/actor.h index 876ef28..e08059c 100644 --- a/myframe/actor.h +++ b/myframe/actor.h @@ -116,14 +116,14 @@ class MYFRAME_EXPORT Actor { void SetInstName(const std::string& name); void SetConfig(const Json::Value& conf); - void SetContext(std::shared_ptr); + void SetContext(ActorContext*); bool is_from_lib_{ false }; std::string mod_name_; std::string actor_name_; std::string instance_name_; Json::Value config_; - std::weak_ptr ctx_; + ActorContext* ctx_{ nullptr }; DISALLOW_COPY_AND_ASSIGN(Actor) }; diff --git a/myframe/actor_context.cpp b/myframe/actor_context.cpp index 2392295..15db419 100644 --- a/myframe/actor_context.cpp +++ b/myframe/actor_context.cpp @@ -23,6 +23,7 @@ ActorContext::ActorContext( , in_wait_que_(false) , actor_(actor) , app_(app) { + actor_->SetContext(this); mailbox_.SetAddr(actor_->GetActorName()); LOG(INFO) << mailbox_.Addr() << " context create"; } @@ -34,7 +35,6 @@ ActorContext::~ActorContext() { std::shared_ptr ActorContext::GetApp() { return app_.lock(); } int ActorContext::Init(const char* param) { - actor_->SetContext(shared_from_this()); return actor_->Init(param); } diff --git a/myframe/actor_context.h b/myframe/actor_context.h index b9ef15e..ac2cd12 100644 --- a/myframe/actor_context.h +++ b/myframe/actor_context.h @@ -19,7 +19,7 @@ class App; class Msg; class Actor; class WorkerCommon; -class ActorContext final : public std::enable_shared_from_this { +class ActorContext final { friend std::ostream& operator<<(std::ostream& out, const ActorContext& ctx); friend class ActorContextManager; friend class WorkerCommon; diff --git a/myframe/app.cpp b/myframe/app.cpp index 6975dd4..1a3fa2b 100644 --- a/myframe/app.cpp +++ b/myframe/app.cpp @@ -276,7 +276,6 @@ bool App::AddWorker( const Json::Value& config) { auto worker_ctx = std::make_shared( shared_from_this(), worker, poller_); - worker->SetContext(worker_ctx); worker->SetInstName(inst_name); worker->SetConfig(config); if (worker->GetTypeName() == "node") { diff --git a/myframe/event.h b/myframe/event.h index c072d0a..b357275 100644 --- a/myframe/event.h +++ b/myframe/event.h @@ -31,7 +31,7 @@ namespace myframe { #error "Unsupported platform" #endif -class MYFRAME_EXPORT Event : public std::enable_shared_from_this { +class MYFRAME_EXPORT Event { public: enum class Type : int { kWorkerCommon, diff --git a/myframe/worker.cpp b/myframe/worker.cpp index 3601187..0a0ddf2 100644 --- a/myframe/worker.cpp +++ b/myframe/worker.cpp @@ -28,11 +28,10 @@ void Worker::SetTypeName(const std::string& name) { worker_name_ = name; } void Worker::SetInstName(const std::string& name) { inst_name_ = name; } void Worker::Stop() { - auto ctx = ctx_.lock(); - if (ctx == nullptr) { + if (ctx_ == nullptr) { return; } - ctx->Stop(); + ctx_->Stop(); } int Worker::DispatchMsg() { @@ -62,18 +61,16 @@ int Worker::DispatchAndWaitMsg() { } Mailbox* Worker::GetMailbox() { - auto ctx = ctx_.lock(); - if (ctx == nullptr) { + if (ctx_ == nullptr) { return nullptr; } - return ctx->GetMailbox(); + return ctx_->GetMailbox(); } CmdChannel* Worker::GetCmdChannel() { - auto ctx = ctx_.lock(); - LOG_IF(FATAL, ctx == nullptr) + LOG_IF(FATAL, ctx_ == nullptr) << "worker ctx is nullptr"; - return ctx->GetCmdChannel(); + return ctx_->GetCmdChannel(); } void Worker::SetConfig(const Json::Value& conf) { @@ -84,7 +81,7 @@ const Json::Value* Worker::GetConfig() const { return &config_; } -void Worker::SetContext(std::shared_ptr ctx) { +void Worker::SetContext(WorkerContext* ctx) { ctx_ = ctx; } @@ -93,11 +90,10 @@ Event::Type Worker::GetType() { } std::shared_ptr Worker::GetApp() { - auto ctx = ctx_.lock(); - if (ctx == nullptr) { + if (ctx_ == nullptr) { return nullptr; } - return ctx->GetApp(); + return ctx_->GetApp(); } } // namespace myframe diff --git a/myframe/worker.h b/myframe/worker.h index d1c77c2..4cfa9a8 100644 --- a/myframe/worker.h +++ b/myframe/worker.h @@ -114,14 +114,14 @@ class MYFRAME_EXPORT Worker { void SetInstName(const std::string&); void SetConfig(const Json::Value&); - void SetContext(std::shared_ptr); + void SetContext(WorkerContext*); std::string mod_name_; std::string worker_name_; std::string inst_name_; Json::Value config_; - std::weak_ptr ctx_; + WorkerContext* ctx_{ nullptr }; DISALLOW_COPY_AND_ASSIGN(Worker) }; diff --git a/myframe/worker_context.cpp b/myframe/worker_context.cpp index eacc2aa..ee255e6 100644 --- a/myframe/worker_context.cpp +++ b/myframe/worker_context.cpp @@ -23,6 +23,7 @@ WorkerContext::WorkerContext( : runing_(false) , worker_(worker) , app_(app) { + worker_->SetContext(this); cmd_channel_ = CmdChannel::Create(poller); } From c272690a322c83b85a8ba843bd92d64f6d84123d Mon Sep 17 00:00:00 2001 From: likepeng Date: Fri, 24 May 2024 17:43:54 +0800 Subject: [PATCH 09/12] Optimize list append --- myframe/common.h | 7 ------- myframe/mailbox.cpp | 5 ++--- myframe/worker_context.cpp | 3 +-- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/myframe/common.h b/myframe/common.h index e799b94..d1c4dfc 100644 --- a/myframe/common.h +++ b/myframe/common.h @@ -31,13 +31,6 @@ class MYFRAME_EXPORT Common final { static stdfs::path GetAbsolutePath(const std::string& flag_path); static bool IsAbsolutePath(const std::string& path); - template - static void ListAppend( - std::list>* dst, - std::list>* src) { - dst->insert(dst->end(), src->begin(), src->end()); - src->clear(); - } static std::vector SplitMsgName(const std::string& name); }; diff --git a/myframe/mailbox.cpp b/myframe/mailbox.cpp index 5dabef3..d4fd842 100644 --- a/myframe/mailbox.cpp +++ b/myframe/mailbox.cpp @@ -5,7 +5,6 @@ All rights reserved. Author: 李柯鹏 ****************************************************************************/ #include "myframe/mailbox.h" -#include "myframe/common.h" #include "myframe/msg.h" namespace myframe { @@ -51,7 +50,7 @@ void Mailbox::Send( } void Mailbox::Send(std::list>* msg_list) { - Common::ListAppend(&send_, msg_list); + send_.splice(send_.end(), *msg_list); } std::list>* Mailbox::GetSendList() { @@ -75,7 +74,7 @@ void Mailbox::Recv(std::shared_ptr msg) { } void Mailbox::Recv(std::list>* msg_list) { - Common::ListAppend(&recv_, msg_list); + recv_.splice(recv_.end(), *msg_list); } const std::shared_ptr Mailbox::PopRecv() { diff --git a/myframe/worker_context.cpp b/myframe/worker_context.cpp index ee255e6..4ef0b40 100644 --- a/myframe/worker_context.cpp +++ b/myframe/worker_context.cpp @@ -9,7 +9,6 @@ Author: 李柯鹏 #include #include "myframe/log.h" -#include "myframe/common.h" #include "myframe/msg.h" #include "myframe/worker.h" #include "myframe/app.h" @@ -90,7 +89,7 @@ void WorkerContext::Cache(std::shared_ptr msg) { } void WorkerContext::Cache(std::list>* msg_list) { - Common::ListAppend(&cache_, msg_list); + cache_.splice(cache_.end(), *msg_list); } Mailbox* WorkerContext::GetMailbox() { From 2ca226250e556a99c25f15c9c517cdcefe1b7d21 Mon Sep 17 00:00:00 2001 From: likepeng Date: Thu, 6 Jun 2024 19:33:13 +0800 Subject: [PATCH 10/12] Optimize pointer access2 --- myframe/actor.cpp | 2 +- myframe/actor_context_manager.cpp | 26 ++++++++++++++------------ myframe/app.cpp | 14 ++++++++------ myframe/app.h | 2 +- myframe/common.cpp | 2 +- myframe/event_conn.cpp | 4 ++-- myframe/event_conn_manager.cpp | 6 +++--- myframe/event_manager.cpp | 4 ++-- myframe/event_manager.h | 4 ++-- myframe/mailbox.cpp | 8 ++++---- myframe/worker_context.cpp | 2 +- myframe/worker_context_manager.cpp | 4 ++-- myframe/worker_timer.cpp | 2 +- 13 files changed, 42 insertions(+), 38 deletions(-) diff --git a/myframe/actor.cpp b/myframe/actor.cpp index 6af5a9f..93817e0 100644 --- a/myframe/actor.cpp +++ b/myframe/actor.cpp @@ -80,7 +80,7 @@ bool Actor::Subscribe(const std::string& addr, const std::string& msg_type) { msg->SetType("SUBSCRIBE"); msg->SetDesc(msg_type); auto mailbox = ctx_->GetMailbox(); - mailbox->Send(addr, msg); + mailbox->Send(addr, std::move(msg)); return true; } diff --git a/myframe/actor_context_manager.cpp b/myframe/actor_context_manager.cpp index c2077e3..e99d09b 100644 --- a/myframe/actor_context_manager.cpp +++ b/myframe/actor_context_manager.cpp @@ -34,8 +34,8 @@ void ActorContextManager::DispatchMsg( return; } auto mailbox = ctx->GetMailbox(); - mailbox->Recv(msg); - PushContext(ctx); + mailbox->Recv(std::move(msg)); + PushContext(std::move(ctx)); } bool ActorContextManager::RegContext(std::shared_ptr ctx) { @@ -46,7 +46,7 @@ bool ActorContextManager::RegContext(std::shared_ptr ctx) { return false; } LOG(INFO) << "reg actor " << ctx->GetActor()->GetActorName(); - ctxs_[ctx->GetActor()->GetActorName()] = ctx; + ctxs_[ctx->GetActor()->GetActorName()] = std::move(ctx); return true; } @@ -76,6 +76,9 @@ bool ActorContextManager::HasActor(const std::string& name) { } void ActorContextManager::PrintWaitQueue() { + if (!VLOG_IS_ON(1)) { + return; + } VLOG(1) << "cur wait queue actor:"; auto it = wait_queue_.begin(); while (it != wait_queue_.end()) { @@ -94,7 +97,7 @@ std::shared_ptr ActorContextManager::GetContextWithMsg() { return nullptr; } - std::vector> in_runing_context; + std::list> in_runing_context; std::shared_ptr ret = nullptr; while (!wait_queue_.empty()) { if (wait_queue_.front().expired()) { @@ -104,20 +107,19 @@ std::shared_ptr ActorContextManager::GetContextWithMsg() { auto ctx = wait_queue_.front().lock(); if (ctx->IsRuning()) { wait_queue_.pop_front(); - in_runing_context.push_back(ctx); + VLOG(1) << ctx->GetActor()->GetActorName() + << " is runing, move to wait queue back"; + in_runing_context.push_back(std::move(ctx)); } else { wait_queue_.pop_front(); - ctx->SetRuningFlag(true); ctx->SetWaitQueueFlag(false); - ret = ctx; + ret.swap(ctx); break; } } - for (std::size_t i = 0; i < in_runing_context.size(); ++i) { - VLOG(1) << in_runing_context[i]->GetActor()->GetActorName() - << " is runing, move to wait queue back"; - wait_queue_.push_back(in_runing_context[i]); + if (!in_runing_context.empty()) { + wait_queue_.splice(wait_queue_.end(), in_runing_context); } return ret; } @@ -129,7 +131,7 @@ void ActorContextManager::PushContext(std::shared_ptr ctx) { return; } ctx->SetWaitQueueFlag(true); - wait_queue_.push_back(ctx); + wait_queue_.push_back(std::move(ctx)); PrintWaitQueue(); } diff --git a/myframe/app.cpp b/myframe/app.cpp index 1a3fa2b..b8e4039 100644 --- a/myframe/app.cpp +++ b/myframe/app.cpp @@ -306,9 +306,9 @@ int App::Send(std::shared_ptr msg) { return -1; } poller_->Add(conn); - auto ret = conn->Send(msg); + auto ret = conn->Send(std::move(msg)); poller_->Del(conn); - ev_conn_mgr_->Release(conn); + ev_conn_mgr_->Release(std::move(conn)); return ret; } @@ -320,9 +320,9 @@ const std::shared_ptr App::SendRequest( return nullptr; } poller_->Add(conn); - auto resp = conn->SendRequest(msg); + auto resp = conn->SendRequest(std::move(msg)); poller_->Del(conn); - ev_conn_mgr_->Release(conn); + ev_conn_mgr_->Release(std::move(conn)); return resp; } @@ -434,7 +434,7 @@ void App::DispatchMsg(std::list>* msg_list) { msg_list->size() > warning_msg_size_.load()) << " dispatch msg too many"; for (auto& msg : (*msg_list)) { - DispatchMsg(msg); + DispatchMsg(std::move(msg)); } msg_list->clear(); } @@ -444,7 +444,7 @@ void App::DispatchMsg(std::shared_ptr msg) { VLOG(1) << *msg; /// 处理框架消息 if (msg->GetDst() == MAIN_ADDR) { - ProcessMain(msg); + ProcessMain(std::move(msg)); return; } /// 消息分发 @@ -463,12 +463,14 @@ void App::DispatchMsg(std::shared_ptr msg) { actor_ctx_mgr_->DispatchMsg(msg); } else if (name_list[0] == "event") { if (name_list[1] == "conn") { + // dispatch to event conn auto handle = ev_mgr_->ToHandle(msg->GetDst()); ev_conn_mgr_->Notify(handle, msg); } else { LOG(ERROR) << "Unknown msg " << *msg; } } else if (!node_addr_.empty()) { + // dispatch to node if (node_addr_.substr(0, 5) == "actor") { actor_ctx_mgr_->DispatchMsg(msg, node_addr_); } else if (node_addr_.substr(0, 6) == "worker") { diff --git a/myframe/app.h b/myframe/app.h index 9ad1825..0deaa7e 100644 --- a/myframe/app.h +++ b/myframe/app.h @@ -136,7 +136,7 @@ class MYFRAME_EXPORT App final : public std::enable_shared_from_this { struct CacheMsg { CacheMsg(int c, std::shared_ptr m) : search_count(c) - , msg(m) {} + , msg(std::move(m)) {} int search_count{0}; std::shared_ptr msg{nullptr}; }; diff --git a/myframe/common.cpp b/myframe/common.cpp index 7418e26..cffaabe 100644 --- a/myframe/common.cpp +++ b/myframe/common.cpp @@ -113,7 +113,7 @@ std::vector Common::SplitMsgName(const std::string& name) { std::string item; std::stringstream ss(name); while (std::getline(ss, item, '.')) { - name_list.push_back(item); + name_list.push_back(std::move(item)); } return name_list; } diff --git a/myframe/event_conn.cpp b/myframe/event_conn.cpp index 9211cdd..445ca77 100644 --- a/myframe/event_conn.cpp +++ b/myframe/event_conn.cpp @@ -44,7 +44,7 @@ int EventConn::Send(std::shared_ptr msg) { if (msg->GetDst().empty()) { return -1; } - mailbox_.Send(msg); + mailbox_.Send(std::move(msg)); cmd_channel_->SendToMain(CmdChannel::Cmd::kRun); CmdChannel::Cmd cmd; return cmd_channel_->RecvFromMain(&cmd); @@ -60,7 +60,7 @@ const std::shared_ptr EventConn::SendRequest( if (req->GetDst().empty()) { return nullptr; } - mailbox_.Send(req); + mailbox_.Send(std::move(req)); cmd_channel_->SendToMain(CmdChannel::Cmd::kRunWithMsg); CmdChannel::Cmd cmd; cmd_channel_->RecvFromMain(&cmd); diff --git a/myframe/event_conn_manager.cpp b/myframe/event_conn_manager.cpp index 226f67c..91b3155 100644 --- a/myframe/event_conn_manager.cpp +++ b/myframe/event_conn_manager.cpp @@ -37,7 +37,7 @@ void EventConnManager::AddEventConn() { auto conn = std::make_shared(poller_); std::string name = "event.conn." + std::to_string(conn_sz_); conn->GetMailbox()->SetAddr(name); - idle_conn_.emplace_back(conn); + idle_conn_.push_back(std::move(conn)); conn_sz_++; } @@ -62,7 +62,7 @@ void EventConnManager::Release(std::shared_ptr ev) { ev_mgr_->Del(ev); // add to idle_conn std::lock_guard g(mtx_); - idle_conn_.emplace_back(ev); + idle_conn_.push_back(std::move(ev)); } // call by main frame @@ -80,7 +80,7 @@ void EventConnManager::Notify( return; } // push msg to event_conn - ev->GetMailbox()->Recv(msg); + ev->GetMailbox()->Recv(std::move(msg)); // send cmd to event_conn auto cmd_channel = ev->GetCmdChannel(); cmd_channel->SendToOwner(CmdChannel::Cmd::kIdle); diff --git a/myframe/event_manager.cpp b/myframe/event_manager.cpp index 57b7fb8..6db1bb9 100644 --- a/myframe/event_manager.cpp +++ b/myframe/event_manager.cpp @@ -52,7 +52,7 @@ std::vector> EventManager::Get( return tmp_evs; } -bool EventManager::Add(std::shared_ptr ev) { +bool EventManager::Add(const std::shared_ptr& ev) { auto handle = ev->GetHandle(); std::unique_lock lk(rw_); if (evs_.find(handle) != evs_.end()) { @@ -64,7 +64,7 @@ bool EventManager::Add(std::shared_ptr ev) { return true; } -bool EventManager::Del(std::shared_ptr ev) { +bool EventManager::Del(const std::shared_ptr& ev) { auto handle = ev->GetHandle(); std::unique_lock lk(rw_); if (evs_.find(handle) == evs_.end()) { diff --git a/myframe/event_manager.h b/myframe/event_manager.h index 2db37ed..91b0b62 100644 --- a/myframe/event_manager.h +++ b/myframe/event_manager.h @@ -54,8 +54,8 @@ class EventManager final { ev_handle_t ToHandle(const std::string&); private: - bool Add(std::shared_ptr); - bool Del(std::shared_ptr); + bool Add(const std::shared_ptr&); + bool Del(const std::shared_ptr&); std::shared_mutex rw_; std::unordered_map name_handle_map_; diff --git a/myframe/mailbox.cpp b/myframe/mailbox.cpp index d4fd842..69f39e8 100644 --- a/myframe/mailbox.cpp +++ b/myframe/mailbox.cpp @@ -30,7 +30,7 @@ void Mailbox::SendClear() { } void Mailbox::Send(std::shared_ptr msg) { - send_.emplace_back(msg); + send_.push_back(std::move(msg)); } void Mailbox::Send( @@ -38,7 +38,7 @@ void Mailbox::Send( std::shared_ptr msg) { msg->SetSrc(addr_); msg->SetDst(dst); - Send(msg); + Send(std::move(msg)); } void Mailbox::Send( @@ -46,7 +46,7 @@ void Mailbox::Send( const std::any& data) { auto msg = std::make_shared(); msg->SetAnyData(data); - Send(dst, msg); + Send(dst, std::move(msg)); } void Mailbox::Send(std::list>* msg_list) { @@ -70,7 +70,7 @@ void Mailbox::RecvClear() { } void Mailbox::Recv(std::shared_ptr msg) { - recv_.emplace_back(msg); + recv_.push_back(std::move(msg)); } void Mailbox::Recv(std::list>* msg_list) { diff --git a/myframe/worker_context.cpp b/myframe/worker_context.cpp index 4ef0b40..0871097 100644 --- a/myframe/worker_context.cpp +++ b/myframe/worker_context.cpp @@ -85,7 +85,7 @@ std::list>* WorkerContext::GetCache() { } void WorkerContext::Cache(std::shared_ptr msg) { - cache_.emplace_back(msg); + cache_.push_back(std::move(msg)); } void WorkerContext::Cache(std::list>* msg_list) { diff --git a/myframe/worker_context_manager.cpp b/myframe/worker_context_manager.cpp index 86a798e..c3f67ff 100644 --- a/myframe/worker_context_manager.cpp +++ b/myframe/worker_context_manager.cpp @@ -77,7 +77,7 @@ void WorkerContextManager::PopFrontIdleWorker() { void WorkerContextManager::PushBackIdleWorker( std::shared_ptr worker) { std::unique_lock lk(rw_); - idle_workers_ctx_.emplace_back(worker); + idle_workers_ctx_.push_back(std::move(worker)); } std::vector WorkerContextManager::GetAllUserWorkerAddr() { @@ -163,7 +163,7 @@ void WorkerContextManager::DispatchWorkerMsg( LOG(WARNING) << worker_name << " unsupport recv msg, drop it"; return; } - worker_ctx->Cache(msg); + worker_ctx->Cache(std::move(msg)); LOG_IF(WARNING, worker_ctx->CacheSize() > warning_msg_size_.load()) << *worker_ctx << " has " << worker_ctx->CacheSize() diff --git a/myframe/worker_timer.cpp b/myframe/worker_timer.cpp index 54c89e6..a8984fa 100644 --- a/myframe/worker_timer.cpp +++ b/myframe/worker_timer.cpp @@ -85,7 +85,7 @@ void TimerManager::_Dispath(List* cur) { msg->SetDesc(timer->timer_name_); msg->SetType("TIMER"); delete begin; - timeout_list_.emplace_back(msg); + timeout_list_.push_back(std::move(msg)); begin = temp; } } From 0dfd910c9deb59d702a6d4540773251ff41e60f9 Mon Sep 17 00:00:00 2001 From: likepeng Date: Thu, 6 Jun 2024 19:41:06 +0800 Subject: [PATCH 11/12] fix codestyle --- myframe/actor.cpp | 1 + myframe/actor_context_manager.cpp | 1 + myframe/app.h | 1 + myframe/common.cpp | 1 + myframe/event_conn.cpp | 2 +- myframe/event_conn_manager.cpp | 2 +- myframe/mailbox.cpp | 2 ++ myframe/worker_context.cpp | 1 + myframe/worker_context_manager.cpp | 2 ++ myframe/worker_timer.cpp | 1 + 10 files changed, 12 insertions(+), 2 deletions(-) diff --git a/myframe/actor.cpp b/myframe/actor.cpp index 93817e0..7b0aa31 100644 --- a/myframe/actor.cpp +++ b/myframe/actor.cpp @@ -6,6 +6,7 @@ Author: 李柯鹏 ****************************************************************************/ #include "myframe/actor.h" +#include #include "myframe/log.h" #include "myframe/app.h" diff --git a/myframe/actor_context_manager.cpp b/myframe/actor_context_manager.cpp index e99d09b..d9dca96 100644 --- a/myframe/actor_context_manager.cpp +++ b/myframe/actor_context_manager.cpp @@ -8,6 +8,7 @@ Author: 李柯鹏 #include "myframe/actor_context_manager.h" #include +#include #include "myframe/log.h" #include "myframe/msg.h" diff --git a/myframe/app.h b/myframe/app.h index 0deaa7e..73fe073 100644 --- a/myframe/app.h +++ b/myframe/app.h @@ -13,6 +13,7 @@ Author: 李柯鹏 #include #include #include +#include #include diff --git a/myframe/common.cpp b/myframe/common.cpp index cffaabe..96c7c5c 100644 --- a/myframe/common.cpp +++ b/myframe/common.cpp @@ -7,6 +7,7 @@ Author: 李柯鹏 #include "myframe/common.h" #include +#include #include "myframe/platform.h" #if defined(MYFRAME_OS_LINUX) || defined(MYFRAME_OS_ANDROID) diff --git a/myframe/event_conn.cpp b/myframe/event_conn.cpp index 445ca77..7fd8227 100644 --- a/myframe/event_conn.cpp +++ b/myframe/event_conn.cpp @@ -5,7 +5,7 @@ All rights reserved. Author: 李柯鹏 ****************************************************************************/ #include "myframe/event_conn.h" - +#include #include "myframe/log.h" #include "myframe/msg.h" diff --git a/myframe/event_conn_manager.cpp b/myframe/event_conn_manager.cpp index 91b3155..0487114 100644 --- a/myframe/event_conn_manager.cpp +++ b/myframe/event_conn_manager.cpp @@ -6,7 +6,7 @@ Author: 李柯鹏 ****************************************************************************/ #include "myframe/event_conn_manager.h" - +#include #include "myframe/log.h" #include "myframe/event_conn.h" #include "myframe/event_manager.h" diff --git a/myframe/mailbox.cpp b/myframe/mailbox.cpp index 69f39e8..a55d6ee 100644 --- a/myframe/mailbox.cpp +++ b/myframe/mailbox.cpp @@ -5,6 +5,8 @@ All rights reserved. Author: 李柯鹏 ****************************************************************************/ #include "myframe/mailbox.h" +#include + #include "myframe/msg.h" namespace myframe { diff --git a/myframe/worker_context.cpp b/myframe/worker_context.cpp index 0871097..074d3ee 100644 --- a/myframe/worker_context.cpp +++ b/myframe/worker_context.cpp @@ -7,6 +7,7 @@ Author: 李柯鹏 #include "myframe/worker_context.h" #include +#include #include "myframe/log.h" #include "myframe/msg.h" diff --git a/myframe/worker_context_manager.cpp b/myframe/worker_context_manager.cpp index c3f67ff..4ffd5f8 100644 --- a/myframe/worker_context_manager.cpp +++ b/myframe/worker_context_manager.cpp @@ -7,6 +7,8 @@ Author: 李柯鹏 #include "myframe/worker_context_manager.h" +#include + #include "myframe/log.h" #include "myframe/msg.h" #include "myframe/worker.h" diff --git a/myframe/worker_timer.cpp b/myframe/worker_timer.cpp index a8984fa..1f420a9 100644 --- a/myframe/worker_timer.cpp +++ b/myframe/worker_timer.cpp @@ -9,6 +9,7 @@ Author: 李柯鹏 #include #include +#include #include "myframe/log.h" #include "myframe/actor.h" From 00109d968f4af257ee0a45cb3f538918c9aebcca Mon Sep 17 00:00:00 2001 From: likepeng Date: Fri, 7 Jun 2024 16:18:03 +0800 Subject: [PATCH 12/12] update version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c75767d..f9576bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10) if (POLICY CMP0091) cmake_policy(SET CMP0091 NEW) endif() -project(myframe VERSION 0.9.2) +project(myframe VERSION 0.9.3) ### option option(MYFRAME_USE_CV "Using conditional variables for thread communication" ON)