Skip to content

Commit 0e322d2

Browse files
Merge pull request #1 from connectivecpp/develop
Merge develop to main
2 parents acf8193 + 8b29b29 commit 0e322d2

11 files changed

Lines changed: 3875 additions & 2 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Build, run unit tests
2+
name: CMake build and run unit test matrix
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
- develop
9+
env:
10+
BUILD_TYPE: Release
11+
jobs:
12+
build_matrix:
13+
strategy:
14+
matrix:
15+
os: [ubuntu-latest, windows-latest, macos-14]
16+
# os: [ubuntu-latest]
17+
runs-on: ${{ matrix.os }}
18+
defaults:
19+
run:
20+
shell: bash
21+
steps:
22+
- name: checkout
23+
uses: actions/checkout@v4
24+
with:
25+
path: main
26+
- name: create-build-dir
27+
run: mkdir build
28+
- name: configure-cmake
29+
run: cd build && cmake -D WAIT_QUEUE_BUILD_TESTS:BOOL=ON -D JM_CIRCULAR_BUFFER_BUILD_TESTS:BOOL=OFF ../main/wait-queue
30+
- name: build
31+
run: cd build && cmake --build . --config $BUILD_TYPE
32+
- name: run-unit-test
33+
run: cd build && ctest -C $BUILD_TYPE

‎.github/workflows/gen_docs.yml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Build, run unit tests
2+
name: Generate documentation
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
jobs:
9+
build_matrix:
10+
strategy:
11+
matrix:
12+
os: [ubuntu-latest]
13+
runs-on: ${{ matrix.os }}
14+
defaults:
15+
run:
16+
shell: bash
17+
steps:
18+
- name: checkout
19+
uses: actions/checkout@v4
20+
- name: run-doxygen
21+
uses: mattnotmitt/doxygen-action@v1.9.8
22+
with:
23+
working-directory: docs
24+
- name: deploy-pages
25+
uses: peaceiris/actions-gh-pages@v4
26+
with:
27+
github_token: ${{ secrets.GITHUB_TOKEN }}
28+
publish_dir: ./doc/doc_output/html

‎CMakeLists.txt‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright (c) 2024 by Cliff Green
2+
#
3+
# https://github.com/connectivecpp/wait-queue
4+
#
5+
# I'm still learning CMake, so improvement suggestions are always welcome.
6+
#
7+
# Distributed under the Boost Software License, Version 1.0.
8+
# (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9+
10+
cmake_minimum_required ( VERSION 3.14 FATAL_ERROR )
11+
12+
project ( wait_queue
13+
LANGUAGES CXX
14+
DESCRIPTION "A multi producer / multi consumer thread safe wait queue"
15+
HOMEPAGE_URL "https://githug.com/connectivecpp/wait-queue/" )
16+
17+
option ( WAIT_QUEUE_BUILD_TESTS "Build unit tests" OFF )
18+
option ( WAIT_QUEUE_BUILD_EXAMPLES "Build examples" OFF )
19+
option ( WAIT_QUEUE_INSTALL "Install header only library" OFF )
20+
21+
# add library targets
22+
23+
add_library ( wait_queue INTERFACE )
24+
add_library ( chops::wait_queue ALIAS wait_queue )
25+
26+
# configure library target
27+
28+
target_include_directories ( wait_queue INTERFACE
29+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
30+
$<INSTALL_INTERFACE:include/> )
31+
target_compile_features ( wait_queue INTERFACE cxx_std_20 )
32+
33+
# check to build unit tests
34+
if ( ${WAIT_QUEUE_BUILD_TESTS} )
35+
enable_testing()
36+
add_subdirectory ( test )
37+
endif ()
38+
39+
# check to build example code
40+
if ( ${WAIT_QUEUE_BUILD_EXAMPLES} )
41+
add_subdirectory ( example )
42+
endif ()
43+
44+
# check to install
45+
if ( ${WAIT_QUEUE_INSTALL} )
46+
set ( CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt )
47+
include ( CPack )
48+
endif ()
49+
50+
# end of file
51+

‎README.md‎

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,69 @@
1-
# wait-queue
2-
Multiple producer / multiple consumer (MPMC) thread-safe queue for passing data between threads
1+
# `wait-queue` is a header-only C++ 20 MPMC (multiple producer / multiple consumer) thread-safe queue for passing data between threads.
2+
3+
# Unit Test and Documentation Generation Workflow Status
4+
5+
![GH Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/connectivecpp/wait-queue/build_run_unit_test_cmake.yml?branch=main&label=GH%20Actions%20build,%20unit%20tests%20on%20main)
6+
7+
![GH Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/connectivecpp/wait-queue/build_run_unit_test_cmake.yml?branch=develop&label=GH%20Actions%20build,%20unit%20tests%20on%20develop)
8+
9+
![GH Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/connectivecpp/wait-queue/gen_docs.yml?branch=main&label=GH%20Actions%20generate%20docs)
10+
11+
# Overview
12+
13+
`wait_queue` is a multi-reader, multi-writer FIFO queue for transferring data between threads. It is templatized on the type of data passed through the queue as well as the queue container type. Data is passed with value semantics, either by copying or by moving (as opposed to a queue that transfers data by pointer or reference). The wait queue has both wait and no-wait pop semantics. A fixed size container (e.g. a `ring_span`) can be used, eliminating any and all dynamic memory management (useful in embedded or deterministic environments). Similarly, a circular buffer that only allocates on construction can be used, which eliminates dynamic memory management when pushing or popping values on or off the queue.
14+
15+
A graceful shutdown can be performed using the `request_stop` method (modeled on the C++ 20 `request_stop` from `std::stop_source`). This allows waiting reader threads to be notified for shutdown. Alternatively a `std::stop_token` can be passed in to the `wait_queue` constructor, allowing shutdown from outside of the `wait_queue` object.
16+
17+
`wait_queue` is inspired by code from Anthony Williams' Concurrency in Action book, although heavily modified.
18+
19+
Additional documentation can be found dkfjlkjdlkjklj
20+
21+
# Generated Documentation
22+
23+
The generated Doxygen documentation for `wait_queue` is [here](https://connectivecpp.github.io/presentations/).
24+
25+
# Dependencies
26+
27+
The `wait-queue` header file does not have any third-party dependencies. It uses C++ standard library headers only. The unit test code does have dependencies as noted below.
28+
29+
# C++ Standard
30+
31+
`wait-queue` uses C++ 20 features, including `std::stop_token`, `std::stop_source`, `std::condition_variable_any`, `std::scoped_lock`, and `concepts` / `requires`.
32+
33+
# Supported Compilers
34+
35+
Continuous integration workflows build and unit test on g++ (through Ubuntu), MSVC (through Windows), and clang (through macOS).
36+
37+
# Unit Test Dependencies
38+
39+
The unit test code uses [Catch2](https://github.com/catchorg/Catch2). If the `WAIT_QUEUE_BUILD_TESTS` flag is provided to Cmake (see commands below) the Cmake configure / generate will download the Catch2 library as appropriate using the [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake) dependency manager. If Catch2 (v3 or greater) is already installed using a different package manager (such as Conan or vcpkg), the `CPM_USE_LOCAL_PACKAGES` variable can be set which results in `find_package` being attempted. Note that v3 (or later) of Catch2 is required.
40+
41+
The unit test uses two third-party libraries (each is a single header-only file):
42+
43+
- Martin Moene's [`ring-span-lite`](https://github.com/martinmoene/ring-span-lite)
44+
- Justas Masiulis' [`circular_buffer`](https://github.com/JustasMasiulis/circular_buffer)
45+
46+
Specific versions and / or branches for the dependencies are in `test/CMakeLists.txt`.
47+
48+
# Build and Run Unit Tests
49+
50+
To build and run the unit test program:
51+
52+
First clone the `wait-queue` repository, then create a build directory in parallel to the presentations directory (this is called "out of source" builds, which is recommended), then `cd` (change directory) into the build directory. The CMake commands:
53+
54+
```
55+
cmake -D WAIT_QUEUE_BUILD_TESTS:BOOL=ON -D JM_CIRCULAR_BUFFER_BUILD_TESTS:BOOL=OFF ../wait-queue
56+
57+
cmake --build .
58+
59+
ctest
60+
```
61+
62+
For additional test output, run the unit test individually, for example:
63+
64+
```
65+
test/wait_queue_test -s
66+
```
67+
68+
The example can be built by adding `-D WAIT_QUEUE_BUILD_EXAMPLES:BOOL=ON` to the CMake configure / generate step.
69+

‎cmake/download_cpm.cmake‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
# copied from CPM.cmake GitHub site
3+
# download CPM.cmake
4+
5+
file(
6+
DOWNLOAD
7+
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.39.0/CPM.cmake
8+
${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
9+
)
10+
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)

0 commit comments

Comments
 (0)