From 33cfe1453e0ecd292e1d527021d84c07ded46a01 Mon Sep 17 00:00:00 2001 From: cliffg-softwarelibre Date: Wed, 2 Apr 2025 11:33:46 -0600 Subject: [PATCH 1/3] Updated download_cpm and gen_docs, added threaded_example --- .github/workflows/gen_docs.yml | 2 +- CMakeLists.txt | 2 +- README.md | 2 ++ cmake/download_cpm.cmake | 2 +- example/CMakeLists.txt | 12 ++++++++++-- example/threaded_queue_buffer_demo.cpp | 4 +++- test/CMakeLists.txt | 2 +- 7 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/gen_docs.yml b/.github/workflows/gen_docs.yml index f3368b4..bab0fc8 100644 --- a/.github/workflows/gen_docs.yml +++ b/.github/workflows/gen_docs.yml @@ -18,7 +18,7 @@ jobs: - name: checkout uses: actions/checkout@v4 - name: run-doxygen - uses: mattnotmitt/doxygen-action@v1.9.8 + uses: mattnotmitt/doxygen-action@v1.12.0 with: working-directory: doc - name: deploy-pages diff --git a/CMakeLists.txt b/CMakeLists.txt index 43fddf2..457eb20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2024 by Cliff Green +# Copyright (c) 2024-2025 by Cliff Green # # https://github.com/connectivecpp/wait-queue # diff --git a/README.md b/README.md index 02c7cb4..aee8990 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ Shutdown semantics are available through `std::stop_token` facilities. A `std::stop_token` can be passed in through the constructors, allowing shutdown to be requested externally to the `wait_queue`, or shutdown can be requested through the `wait_queue request_stop` method. +[P0260R15 - C++ Concurrent Queues](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p0260r15.html) has recently (February 2025) been accepted by the standards committee for C++ 26. This proposal has more features than `wait_queue`, but much of the API is similar. + Thanks go to [Louis Langholtz](https://github.com/louis-langholtz) for adding DBC (Design by Contract) asserts and comments. Concepts and various type constraints have been added. Enhancements are always appreciated. diff --git a/cmake/download_cpm.cmake b/cmake/download_cpm.cmake index b4e123b..a7319b7 100644 --- a/cmake/download_cpm.cmake +++ b/cmake/download_cpm.cmake @@ -4,7 +4,7 @@ file( DOWNLOAD - https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.39.0/CPM.cmake + https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.8/CPM.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake ) include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 2f1b767..40c57c6 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2024 by Cliff Green +# Copyright (c) 2024-2025 by Cliff Green # # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE.txt or copy at https://www.boost.org/LICENSE_1_0.txt) @@ -8,10 +8,16 @@ cmake_minimum_required ( VERSION 3.14 FATAL_ERROR ) # create project project ( wait_queue_example LANGUAGES CXX ) -# add executable +# add dependencies +CPMAddPackage ( "gh:connectivecpp/shared-buffer@1.0.2" ) + +# add executables add_executable ( wait_queue_example wait_queue_example.cpp ) target_compile_features ( wait_queue_example PRIVATE cxx_std_20 ) +add_executable ( threaded_queue_buffer_demo threaded_queue_buffer_demo.cpp ) +target_compile_features ( threaded_queue_buffer_demo PRIVATE cxx_std_20 ) + set ( CMAKE_THREAD_PREFER_PTHREAD TRUE ) set ( THREADS_PREFER_PTHREAD_FLAG TRUE ) find_package ( Threads REQUIRED ) @@ -19,4 +25,6 @@ find_package ( Threads REQUIRED ) # link dependencies target_link_libraries ( wait_queue_example PRIVATE Threads::Threads wait_queue ) +target_link_libraries ( threaded_queue_buffer_demo PRIVATE + Threads::Threads shared_buffer wait_queue ) diff --git a/example/threaded_queue_buffer_demo.cpp b/example/threaded_queue_buffer_demo.cpp index 297b198..ba39f8b 100644 --- a/example/threaded_queue_buffer_demo.cpp +++ b/example/threaded_queue_buffer_demo.cpp @@ -7,6 +7,8 @@ * Copyright (c)2019 by Thurman Gillespy * 3/22/19 * + * Minor changes Apr 2025 by Cliff Green to match changed APIs. + * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) * @@ -26,7 +28,7 @@ #include // std::time #include "queue/wait_queue.hpp" -#include "marshall/shared_buffer.hpp" +#include "buffer/shared_buffer.hpp" /** Project Overview diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ba10fdb..123878f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2024 by Cliff Green +# Copyright (c) 2024-2025 by Cliff Green # # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE.txt or copy at https://www.boost.org/LICENSE_1_0.txt) From 3bcb319d3148f7e4a10c2958114e5ac52d63d743 Mon Sep 17 00:00:00 2001 From: cliffg-softwarelibre Date: Wed, 2 Apr 2025 12:13:06 -0600 Subject: [PATCH 2/3] Using std::ranges::iota_view for loops --- test/wait_queue_test.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/wait_queue_test.cpp b/test/wait_queue_test.cpp index 21c4ddc..9405ce9 100644 --- a/test/wait_queue_test.cpp +++ b/test/wait_queue_test.cpp @@ -19,6 +19,7 @@ #include #include #include +#include // std::views::iota #include // std::is_arithmetic #include @@ -45,12 +46,12 @@ void non_threaded_push_test(Q& wq, const typename Q::value_type& val, int count) REQUIRE (wq.empty()); REQUIRE (wq.size() == 0); - for (int i {0}; i < count; ++i) { + for (int i : std::ranges::iota_view{0, count}) { REQUIRE(wq.push(val)); } REQUIRE_FALSE (wq.empty()); REQUIRE (wq.size() == count); - for (int i {0}; i < count; ++i) { + for (int i : std::ranges::iota_view{0, count}) { auto ret = wq.try_pop(); REQUIRE(*ret == val); } @@ -69,22 +70,22 @@ void non_threaded_arithmetic_test(Q& wq, int count) { REQUIRE (wq.empty()); - for (int i {0}; i < count; ++i) { + for (int i : std::ranges::iota_view{0, count}) { REQUIRE(wq.push(base_val)); } val_type sum { 0 }; wq.apply( [&sum] (const val_type& x) { sum += x; } ); REQUIRE (sum == expected_sum); - for (int i {0}; i < count; ++i) { + for (int i : std::ranges::iota_view{0, count}) { REQUIRE(*(wq.try_pop()) == base_val); } REQUIRE (wq.empty()); - for (int i {0}; i < count; ++i) { + for (int i : std::ranges::iota_view{0, count}) { wq.push(base_val+i); } - for (int i {0}; i < count; ++i) { + for (int i : std::ranges::iota_view{0, count}) { REQUIRE(*(wq.try_pop()) == (base_val+i)); } REQUIRE (wq.size() == 0); @@ -389,25 +390,25 @@ TEST_CASE ( "Fixed size ring_span, testing wrap around with int type", constexpr int Answer = 42; constexpr int AnswerPlus = 42+5; - for (int i {0}; i < N; ++i) { + for (int i : std::ranges::iota_view{0, N}) { wq.push(Answer); } REQUIRE (wq.size() == N); wq.apply([Answer] (const int& i) { REQUIRE(i == Answer); } ); - for (int i {0}; i < N; ++i) { + for (int i : std::ranges::iota_view{0, N}) { wq.push(Answer); } - for (int i {0}; i < (N/2); ++i) { + for (int i : std::ranges::iota_view{0, N/2}) { wq.push(AnswerPlus); } // the size is full but half match answer and half answer plus, since there's been wrap REQUIRE (wq.size() == N); // wait_pop should immediately return if the queue is non empty - for (int i {0}; i < (N/2); ++i) { + for (int i : std::ranges::iota_view{0, N/2}) { REQUIRE (wq.wait_and_pop() == Answer); } - for (int i {0}; i < (N/2); ++i) { + for (int i : std::ranges::iota_view{0, N/2}) { REQUIRE (wq.wait_and_pop() == AnswerPlus); } REQUIRE (wq.empty()); From 23c880f97084df6e3225caa0140b197e8d1b682c Mon Sep 17 00:00:00 2001 From: cliffg-softwarelibre Date: Wed, 2 Apr 2025 12:53:04 -0600 Subject: [PATCH 3/3] setting CMake policy for 3rd party dependencies --- .github/workflows/build_run_unit_test_cmake.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_run_unit_test_cmake.yml b/.github/workflows/build_run_unit_test_cmake.yml index f23b9ee..9c2413b 100644 --- a/.github/workflows/build_run_unit_test_cmake.yml +++ b/.github/workflows/build_run_unit_test_cmake.yml @@ -28,7 +28,7 @@ jobs: - name: create-build-dir run: mkdir build - name: configure-cmake - run: cd build && cmake -D WAIT_QUEUE_BUILD_TESTS:BOOL=ON -D WAIT_QUEUE_BUILD_EXAMPLES:BOOL=ON -D JM_CIRCULAR_BUFFER_BUILD_TESTS:BOOL=OFF .. + run: cd build && cmake -D CMAKE_POLICY_VERSION_MINIMUM=3.5 -D WAIT_QUEUE_BUILD_TESTS:BOOL=ON -D WAIT_QUEUE_BUILD_EXAMPLES:BOOL=ON -D JM_CIRCULAR_BUFFER_BUILD_TESTS:BOOL=OFF .. - name: build run: cd build && cmake --build . --config $BUILD_TYPE - name: run-unit-test