From 06451b44a2b43324a2f51cbeb91721dd8b62801a Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 25 Mar 2024 17:23:48 +0800 Subject: [PATCH] feat delete old futures --- CMakeLists.txt | 149 +++++++++++++++---------------- include/sled/futures/base_cell.h | 15 ---- include/sled/futures/future.h | 51 ----------- include/sled/futures/just.h | 28 ------ include/sled/futures/then.h | 40 --------- src/futures/future_test.cc | 8 -- 6 files changed, 74 insertions(+), 217 deletions(-) delete mode 100644 include/sled/futures/base_cell.h delete mode 100644 include/sled/futures/future.h delete mode 100644 include/sled/futures/just.h delete mode 100644 include/sled/futures/then.h delete mode 100644 src/futures/future_test.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 7923d31..d8bfb40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.10) -project(sled VERSION 0.1.0 LANGUAGES C CXX) +project( + sled + VERSION 0.1.0 + LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -19,31 +22,28 @@ add_library(sled STATIC "") add_subdirectory(3party/gperftools EXCLUDE_FROM_ALL) # add_subdirectory(3party/cppuprofile EXCLUDE_FROM_ALL) add_subdirectory(3party/protobuf-3.21.12 EXCLUDE_FROM_ALL) -if (NOT TARGET marl) - add_subdirectory(3party/marl EXCLUDE_FROM_ALL) +if(NOT TARGET marl) + add_subdirectory(3party/marl EXCLUDE_FROM_ALL) endif() -if (NOT TARGET rpc_core) - add_subdirectory(3party/rpc_core EXCLUDE_FROM_ALL) +if(NOT TARGET rpc_core) + add_subdirectory(3party/rpc_core EXCLUDE_FROM_ALL) endif() -if (NOT TARGET fmt) - add_subdirectory(3party/fmt EXCLUDE_FROM_ALL) +if(NOT TARGET fmt) + add_subdirectory(3party/fmt EXCLUDE_FROM_ALL) endif() -if (SLED_LOCATION_PATH) - target_compile_definitions(sled PRIVATE __SLED_LOCATION_PATH="${SLED_LOCATION_PATH}") +if(SLED_LOCATION_PATH) + target_compile_definitions( + sled PRIVATE __SLED_LOCATION_PATH="${SLED_LOCATION_PATH}") endif() # add_subdirectory(3party/eigen EXCLUDE_FROM_ALL) -target_include_directories(sled PUBLIC - include - 3party/eigen - 3party/inja - 3party/rxcpp) +target_include_directories(sled PUBLIC include 3party/eigen 3party/inja + 3party/rxcpp) target_sources( sled - PRIVATE - src/filesystem/path.cc + PRIVATE src/filesystem/path.cc src/log/log.cc src/network/async_resolver.cc src/network/ip_address.cc @@ -51,7 +51,7 @@ target_sources( src/network/physical_socket_server.cc src/network/socket_address.cc src/network/socket_server.cc - src/profiling/profiling.cc + src/profiling/profiling.cc src/strings/base64.cc src/strings/utils.cc src/synchronization/event.cc @@ -59,7 +59,7 @@ target_sources( src/synchronization/sequence_checker.cc src/synchronization/thread_local.cc src/system/location.cc - src/system/pid.cc + src/system/pid.cc src/system/thread.cc src/system/thread_pool.cc src/task_queue/pending_task_safety_flag.cc @@ -74,81 +74,80 @@ target_sources( src/status.cc src/system_time.cc src/time_utils.cc - src/uri.cc -) + src/uri.cc) # set(BUILD_RTTR_DYNAMIC OFF) set(BUILD_UNIT_TESTS OFF) # set(BUILD_WITH_STATIC_RUNTIME_LIBS ON) set(BUILD_WITH_DOCUMENTATION OFF) # add_subdirectory(3party/rttr EXCLUDE_FROM_ALL) include(CheckCCompilerFlag) check_c_compiler_flag("-Wl,--whole-archive" SUPPORT_COMPILE_WHOLE_ARCHIVE) -if (SUPPORT_COMPILE_WHOLE_ARCHIVE) - set(WHOLE_ARCHIVE_WRAPPER_START "-Wl,--whole-archive") - set(WHOLE_ARCHIVE_WRAPPER_END "-Wl,--no-whole-archive") +if(SUPPORT_COMPILE_WHOLE_ARCHIVE) + set(WHOLE_ARCHIVE_WRAPPER_START "-Wl,--whole-archive") + set(WHOLE_ARCHIVE_WRAPPER_END "-Wl,--no-whole-archive") endif() - -target_link_libraries(sled - PUBLIC rpc_core fmt marl protobuf::libprotobuf # cppuprofile - # ${WHOLE_ARCHIVE_WRAPPER_START} - tcmalloc_and_profiler_static - # ${WHOLE_ARCHIVE_WRAPPER_END} +target_link_libraries( + sled + PUBLIC rpc_core fmt marl protobuf::libprotobuf # cppuprofile + # ${WHOLE_ARCHIVE_WRAPPER_START} + tcmalloc_and_profiler_static + # ${WHOLE_ARCHIVE_WRAPPER_END} ) -## set fPIC +# set fPIC set_target_properties(sled PROPERTIES POSITION_INDEPENDENT_CODE ON) if(SLED_BUILD_BENCHMARK) - if (NOT TARGET benchmark) - find_package(benchmark REQUIRED) - endif() + if(NOT TARGET benchmark) + find_package(benchmark REQUIRED) + endif() - add_executable(sled_benchmark - src/random_bench.cc - src/strings/base64_bench.cc - src/system/fiber/fiber_bench.cc - src/system/thread_pool_bench.cc - src/system_time_bench.cc) - target_link_libraries(sled_benchmark PRIVATE sled benchmark::benchmark + add_executable( + sled_benchmark + src/random_bench.cc src/strings/base64_bench.cc + src/system/fiber/fiber_bench.cc src/system/thread_pool_bench.cc + src/system_time_bench.cc) + target_link_libraries(sled_benchmark PRIVATE sled benchmark::benchmark benchmark::benchmark_main) endif(SLED_BUILD_BENCHMARK) if(SLED_BUILD_TESTS) - include(FetchContent) - FetchContent_Declare( - googletest - URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip - ) - FetchContent_MakeAvailable(googletest) - add_executable(sled_tests - # src/exec/just_test.cc - src/any_test.cc - src/filesystem/path_test.cc - src/futures/future_test.cc - src/futures/promise_test.cc - src/log/fmt_test.cc - # src/profiling/profiling_test.cc - src/strings/base64_test.cc - src/synchronization/sequence_checker_test.cc - src/cleanup_test.cc - src/status_test.cc - src/status_or_test.cc - src/system/fiber/fiber_test.cc - src/system/thread_pool_test.cc - src/rx_test.cc - src/uri_test.cc - ) - target_link_libraries(sled_tests PRIVATE sled GTest::gtest GTest::gtest_main) - add_test(NAME sled_tests COMMAND sled_tests) + include(FetchContent) + FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip + ) + FetchContent_MakeAvailable(googletest) + add_executable( + sled_tests + # src/exec/just_test.cc + src/any_test.cc + src/filesystem/path_test.cc + src/futures/promise_test.cc + src/log/fmt_test.cc + # src/profiling/profiling_test.cc + src/strings/base64_test.cc + src/synchronization/sequence_checker_test.cc + src/cleanup_test.cc + src/status_test.cc + src/status_or_test.cc + src/system/fiber/fiber_test.cc + src/system/thread_pool_test.cc + src/rx_test.cc + src/uri_test.cc) + target_link_libraries(sled_tests PRIVATE sled GTest::gtest GTest::gtest_main) + add_test(NAME sled_tests COMMAND sled_tests) endif(SLED_BUILD_TESTS) -if (SLED_BUILD_FUZZ) +if(SLED_BUILD_FUZZ) -macro(add_fuzz_test name sources) - add_executable(${name} ${sources}) - target_link_libraries(${name} PRIVATE sled) - target_compile_options(${name} PRIVATE -g -O1 -fsanitize=fuzzer,address -fsanitize-coverage=trace-cmp) - target_link_options(${name} PRIVATE -fsanitize=fuzzer,address -fsanitize-coverage=trace-cmp) -endmacro() + macro(add_fuzz_test name sources) + add_executable(${name} ${sources}) + target_link_libraries(${name} PRIVATE sled) + target_compile_options(${name} PRIVATE -g -O1 -fsanitize=fuzzer,address + -fsanitize-coverage=trace-cmp) + target_link_options(${name} PRIVATE -fsanitize=fuzzer,address + -fsanitize-coverage=trace-cmp) + endmacro() -add_fuzz_test(base64_fuzz src/strings/base64_fuzz.cc) -endif (SLED_BUILD_FUZZ) + add_fuzz_test(base64_fuzz src/strings/base64_fuzz.cc) +endif(SLED_BUILD_FUZZ) diff --git a/include/sled/futures/base_cell.h b/include/sled/futures/base_cell.h deleted file mode 100644 index e13fee0..0000000 --- a/include/sled/futures/base_cell.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef SLED_FUTURES_BASE_CELL_H -#define SLED_FUTURES_BASE_CELL_H -#include -#pragma once - -namespace sled { -namespace futures { - -struct BaseCell { - void *scheduler; -}; -}// namespace futures - -}// namespace sled -#endif// SLED_FUTURES_BASE_CELL_H diff --git a/include/sled/futures/future.h b/include/sled/futures/future.h deleted file mode 100644 index 8d06c56..0000000 --- a/include/sled/futures/future.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef SLED_FUTURES_FUTHRE_H -#define SLED_FUTURES_FUTHRE_H - -#include "sled/any.h" -#include "sled/exec/detail/invoke_result.h" -#include "sled/optional.h" -#include "sled/synchronization/mutex.h" -#include -#include - -namespace sled { - -template -class Future; -template -class Promise; - -template -struct FPState : std::enable_shared_from_this> { - sled::Mutex lock; - sled::optional data; - std::exception_ptr err; - bool done; - sled::any priv; -}; - -template -class Future { -public: - using result_t = T; - - Future(std::shared_ptr> state) : state_(state) {} - -private: - std::shared_ptr> state_; -}; - -template -class Promise { -public: - using result_t = T; - - void SetValue(T &&value) {} - - void SetError(std::exception_ptr err) {} - - Future GetFuture() {} -}; - -}// namespace sled -#endif// SLED_FUTURES_FUTHRE_H diff --git a/include/sled/futures/just.h b/include/sled/futures/just.h deleted file mode 100644 index 6265c33..0000000 --- a/include/sled/futures/just.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef SLED_FUTURES_JUST_H -#define SLED_FUTURES_JUST_H -#include -#pragma once - -namespace sled { -namespace futures { -template -struct JustCell { - T value; - - template - void Start(R receiver) - { - receiver.SetValue(value); - } -}; - -template -JustCell -Just(T &&t) -{ - return {std::forward(t)}; -} - -}// namespace futures -}// namespace sled -#endif// SLED_FUTURES_JUST_H diff --git a/include/sled/futures/then.h b/include/sled/futures/then.h deleted file mode 100644 index a709054..0000000 --- a/include/sled/futures/then.h +++ /dev/null @@ -1,40 +0,0 @@ - -#ifndef SLED_FUTURES_THEN_H -#define SLED_FUTURES_THEN_H -#include -#include -#pragma once - -namespace sled { -namespace futures { - -template -struct ThenCell { - S sender; - F func; - - // T value; - - template - void Start(R receiver) - { - sender.Start(); - } - - template - void SetValue(U &&value) - {} - - void SetError(std::exception_ptr err) {} -}; - -template -ThenCell -Then(S sender, F &&func) -{ - return {std::forward(sender), std::forward(func)}; -} - -}// namespace futures -}// namespace sled -#endif// SLED_FUTURES_THEN_H diff --git a/src/futures/future_test.cc b/src/futures/future_test.cc deleted file mode 100644 index bf568cb..0000000 --- a/src/futures/future_test.cc +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include - -TEST(Future, basic) -{ - // sled::Future x; - // auto res = x.Then([](int) {}); -}