Skip to content

Commit

Permalink
Refactor boost support to proper event loop, removing need for locks …
Browse files Browse the repository at this point in the history
…and threads
  • Loading branch information
Oipo committed Jan 4, 2025
1 parent 1aa3656 commit 31624d9
Show file tree
Hide file tree
Showing 41 changed files with 767 additions and 741 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake-internal-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ jobs:

- name: Examples
working-directory: ${{github.workspace}}/bin
run: ../bin/ichor_etcd_example && ../bin/ichor_http_example && ../bin/ichor_multithreaded_example && ../bin/ichor_optional_dependency_example && ../bin/ichor_serializer_example && ../bin/ichor_tcp_example && ../bin/ichor_timer_example && ../bin/ichor_factory_example && ../bin/ichor_websocket_example && ../bin/ichor_websocket_example -t4 && ../bin/ichor_yielding_timer_example && ../bin/ichor_event_statistics_example && ../bin/ichor_introspection_example && ../bin/ichor_coroutine_benchmark && ../bin/ichor_event_benchmark && ../bin/ichor_serializer_benchmark && ../bin/ichor_start_benchmark && ../bin/ichor_start_stop_benchmark && ../bin/ichor_utils_benchmark -r
run: ../bin/ichor_etcd_example && ../bin/ichor_http_example_boost && ../bin/ichor_http_example_uring && ../bin/ichor_multithreaded_example && ../bin/ichor_multithreaded_example_uring && ../bin/ichor_optional_dependency_example && ../bin/ichor_serializer_example && ../bin/ichor_tcp_example && ../bin/ichor_tcp_example_uring && ../bin/ichor_timer_example && ../bin/ichor_yielding_timer_example && ../bin/ichor_timer_example_uring && ../bin/ichor_yielding_timer_example_uring && ../bin/ichor_factory_example && ../bin/ichor_websocket_example && ../bin/ichor_event_statistics_example && ../bin/ichor_introspection_example && ../bin/ichor_coroutine_benchmark && ../bin/ichor_event_benchmark && ../bin/ichor_serializer_benchmark && ../bin/ichor_start_benchmark && ../bin/ichor_start_stop_benchmark && ../bin/ichor_utils_benchmark -r

14 changes: 10 additions & 4 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
if: ${{matrix.sanitizer == 'asan'}}
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -GNinja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.opts}} -DICHOR_USE_SPDLOG=${{matrix.spdlog}} -DICHOR_USE_BOOST_BEAST=ON -DICHOR_USE_SDEVENT=ON -DICHOR_USE_SANITIZERS=ON -DICHOR_USE_MOLD=ON -DICHOR_USE_LIBCPP=OFF -DICHOR_USE_LIBURING=ON
run: cmake -GNinja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.opts}} -DICHOR_USE_SPDLOG=${{matrix.spdlog}} -DICHOR_USE_BOOST_BEAST=OFF -DICHOR_USE_SDEVENT=ON -DICHOR_USE_SANITIZERS=ON -DICHOR_USE_MOLD=ON -DICHOR_USE_LIBCPP=OFF -DICHOR_USE_LIBURING=ON

- name: "Configure CMake (spdlog:${{matrix.spdlog}}, no asan)"
if: ${{matrix.sanitizer == 'none'}}
Expand All @@ -53,7 +53,7 @@ jobs:
if: ${{matrix.sanitizer == 'tsan'}}
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -GNinja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.opts}} -DICHOR_USE_SPDLOG=${{matrix.spdlog}} -DICHOR_USE_BOOST_BEAST=ON -DICHOR_USE_SDEVENT=ON -DICHOR_USE_SANITIZERS=OFF -DICHOR_USE_THREAD_SANITIZER=ON -DICHOR_USE_MOLD=ON -DICHOR_USE_LIBCPP=OFF -DICHOR_USE_LIBURING=ON
run: cmake -GNinja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.opts}} -DICHOR_USE_SPDLOG=${{matrix.spdlog}} -DICHOR_USE_BOOST_BEAST=OFF -DICHOR_USE_SDEVENT=ON -DICHOR_USE_SANITIZERS=OFF -DICHOR_USE_THREAD_SANITIZER=ON -DICHOR_USE_MOLD=ON -DICHOR_USE_LIBCPP=OFF -DICHOR_USE_LIBURING=ON

- name: Build
# Build your program with the given configuration
Expand All @@ -65,7 +65,13 @@ jobs:
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --output-on-failure -C ${{env.BUILD_TYPE}}

- name: Examples
- name: Examples no san
if: ${{matrix.sanitizer == 'none'}}
working-directory: ${{github.workspace}}/bin
run: ../bin/ichor_etcd_example && ../bin/ichor_http_example_boost && ../bin/ichor_http_example_uring && ../bin/ichor_multithreaded_example && ../bin/ichor_multithreaded_example_uring && ../bin/ichor_optional_dependency_example && ../bin/ichor_serializer_example && ../bin/ichor_tcp_example && ../bin/ichor_tcp_example_uring && ../bin/ichor_timer_example && ../bin/ichor_yielding_timer_example && ../bin/ichor_timer_example_uring && ../bin/ichor_yielding_timer_example_uring && ../bin/ichor_factory_example && ../bin/ichor_websocket_example && ../bin/ichor_event_statistics_example && ../bin/ichor_introspection_example

- name: Examples san
if: ${{matrix.sanitizer != 'none'}}
working-directory: ${{github.workspace}}/bin
run: ../bin/ichor_etcd_example && ../bin/ichor_http_example && ../bin/ichor_multithreaded_example && ../bin/ichor_optional_dependency_example && ../bin/ichor_serializer_example && ../bin/ichor_tcp_example && ../bin/ichor_timer_example && ../bin/ichor_factory_example && ../bin/ichor_websocket_example && ../bin/ichor_websocket_example -t4 && ../bin/ichor_yielding_timer_example && ../bin/ichor_event_statistics_example && ../bin/ichor_introspection_example
run: ../bin/ichor_http_example_uring && ../bin/ichor_multithreaded_example && ../bin/ichor_multithreaded_example_uring && ../bin/ichor_optional_dependency_example && ../bin/ichor_serializer_example && ../bin/ichor_tcp_example && ../bin/ichor_tcp_example_uring && ../bin/ichor_timer_example && ../bin/ichor_yielding_timer_example && ../bin/ichor_timer_example_uring && ../bin/ichor_yielding_timer_example_uring && ../bin/ichor_factory_example && ../bin/ichor_event_statistics_example && ../bin/ichor_introspection_example

2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: Examples
working-directory: ${{github.workspace}}/bin
run: ../bin/ichor_etcd_example && ../bin/ichor_http_example && ../bin/ichor_multithreaded_example && ../bin/ichor_optional_dependency_example && ../bin/ichor_serializer_example && ../bin/ichor_tcp_example && ../bin/ichor_timer_example && ../bin/ichor_factory_example && ../bin/ichor_websocket_example && ../bin/ichor_yielding_timer_example && ../bin/ichor_event_statistics_example && ../bin/ichor_introspection_example && ../bin/ichor_coroutine_benchmark && ../bin/ichor_event_benchmark && ../bin/ichor_serializer_benchmark && ../bin/ichor_start_benchmark && ../bin/ichor_start_stop_benchmark && ../bin/ichor_utils_benchmark -r
run: ../bin/ichor_etcd_example && ../bin/ichor_http_example_boost && ../bin/ichor_http_example_uring && ../bin/ichor_multithreaded_example && ../bin/ichor_multithreaded_example_uring && ../bin/ichor_optional_dependency_example && ../bin/ichor_serializer_example && ../bin/ichor_tcp_example && ../bin/ichor_tcp_example_uring && ../bin/ichor_timer_example && ../bin/ichor_yielding_timer_example && ../bin/ichor_timer_example_uring && ../bin/ichor_yielding_timer_example_uring && ../bin/ichor_factory_example && ../bin/ichor_websocket_example && ../bin/ichor_event_statistics_example && ../bin/ichor_introspection_example && ../bin/ichor_coroutine_benchmark && ../bin/ichor_event_benchmark && ../bin/ichor_serializer_benchmark && ../bin/ichor_start_benchmark && ../bin/ichor_start_stop_benchmark && ../bin/ichor_utils_benchmark -r

- name: coverage
run: lcov --directory . --capture --output-file coverage.info && lcov --remove coverage.info '/usr/*' '/opt/*' '${{github.workspace}}/external/*' --output-file coverage.info && lcov --list coverage.info && codecov -f coverage.info
Expand Down
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ option(ICHOR_ENABLE_INTERNAL_IO_DEBUGGING "Add verbose logging of Ichor I/O inte
option(ICHOR_ENABLE_INTERNAL_STL_DEBUGGING "Add verbose logging of Ichor STL" OFF)
option(ICHOR_BUILD_COVERAGE "Build ichor with coverage" OFF)
option(ICHOR_USE_SPDLOG "Use spdlog as framework logging implementation" OFF)
option(ICHOR_USE_BOOST_BEAST "Add boost asio and boost BEAST as dependencies" OFF)
cmake_dependent_option(ICHOR_USE_SANITIZERS "Enable sanitizers, catching potential errors but slowing down compilation and execution speed" $ICHOR_BUILDING_DEBUG "NOT ICHOR_MUSL" OFF)
cmake_dependent_option(ICHOR_USE_THREAD_SANITIZER "Enable thread sanitizer, catching potential threading errors but slowing down compilation and execution speed. Cannot be combined with ICHOR_USE_SANITIZERS" OFF "NOT WIN32" OFF)
cmake_dependent_option(ICHOR_USE_BOOST_BEAST "Add boost asio and boost BEAST as dependencies" OFF "NOT ICHOR_USE_SANITIZERS AND NOT ICHOR_USE_THREAD_SANITIZER" OFF)
option(ICHOR_USE_UGLY_HACK_EXCEPTION_CATCHING "Enable an ugly hack on gcc to enable debugging the point where exceptions are thrown. Useful for debugging boost asio/beast backtraces." OFF)
option(ICHOR_REMOVE_SOURCE_NAMES "Remove compiling source file names and line numbers when logging." $ICHOR_BUILDING_DEBUG)
cmake_dependent_option(ICHOR_USE_MOLD "Use mold when linking, recommended to use with gcc 12+ or clang" OFF "NOT WIN32" OFF)
Expand Down Expand Up @@ -112,7 +112,8 @@ if(ICHOR_COMPILER_ID STREQUAL "clang" AND ICHOR_RUN_CLANG_TIDY)
endif()

set(FMT_SOURCES ${ICHOR_EXTERNAL_DIR}/fmt/src/format.cc ${ICHOR_EXTERNAL_DIR}/fmt/src/os.cc)
file(GLOB_RECURSE ICHOR_FRAMEWORK_SOURCES ${ICHOR_TOP_DIR}/src/ichor/*.cpp)
file(GLOB_RECURSE ICHOR_FRAMEWORK_SOURCES ${ICHOR_TOP_DIR}/src/ichor/coroutines/*.cpp ${ICHOR_TOP_DIR}/src/ichor/dependency_management/*.cpp ${ICHOR_TOP_DIR}/src/ichor/DependencyManager.cpp ${ICHOR_TOP_DIR}/src/ichor/LifecycleManager.cpp ${ICHOR_TOP_DIR}/src/ichor/Service.cpp)
set(ICHOR_FRAMEWORK_QUEUE_SOURCES ${ICHOR_TOP_DIR}/src/ichor/event_queues/PriorityQueue.cpp ${ICHOR_TOP_DIR}/src/ichor/event_queues/EventQueue.cpp)
file(GLOB_RECURSE ICHOR_OPTIONAL_ETCD_SOURCES ${ICHOR_TOP_DIR}/src/services/etcd/*.cpp)
file(GLOB_RECURSE ICHOR_LOGGING_SOURCES ${ICHOR_TOP_DIR}/src/services/logging/*.cpp)
file(GLOB_RECURSE ICHOR_HTTP_SOURCES ${ICHOR_TOP_DIR}/src/services/network/http/*.cpp)
Expand All @@ -121,23 +122,30 @@ file(GLOB_RECURSE ICHOR_METRICS_SOURCES ${ICHOR_TOP_DIR}/src/services/metrics/*.
file(GLOB_RECURSE ICHOR_TIMER_SOURCES ${ICHOR_TOP_DIR}/src/services/timer/Timer.cpp ${ICHOR_TOP_DIR}/src/services/timer/TimerFactoryFactory.cpp)
file(GLOB_RECURSE ICHOR_OPTIONAL_HIREDIS_SOURCES ${ICHOR_TOP_DIR}/src/services/redis/*.cpp)
file(GLOB_RECURSE ICHOR_BASE64_SOURCES ${ICHOR_TOP_DIR}/src/base64/*.cpp)
file(GLOB_RECURSE ICHOR_STL_SOURCES ${ICHOR_TOP_DIR}/src/ichor/stl/Any.cpp ${ICHOR_TOP_DIR}/src/ichor/stl/LinuxUtils.cpp ${ICHOR_TOP_DIR}/src/ichor/stl/StringUtils.cpp)
file(GLOB_RECURSE ICHOR_STL_SOURCES ${ICHOR_TOP_DIR}/src/ichor/stl/Any.cpp ${ICHOR_TOP_DIR}/src/ichor/stl/AsyncSingleThreadedMutex.cpp ${ICHOR_TOP_DIR}/src/ichor/stl/LinuxUtils.cpp ${ICHOR_TOP_DIR}/src/ichor/stl/StringUtils.cpp)

set(ICHOR_IO_SOURCES ${ICHOR_TOP_DIR}/src/services/io/SharedOverThreadsAsyncFileIO.cpp)
set(ICHOR_TCP_SOURCES ${ICHOR_TOP_DIR}/src/services/network/tcp/TcpConnectionService.cpp ${ICHOR_TOP_DIR}/src/services/network/tcp/TcpHostService.cpp)
if(ICHOR_USE_LIBURING)
set(ICHOR_FRAMEWORK_QUEUE_SOURCES ${ICHOR_FRAMEWORK_QUEUE_SOURCES} ${ICHOR_TOP_DIR}/src/ichor/event_queues/IOUringQueue.cpp)
set(ICHOR_IO_SOURCES ${ICHOR_IO_SOURCES} ${ICHOR_TOP_DIR}/src/services/io/IOUringAsyncFileIO.cpp)
set(ICHOR_TCP_SOURCES ${ICHOR_TCP_SOURCES} ${ICHOR_TOP_DIR}/src/services/network/tcp/IOUringTcpConnectionService.cpp ${ICHOR_TOP_DIR}/src/services/network/tcp/IOUringTcpHostService.cpp)
set(ICHOR_TIMER_SOURCES ${ICHOR_TIMER_SOURCES} ${ICHOR_TOP_DIR}/src/services/timer/IOUringTimerFactoryFactory.cpp ${ICHOR_TOP_DIR}/src/services/timer/IOUringTimer.cpp)
endif()
if(ICHOR_USE_SDEVENT)
set(ICHOR_FRAMEWORK_QUEUE_SOURCES ${ICHOR_FRAMEWORK_QUEUE_SOURCES} ${ICHOR_TOP_DIR}/src/ichor/event_queues/SdeventQueue.cpp)
endif()
if(ICHOR_USE_BOOST_BEAST)
set(ICHOR_FRAMEWORK_QUEUE_SOURCES ${ICHOR_FRAMEWORK_QUEUE_SOURCES} ${ICHOR_TOP_DIR}/src/ichor/event_queues/BoostAsioQueue.cpp)
endif()

file(GLOB SPDLOG_SOURCES ${ICHOR_EXTERNAL_DIR}/spdlog/src/*.cpp)

if(ICHOR_USE_MIMALLOC AND NOT ICHOR_USE_SYSTEM_MIMALLOC)
set(ICHOR_FRAMEWORK_SOURCES ${ICHOR_FRAMEWORK_SOURCES} ${ICHOR_TOP_DIR}/external/mimalloc/src/static.c)
endif()

add_library(ichor ${FMT_SOURCES} ${ICHOR_FRAMEWORK_SOURCES} ${ICHOR_LOGGING_SOURCES} ${ICHOR_TCP_SOURCES} ${ICHOR_HTTP_SOURCES} ${ICHOR_METRICS_SOURCES} ${ICHOR_TIMER_SOURCES} ${ICHOR_IO_SOURCES} ${ICHOR_BASE64_SOURCES} ${ICHOR_STL_SOURCES})
add_library(ichor ${FMT_SOURCES} ${ICHOR_FRAMEWORK_SOURCES} ${ICHOR_FRAMEWORK_QUEUE_SOURCES} ${ICHOR_LOGGING_SOURCES} ${ICHOR_TCP_SOURCES} ${ICHOR_HTTP_SOURCES} ${ICHOR_METRICS_SOURCES} ${ICHOR_TIMER_SOURCES} ${ICHOR_IO_SOURCES} ${ICHOR_BASE64_SOURCES} ${ICHOR_STL_SOURCES})

if(ICHOR_ENABLE_INTERNAL_DEBUGGING)
target_compile_definitions(ichor PUBLIC ICHOR_ENABLE_INTERNAL_DEBUGGING)
Expand Down Expand Up @@ -450,7 +458,7 @@ endif()
if(NOT WIN32 AND NOT ICHOR_BUILD_COVERAGE)
# gcc uses gdwarf-4 by default, which messes up using the coz profiler, add "-gdwarf-3" if using coz
set(CMAKE_CXX_FLAGS_DEBUG "-ggdb")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ggdb3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-ggdb -O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
endif()
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-12 60

WORKDIR /opt
RUN wget https://github.com/redis/hiredis/archive/refs/tags/v1.2.0.tar.gz
RUN wget https://boostorg.jfrog.io/artifactory/main/release/1.83.0/source/boost_1_83_0.tar.bz2
RUN wget https://archives.boost.io/release/1.83.0/source/boost_1_83_0.tar.bz2
RUN wget https://github.com/openssl/openssl/releases/download/openssl-3.0.15/openssl-3.0.15.tar.gz

ENV CFLAGS="-O2 -fstack-protector-strong -fcf-protection -fstack-clash-protection -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"
Expand Down
13 changes: 1 addition & 12 deletions Dockerfile-asan
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ RUN update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-12 60

WORKDIR /opt
RUN wget https://github.com/redis/hiredis/archive/refs/tags/v1.2.0.tar.gz
RUN wget https://boostorg.jfrog.io/artifactory/main/release/1.83.0/source/boost_1_83_0.tar.bz2
RUN wget https://github.com/openssl/openssl/releases/download/openssl-3.0.15/openssl-3.0.15.tar.gz

ENV CFLAGS="-Og -fsanitize=address,undefined -fno-sanitize=vptr"
Expand All @@ -27,16 +26,6 @@ RUN ./Configure --prefix=/usr --openssldir=/etc/ssl --libdir=lib no-shared
RUN make -j
RUN make -j install

WORKDIR /opt
#Build boost with support for asan
RUN tar xf boost_1_83_0.tar.bz2

WORKDIR /opt/boost_1_83_0

RUN ./bootstrap.sh --prefix=/usr
RUN ./b2 cxxflags="-fsanitize=address,undefined -fno-sanitize=vptr -Og -std=c++20 -DBOOST_USE_ASAN -DBOOST_USE_UCONTEXT" linkflags="-static-libasan -static-libgcc -static-libstdc++ -lubsan" variant=debug link=static threading=multi context-impl=ucontext
RUN ./b2 cxxflags="-fsanitize=address,undefined -fno-sanitize=vptr -Og -std=c++20 -DBOOST_USE_ASAN -DBOOST_USE_UCONTEXT" linkflags="-static-libasan -static-libgcc -static-libstdc++ -lubsan" variant=debug link=static threading=multi context-impl=ucontext install

WORKDIR /opt

#Build latest hiredis containing sdevent support, not available yet in apt
Expand All @@ -57,4 +46,4 @@ WORKDIR /opt/ichor/build

ENTRYPOINT ["/bin/bash", "-c"]

CMD ["unset CFLAGS CXXFLAGS && cd /opt/ichor/build && cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DICHOR_USE_SANITIZERS=1 -DICHOR_USE_HIREDIS=1 -DICHOR_USE_BOOST_BEAST=1 -DICHOR_USE_SPDLOG=1 -DICHOR_USE_SDEVENT=1 -DICHOR_SKIP_EXTERNAL_TESTS=1 /opt/ichor/src && ninja && ninja test"]
CMD ["unset CFLAGS CXXFLAGS && cd /opt/ichor/build && cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DICHOR_USE_SANITIZERS=1 -DICHOR_USE_HIREDIS=1 -DICHOR_USE_SPDLOG=1 -DICHOR_USE_SDEVENT=1 -DICHOR_SKIP_EXTERNAL_TESTS=1 /opt/ichor/src && ninja && ninja test"]
Loading

0 comments on commit 31624d9

Please sign in to comment.