This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Wait Queue, a Header-Only C++ 20 MPMC Thread-Safe Queue
# Wait Queue, a Header-Only C++ 20 MPMC Thread-Safe Queue With Shutdown Semantics
#### Unit Test and Documentation Generation Workflow Status
Expand All
@@ -16,8 +16,12 @@
`wait_queue` is a multi-reader, multi-writer FIFO thread-safe wait queue (often called MPMC for multiple producer / multiple consumer) 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.
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.
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.
## Generated Documentation
The generated Doxygen documentation for `wait_queue` is [here](https://connectivecpp.github.io/wait-queue/).
Expand All
@@ -28,11 +32,11 @@ The `wait_queue` header file does not have any third-party dependencies. It uses
## C++ Standard
`wait_queue` uses C++ 20 features, including `std::stop_token`, `std::stop_source`, `std::condition_variable_any`, `std::scoped_lock`, and `concepts` / `requires`.
`wait_queue` uses C++ 20 features, including `std::stop_token`, `std::stop_source`, `std::condition_variable_any`, `std::scoped_lock`, `concepts`, and `requires` clauses.
## Supported Compilers
Continuous integration workflows build and unit test on g++ (through Ubuntu) and MSVC (through Windows). Note that clang support for C++ 20 `std::jthread` and `std::stop_token` is still experimental (and possibly incomplete) as of May 2024, so has not (yet) been tested with `wait_queue`.
Continuous integration workflows build and unit test on g++ (through Ubuntu) and MSVC (through Windows). Note that clang support for C++ 20 `std::jthread` and `std::stop_token` is still experimental (and possibly incomplete) as of Sep 2024, so has not (yet) been tested with `wait_queue`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* same @c wait_queue since it results in recursive mutex locks.
*/
template <typename F>
auto apply(F&& func) const /* noexcept(std::is_nothrow_invocable<F&&, const T&>::value) */
-> void {
auto apply(F&& func) const /* noexcept(std::is_nothrow_invocable_v<F&&, const T&>) */
-> void
requires std::is_invocable_v<F, T>
{
lock_guard lk{m_mut};
for (const T& elem : m_data_queue) {
func(elem);
Expand All
@@ -536,21 +586,23 @@ class wait_queue {
*
* @return @c true if the @c stop_requested has been called.
*/
auto stop_requested() const noexcept
-> bool {
[[nodiscard]] auto stop_requested() const noexcept
-> bool
{
return m_stop_tok.stop_requested();
}
/**
* Query whether the @c wait_queue is empty or not.
*
* @return @c true if the @c wait_queue is empty.
*/
auto empty() const /* noexcept */
-> bool {
[[nodiscard]] auto empty() const /* noexcept */
-> bool
requires supports_empty<Container>
{
lock_guard lk{m_mut};
return m_data_queue.empty();
Expand All
@@ -561,9 +613,11 @@ class wait_queue {
*
* @return Number of elements in the @c wait_queue.
*/
auto size() const /* noexcept */
-> size_type {
[[nodiscard]] auto size() const /* noexcept */
-> size_type
requires supports_size<Container>
{
lock_guard lk{m_mut};
return m_data_queue.size();
Expand Down
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Merge develop to main #18
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Merge develop to main #18
Filter by extension
Viewed files
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing