feat delete old futures
This commit is contained in:
parent
1396a20daf
commit
06451b44a2
@ -1,5 +1,8 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
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 11)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
@ -32,18 +35,15 @@ if (NOT TARGET fmt)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(SLED_LOCATION_PATH)
|
if(SLED_LOCATION_PATH)
|
||||||
target_compile_definitions(sled PRIVATE __SLED_LOCATION_PATH="${SLED_LOCATION_PATH}")
|
target_compile_definitions(
|
||||||
|
sled PRIVATE __SLED_LOCATION_PATH="${SLED_LOCATION_PATH}")
|
||||||
endif()
|
endif()
|
||||||
# add_subdirectory(3party/eigen EXCLUDE_FROM_ALL)
|
# add_subdirectory(3party/eigen EXCLUDE_FROM_ALL)
|
||||||
target_include_directories(sled PUBLIC
|
target_include_directories(sled PUBLIC include 3party/eigen 3party/inja
|
||||||
include
|
|
||||||
3party/eigen
|
|
||||||
3party/inja
|
|
||||||
3party/rxcpp)
|
3party/rxcpp)
|
||||||
target_sources(
|
target_sources(
|
||||||
sled
|
sled
|
||||||
PRIVATE
|
PRIVATE src/filesystem/path.cc
|
||||||
src/filesystem/path.cc
|
|
||||||
src/log/log.cc
|
src/log/log.cc
|
||||||
src/network/async_resolver.cc
|
src/network/async_resolver.cc
|
||||||
src/network/ip_address.cc
|
src/network/ip_address.cc
|
||||||
@ -74,8 +74,7 @@ target_sources(
|
|||||||
src/status.cc
|
src/status.cc
|
||||||
src/system_time.cc
|
src/system_time.cc
|
||||||
src/time_utils.cc
|
src/time_utils.cc
|
||||||
src/uri.cc
|
src/uri.cc)
|
||||||
)
|
|
||||||
# set(BUILD_RTTR_DYNAMIC OFF) set(BUILD_UNIT_TESTS OFF)
|
# set(BUILD_RTTR_DYNAMIC OFF) set(BUILD_UNIT_TESTS OFF)
|
||||||
# set(BUILD_WITH_STATIC_RUNTIME_LIBS ON) set(BUILD_WITH_DOCUMENTATION OFF)
|
# set(BUILD_WITH_STATIC_RUNTIME_LIBS ON) set(BUILD_WITH_DOCUMENTATION OFF)
|
||||||
# add_subdirectory(3party/rttr EXCLUDE_FROM_ALL)
|
# add_subdirectory(3party/rttr EXCLUDE_FROM_ALL)
|
||||||
@ -86,15 +85,15 @@ if (SUPPORT_COMPILE_WHOLE_ARCHIVE)
|
|||||||
set(WHOLE_ARCHIVE_WRAPPER_END "-Wl,--no-whole-archive")
|
set(WHOLE_ARCHIVE_WRAPPER_END "-Wl,--no-whole-archive")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
target_link_libraries(
|
||||||
target_link_libraries(sled
|
sled
|
||||||
PUBLIC rpc_core fmt marl protobuf::libprotobuf # cppuprofile
|
PUBLIC rpc_core fmt marl protobuf::libprotobuf # cppuprofile
|
||||||
# ${WHOLE_ARCHIVE_WRAPPER_START}
|
# ${WHOLE_ARCHIVE_WRAPPER_START}
|
||||||
tcmalloc_and_profiler_static
|
tcmalloc_and_profiler_static
|
||||||
# ${WHOLE_ARCHIVE_WRAPPER_END}
|
# ${WHOLE_ARCHIVE_WRAPPER_END}
|
||||||
)
|
)
|
||||||
|
|
||||||
## set fPIC
|
# set fPIC
|
||||||
set_target_properties(sled PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
set_target_properties(sled PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||||
|
|
||||||
if(SLED_BUILD_BENCHMARK)
|
if(SLED_BUILD_BENCHMARK)
|
||||||
@ -102,11 +101,10 @@ if(SLED_BUILD_BENCHMARK)
|
|||||||
find_package(benchmark REQUIRED)
|
find_package(benchmark REQUIRED)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(sled_benchmark
|
add_executable(
|
||||||
src/random_bench.cc
|
sled_benchmark
|
||||||
src/strings/base64_bench.cc
|
src/random_bench.cc src/strings/base64_bench.cc
|
||||||
src/system/fiber/fiber_bench.cc
|
src/system/fiber/fiber_bench.cc src/system/thread_pool_bench.cc
|
||||||
src/system/thread_pool_bench.cc
|
|
||||||
src/system_time_bench.cc)
|
src/system_time_bench.cc)
|
||||||
target_link_libraries(sled_benchmark PRIVATE sled benchmark::benchmark
|
target_link_libraries(sled_benchmark PRIVATE sled benchmark::benchmark
|
||||||
benchmark::benchmark_main)
|
benchmark::benchmark_main)
|
||||||
@ -119,11 +117,11 @@ if(SLED_BUILD_TESTS)
|
|||||||
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
|
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(googletest)
|
FetchContent_MakeAvailable(googletest)
|
||||||
add_executable(sled_tests
|
add_executable(
|
||||||
|
sled_tests
|
||||||
# src/exec/just_test.cc
|
# src/exec/just_test.cc
|
||||||
src/any_test.cc
|
src/any_test.cc
|
||||||
src/filesystem/path_test.cc
|
src/filesystem/path_test.cc
|
||||||
src/futures/future_test.cc
|
|
||||||
src/futures/promise_test.cc
|
src/futures/promise_test.cc
|
||||||
src/log/fmt_test.cc
|
src/log/fmt_test.cc
|
||||||
# src/profiling/profiling_test.cc
|
# src/profiling/profiling_test.cc
|
||||||
@ -135,8 +133,7 @@ if(SLED_BUILD_TESTS)
|
|||||||
src/system/fiber/fiber_test.cc
|
src/system/fiber/fiber_test.cc
|
||||||
src/system/thread_pool_test.cc
|
src/system/thread_pool_test.cc
|
||||||
src/rx_test.cc
|
src/rx_test.cc
|
||||||
src/uri_test.cc
|
src/uri_test.cc)
|
||||||
)
|
|
||||||
target_link_libraries(sled_tests PRIVATE sled GTest::gtest GTest::gtest_main)
|
target_link_libraries(sled_tests PRIVATE sled GTest::gtest GTest::gtest_main)
|
||||||
add_test(NAME sled_tests COMMAND sled_tests)
|
add_test(NAME sled_tests COMMAND sled_tests)
|
||||||
endif(SLED_BUILD_TESTS)
|
endif(SLED_BUILD_TESTS)
|
||||||
@ -146,8 +143,10 @@ if (SLED_BUILD_FUZZ)
|
|||||||
macro(add_fuzz_test name sources)
|
macro(add_fuzz_test name sources)
|
||||||
add_executable(${name} ${sources})
|
add_executable(${name} ${sources})
|
||||||
target_link_libraries(${name} PRIVATE sled)
|
target_link_libraries(${name} PRIVATE sled)
|
||||||
target_compile_options(${name} PRIVATE -g -O1 -fsanitize=fuzzer,address -fsanitize-coverage=trace-cmp)
|
target_compile_options(${name} PRIVATE -g -O1 -fsanitize=fuzzer,address
|
||||||
target_link_options(${name} PRIVATE -fsanitize=fuzzer,address -fsanitize-coverage=trace-cmp)
|
-fsanitize-coverage=trace-cmp)
|
||||||
|
target_link_options(${name} PRIVATE -fsanitize=fuzzer,address
|
||||||
|
-fsanitize-coverage=trace-cmp)
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
add_fuzz_test(base64_fuzz src/strings/base64_fuzz.cc)
|
add_fuzz_test(base64_fuzz src/strings/base64_fuzz.cc)
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
#ifndef SLED_FUTURES_BASE_CELL_H
|
|
||||||
#define SLED_FUTURES_BASE_CELL_H
|
|
||||||
#include <functional>
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace sled {
|
|
||||||
namespace futures {
|
|
||||||
|
|
||||||
struct BaseCell {
|
|
||||||
void *scheduler;
|
|
||||||
};
|
|
||||||
}// namespace futures
|
|
||||||
|
|
||||||
}// namespace sled
|
|
||||||
#endif// SLED_FUTURES_BASE_CELL_H
|
|
@ -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 <exception>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace sled {
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class Future;
|
|
||||||
template<typename T>
|
|
||||||
class Promise;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct FPState : std::enable_shared_from_this<FPState<T>> {
|
|
||||||
sled::Mutex lock;
|
|
||||||
sled::optional<T> data;
|
|
||||||
std::exception_ptr err;
|
|
||||||
bool done;
|
|
||||||
sled::any priv;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class Future {
|
|
||||||
public:
|
|
||||||
using result_t = T;
|
|
||||||
|
|
||||||
Future(std::shared_ptr<FPState<T>> state) : state_(state) {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::shared_ptr<FPState<T>> state_;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class Promise {
|
|
||||||
public:
|
|
||||||
using result_t = T;
|
|
||||||
|
|
||||||
void SetValue(T &&value) {}
|
|
||||||
|
|
||||||
void SetError(std::exception_ptr err) {}
|
|
||||||
|
|
||||||
Future<T> GetFuture() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
}// namespace sled
|
|
||||||
#endif// SLED_FUTURES_FUTHRE_H
|
|
@ -1,28 +0,0 @@
|
|||||||
#ifndef SLED_FUTURES_JUST_H
|
|
||||||
#define SLED_FUTURES_JUST_H
|
|
||||||
#include <utility>
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace sled {
|
|
||||||
namespace futures {
|
|
||||||
template<typename T>
|
|
||||||
struct JustCell {
|
|
||||||
T value;
|
|
||||||
|
|
||||||
template<typename R>
|
|
||||||
void Start(R receiver)
|
|
||||||
{
|
|
||||||
receiver.SetValue(value);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
JustCell<T>
|
|
||||||
Just(T &&t)
|
|
||||||
{
|
|
||||||
return {std::forward<T>(t)};
|
|
||||||
}
|
|
||||||
|
|
||||||
}// namespace futures
|
|
||||||
}// namespace sled
|
|
||||||
#endif// SLED_FUTURES_JUST_H
|
|
@ -1,40 +0,0 @@
|
|||||||
|
|
||||||
#ifndef SLED_FUTURES_THEN_H
|
|
||||||
#define SLED_FUTURES_THEN_H
|
|
||||||
#include <exception>
|
|
||||||
#include <utility>
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace sled {
|
|
||||||
namespace futures {
|
|
||||||
|
|
||||||
template<typename S, typename F>
|
|
||||||
struct ThenCell {
|
|
||||||
S sender;
|
|
||||||
F func;
|
|
||||||
|
|
||||||
// T value;
|
|
||||||
|
|
||||||
template<typename R>
|
|
||||||
void Start(R receiver)
|
|
||||||
{
|
|
||||||
sender.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename U>
|
|
||||||
void SetValue(U &&value)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void SetError(std::exception_ptr err) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename S, typename F>
|
|
||||||
ThenCell<S, F>
|
|
||||||
Then(S sender, F &&func)
|
|
||||||
{
|
|
||||||
return {std::forward<S>(sender), std::forward<F>(func)};
|
|
||||||
}
|
|
||||||
|
|
||||||
}// namespace futures
|
|
||||||
}// namespace sled
|
|
||||||
#endif// SLED_FUTURES_THEN_H
|
|
@ -1,8 +0,0 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
#include <sled/futures/future.h>
|
|
||||||
|
|
||||||
TEST(Future, basic)
|
|
||||||
{
|
|
||||||
// sled::Future<int> x;
|
|
||||||
// auto res = x.Then([](int) {});
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user