-
Notifications
You must be signed in to change notification settings - Fork 21
Adding new mpmc queue #187
New issue
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
Open
MaciejKaszynski
wants to merge
13
commits into
eclipse-score:main
Choose a base branch
from
etas-contrib:new-queue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e5d3018
Adding new mpmc queue
MaciejKaszynski 3031a8d
Fixing missing breaks
MaciejKaszynski f6922e4
Adding a no-coverage tag
MaciejKaszynski 50f3cec
renaminb head and tail to fit standard
MaciejKaszynski d35b1ce
Getting 100% coverage
MaciejKaszynski 02e8856
Adding results
MaciejKaszynski a6cb5cc
Fixing infinite while errors
MaciejKaszynski 55d687c
Statically linking libatomic
MaciejKaszynski c3bcb71
Adding some more coverage
MaciejKaszynski b5b78c6
Fixing review comments
MaciejKaszynski c2ee6d4
Making queue return slimmer
MaciejKaszynski c3f8907
Moving folder
MaciejKaszynski 3958efe
Adding yields
MaciejKaszynski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
| load("@rules_cc//cc:defs.bzl", "cc_test") | ||
| load("//config:common_cc.bzl", "cc_library_with_common_opts") | ||
|
|
||
| cc_library( | ||
| name = "helgrind_annotations", | ||
| hdrs = ["helgrind_annotations.hpp"], | ||
| strip_include_prefix = "//src/launch_manager_daemon/common", | ||
| visibility = ["//src:__subpackages__"], | ||
| ) | ||
|
|
||
| cc_library( | ||
| name = "mpmc_concurrent_queue", | ||
| hdrs = [ | ||
| "concurrency_error_domain.hpp", | ||
| "mpmc_concurrent_queue.hpp", | ||
| ], | ||
| linkopts = [ | ||
| "-l:libatomic.a", | ||
|
MaciejKaszynski marked this conversation as resolved.
|
||
| ], | ||
| strip_include_prefix = "//src/launch_manager_daemon/common", | ||
| visibility = ["//src:__subpackages__"], | ||
| deps = [ | ||
| ":helgrind_annotations", | ||
| "//src/launch_manager_daemon/common:osal", | ||
| "@score_baselibs//score/language/futurecpp", | ||
| ], | ||
| ) | ||
|
|
||
| cc_test( | ||
| name = "mpmc_concurrent_queue_test", | ||
| srcs = ["mpmc_concurrent_queue_test.cpp"], | ||
| visibility = ["//tests:__subpackages__"], | ||
| deps = [ | ||
| ":mpmc_concurrent_queue", | ||
| "@googletest//:gtest_main", | ||
| ], | ||
| ) | ||
|
|
||
| # Run with: | ||
| # bazel test --run_under="valgrind --tool=helgrind --suppressions=src/launch_manager_daemon/common/concurrency/helgrind.supp --error-exitcode=1" //src/launch_manager_daemon/common/concurrency:mpmc_concurrent_queue_helgrind_test --config=host --test_output=all | ||
| # Note: This is using your host packages so you need to install valgrind. | ||
| # Two tests intentionally exercise semaphore failure paths (EINTR / EAGAIN). | ||
| # Those expected PthAPIerror reports are silenced via helgrind.supp. | ||
| cc_test( | ||
| name = "mpmc_concurrent_queue_helgrind_test", | ||
| srcs = ["mpmc_concurrent_queue_test.cpp"], | ||
| data = ["helgrind.supp"], | ||
| tags = [ | ||
| "helgrind", | ||
| "manual", | ||
| ], | ||
| visibility = ["//tests:__subpackages__"], | ||
| deps = [ | ||
| ":mpmc_concurrent_queue", | ||
| "@googletest//:gtest_main", | ||
| ], | ||
| ) | ||
|
|
||
| cc_test( | ||
| name = "mpmc_concurrent_queue_tsan_test", | ||
| srcs = ["mpmc_concurrent_queue_test.cpp"], | ||
| copts = [ | ||
| "-fsanitize=thread", | ||
| "-O0", | ||
| "-g", | ||
| ], | ||
| linkopts = ["-fsanitize=thread"], | ||
| tags = [ | ||
| "no-coverage", # coverage + tsan might cause problems | ||
| "tsan", | ||
| ], | ||
| visibility = ["//tests:__subpackages__"], | ||
| deps = [ | ||
| ":mpmc_concurrent_queue", | ||
| "@googletest//:gtest_main", | ||
| ], | ||
| ) | ||
52 changes: 52 additions & 0 deletions
52
src/launch_manager_daemon/common/concurrency/concurrency_error_domain.hpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Apache License Version 2.0 which is available at | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ********************************************************************************/ | ||
|
|
||
| #ifndef CONCURRENCY_ERROR_DOMAIN_HPP_INCLUDED | ||
| #define CONCURRENCY_ERROR_DOMAIN_HPP_INCLUDED | ||
|
|
||
| #include <cstdint> | ||
| #include <ostream> | ||
|
|
||
| namespace score::lcm::internal | ||
| { | ||
|
|
||
| enum class ConcurrencyErrc : std::uint8_t | ||
| { | ||
| /// @brief An OS call returned an error. | ||
| kOsError = 1, | ||
|
|
||
| // @brief The container has overflowed. | ||
| kOverflow = 2, | ||
|
|
||
| // @brief The container has stopped. | ||
| kStopped = 3, | ||
|
|
||
| // @brief A timeout was triggered. | ||
| kTimeout = 4, | ||
| }; | ||
|
|
||
| inline std::ostream& operator<<(std::ostream& os, ConcurrencyErrc errc) noexcept | ||
| { | ||
| switch (errc) | ||
| { | ||
| case ConcurrencyErrc::kOsError: return os << "kOsError"; | ||
| case ConcurrencyErrc::kOverflow: return os << "kOverflow"; | ||
| case ConcurrencyErrc::kStopped: return os << "kStopped"; | ||
| case ConcurrencyErrc::kTimeout: return os << "kTimeout"; | ||
| default: return os << static_cast<std::uint8_t>(errc); | ||
| } | ||
| } | ||
|
|
||
| } // namespace score::lcm::internal | ||
|
|
||
| #endif // CONCURRENCY_ERROR_DOMAIN_HPP_INCLUDED |
42 changes: 42 additions & 0 deletions
42
src/launch_manager_daemon/common/concurrency/helgrind.supp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
|
|
||
| # Helgrind suppression file | ||
|
|
||
|
|
||
| # --- mpmc_concurrent_queue_helgrind_test ---- | ||
|
|
||
| # tests intentionally exercise semaphore failure paths and therefore | ||
| # trigger Helgrind's PthAPIerror reports | ||
| # | ||
| # * MPMCConcurrentQueueTest_Basic.PopReturnsNulloptOnSemaphoreWaitFailure | ||
| # Sends SIGUSR1 to the consumer so sem_wait() returns -1 / EINTR and | ||
| # the kFail path in Semaphore::wait() is taken. | ||
| { | ||
| mpmc_queue_sem_wait_eintr_intentional | ||
| Helgrind:PthAPIerror | ||
| obj:*/vgpreload_helgrind-*.so | ||
| fun:_ZN5score3lcm8internal4osal9Semaphore4waitEv | ||
| ... | ||
| } | ||
|
|
||
| # * MPMCConcurrentQueueTest_Timeout.PushWithTimeoutReturnsFalseWhenFull | ||
| # Fills the queue so sem_trywait() inside Semaphore::timedWait() | ||
| # returns -1 / EAGAIN until the timeout expires. | ||
| { | ||
| mpmc_queue_sem_trywait_eagain_intentional | ||
| Helgrind:PthAPIerror | ||
| obj:*/vgpreload_helgrind-*.so | ||
| fun:_ZN5score3lcm8internal4osal9Semaphore9timedWaitENSt6chrono8durationIlSt5ratioILl1ELl1000EEEE | ||
| ... | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/launch_manager_daemon/common/concurrency/helgrind_annotations.hpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /******************************************************************************** | ||
| * Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
| * | ||
| * See the NOTICE file(s) distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Apache License Version 2.0 which is available at | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| ********************************************************************************/ | ||
|
|
||
| #ifndef HELGRIND_ANNOTATIONS_HPP_INCLUDED | ||
| #define HELGRIND_ANNOTATIONS_HPP_INCLUDED | ||
|
|
||
| // When built with --config=host the system compiler finds valgrind/helgrind.h | ||
| // in its default include paths and the real annotations are active. Under any | ||
| // other config the header is absent and the macros expand to no-ops. | ||
| #if __has_include(<valgrind/helgrind.h>) | ||
| #include <valgrind/helgrind.h> | ||
| #else | ||
| // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) | ||
| #define ANNOTATE_HAPPENS_BEFORE(obj) do {} while (false) | ||
| // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) | ||
| #define ANNOTATE_HAPPENS_AFTER(obj) do {} while (false) | ||
| #endif | ||
|
|
||
| #endif // HELGRIND_ANNOTATIONS_HPP_INCLUDED |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.