From 93147df3b60959b5d28898441429ca5df6d99083 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Wed, 21 Aug 2024 01:51:10 +0200 Subject: [PATCH 1/4] iox-#2329 Use iox::concurrent::Atomic --- doc/design/listener.md | 38 +++---- doc/design/relocatable_pointer.md | 2 +- .../test/moduletests/test_listener.cpp | 1 - .../test/moduletests/test_wait_set.cpp | 12 +-- .../node/iox_cpp_node_subscriber.cpp | 3 +- .../include/discovery_blocking.hpp | 4 +- .../request_response/client_cxx_waitset.cpp | 1 - .../singleprocess/single_process.cpp | 1 - .../user_header/publisher_cxx_api.cpp | 1 - .../user_header/publisher_untyped_cxx_api.cpp | 1 - .../user_header/subscriber_cxx_api.cpp | 1 - .../subscriber_untyped_cxx_api.cpp | 1 - .../waitset/ice_waitset_basic.cpp | 1 - .../waitset/ice_waitset_gateway.cpp | 3 +- .../waitset/ice_waitset_grouping.cpp | 3 +- .../waitset/ice_waitset_individual.cpp | 3 +- .../ice_waitset_timer_driven_execution.cpp | 3 +- .../waitset/ice_waitset_trigger.cpp | 3 +- .../iox/detail/mpmc_lockfree_queue.hpp | 6 +- .../mpmc_lockfree_queue/mpmc_index_queue.hpp | 8 +- .../buffer/include/iox/detail/mpmc_loffli.hpp | 4 +- .../detail/mpmc_resizeable_lockfree_queue.hpp | 7 +- .../buffer/include/iox/detail/spsc_fifo.hpp | 7 +- .../buffer/include/iox/detail/spsc_sofi.hpp | 6 +- .../concurrent/buffer/source/mpmc_loffli.cpp | 1 - .../iox/detail/polymorphic_handler.inl | 2 +- .../iox/detail/static_lifetime_guard.inl | 6 +- .../include/iox/polymorphic_handler.hpp | 10 +- .../include/iox/static_lifetime_guard.hpp | 7 +- .../posix/ipc/include/iox/named_pipe.hpp | 3 +- .../posix/sync/include/iox/signal_watcher.hpp | 7 +- .../posix/sync/include/iox/thread.hpp | 1 - .../iox/detail/log/building_blocks/logger.inl | 1 - .../log/building_blocks/console_logger.hpp | 4 +- .../iox/log/building_blocks/logger.hpp | 6 +- .../reporting/source/console_logger.cpp | 2 +- .../test_concurrent_smart_lock.cpp | 4 +- .../test_design_polymorphic_handler.cpp | 7 +- .../test_posix_ipc_unix_domain_sockets.cpp | 6 +- .../test/moduletests/test_posix_mutex.cpp | 6 +- .../test_posix_semaphore_interface.cpp | 1 - .../moduletests/test_posix_signal_handler.cpp | 22 ++-- .../test_posix_sync_signal_watcher.cpp | 4 +- .../moduletests/test_time_adaptive_wait.cpp | 6 +- .../moduletests/test_time_deadline_timer.cpp | 3 +- .../benchmark.hpp | 4 +- .../sofi/test_stress_spsc_sofi.cpp | 43 ++++---- .../test_mpmc_lockfree_queue_stresstest.cpp | 24 +++-- ...c_resizeable_lockfree_queue_stresstest.cpp | 37 ++++--- .../error_reporting/testing_error_handler.cpp | 4 +- .../error_reporting/testing_error_handler.hpp | 6 +- .../iceoryx_hoofs/testing/fatal_failure.hpp | 1 - .../iceoryx_hoofs/testing/timing_test.hpp | 11 +- iceoryx_hoofs/testing/timing_test.cpp | 5 +- .../utility/include/iox/detail/unique_id.hpp | 5 +- iceoryx_hoofs/utility/source/unique_id.cpp | 2 +- iceoryx_platform/generic/source/logging.cpp | 6 +- .../include/iceoryx_platform/semaphore.hpp | 5 +- .../mac/include/iceoryx_platform/time.hpp | 1 - .../moduletests/test_platform_logging.cpp | 12 +-- .../iceoryx_platform/unique_system_id.hpp | 5 +- .../win/source/unique_system_id.cpp | 3 +- .../iceoryx_posh/gateway/gateway_generic.hpp | 4 +- .../internal/mepoo/chunk_management.hpp | 4 +- .../iceoryx_posh/internal/mepoo/mem_pool.hpp | 6 +- .../popo/building_blocks/chunk_queue_data.hpp | 3 +- .../building_blocks/condition_listener.hpp | 3 +- .../condition_variable_data.hpp | 9 +- .../popo/building_blocks/unique_port_id.hpp | 4 +- .../internal/popo/ports/base_port_data.hpp | 5 +- .../internal/popo/ports/client_port_data.hpp | 6 +- .../popo/ports/publisher_port_data.hpp | 6 +- .../internal/popo/ports/server_port_data.hpp | 6 +- .../popo/ports/subscriber_port_data.hpp | 7 +- .../internal/popo/used_chunk_list.hpp | 4 +- .../introspection/port_introspection.hpp | 4 +- .../iceoryx_posh/internal/roudi/process.hpp | 3 +- .../iceoryx_posh/internal/roudi/roudi.hpp | 5 +- .../internal/runtime/heartbeat.hpp | 6 +- .../include/iceoryx_posh/popo/listener.hpp | 5 +- .../iceoryx_posh/popo/user_trigger.hpp | 1 - .../iceoryx_posh/runtime/posh_runtime.hpp | 5 +- .../roudi_env/runtime_test_interface.hpp | 6 +- .../source/runtime_test_interface.cpp | 5 +- iceoryx_posh/source/iceoryx_posh_types.cpp | 5 +- .../popo/building_blocks/unique_port_id.cpp | 3 +- .../source/popo/ports/client_port_user.cpp | 2 +- .../popo/ports/subscriber_port_user.cpp | 2 +- iceoryx_posh/source/runtime/posh_runtime.cpp | 10 +- .../integrationtests/test_client_server.cpp | 5 +- .../test_mq_interface_startup_race.cpp | 7 +- .../test_popo_chunk_building_blocks.cpp | 11 +- .../test_popo_port_user_building_blocks.cpp | 7 +- ...est_publisher_subscriber_communication.cpp | 13 ++- .../test_service_discovery.cpp | 3 +- .../test_popo_chunk_distributor.cpp | 7 +- .../moduletests/test_popo_client_port.cpp | 17 +-- .../test_popo_condition_variable.cpp | 44 ++++---- .../test/moduletests/test_popo_listener.cpp | 100 +++++++++--------- .../moduletests/test_popo_trigger_handle.cpp | 3 +- .../test/moduletests/test_popo_waitset.cpp | 15 +-- .../test/moduletests/test_posh_runtime.cpp | 21 ++-- .../moduletests/test_roudi_portmanager.cpp | 3 +- .../test_roudi_portmanager_client_server.cpp | 8 +- .../test/moduletests/test_roudi_portpool.cpp | 8 +- 105 files changed, 413 insertions(+), 391 deletions(-) diff --git a/doc/design/listener.md b/doc/design/listener.md index f7e0974954..23e9352cc2 100644 --- a/doc/design/listener.md +++ b/doc/design/listener.md @@ -75,22 +75,22 @@ which event is attached, like in the _WaitSet_. | - m_toBeDestroyed | | - m_activeNotifications | +---------------------------+ - | 1 | 1 - | | - | 1 | n -+-----------------------------------------------+ +--------------------------------------------------+ -| ConditionListener | | ConditionNotifier | -| ConditionListener(ConditionVariableData & ) | | ConditionNotifier(ConditionVariableData &, | -| | | uint64_t notificationIndex) | -| bool wasNotified() | | | -| void destroy() | | void notify() | -| NotificationVector_t wait() | | | -| NotificationVector_t timedWait() | | - m_condVarDataPtr : ConditionVariableData* | -| | | - m_notificationIndex | -| - m_condVarDataPtr : ConditionVariableData* | +--------------------------------------------------+ -| - m_toBeDestroyed : std::atomic_bool | | 1 -+-----------------------------------------------+ | - | 1 | n + | 1 | 1 + | | + | 1 | n ++------------------------------------------------------+ +--------------------------------------------------+ +| ConditionListener | | ConditionNotifier | +| ConditionListener(ConditionVariableData & ) | | ConditionNotifier(ConditionVariableData &, | +| | | uint64_t notificationIndex) | +| bool wasNotified() | | | +| void destroy() | | void notify() | +| NotificationVector_t wait() | | | +| NotificationVector_t timedWait() | | - m_condVarDataPtr : ConditionVariableData* | +| | | - m_notificationIndex | +| - m_condVarDataPtr : ConditionVariableData* | +--------------------------------------------------+ +| - m_toBeDestroyed : iox::concurrent::Atomic | | 1 ++------------------------------------------------------+ | + | 1 | n | +--------------------------------+ | 1 | TriggerHandle | +-------------------------------------------------+ | bool isValid() | @@ -171,8 +171,8 @@ Triggerable TriggerHandle ConditionNotifier ConditionListener | | | | | m_events[notificationId] | ``` -- **Triggerable goes out of scope:** The TriggerHandle is a member of the - Triggerable, therefore the d'tor of the TriggerHandle is called which removes +- **Triggerable goes out of scope:** The TriggerHandle is a member of the + Triggerable, therefore the d'tor of the TriggerHandle is called which removes the trigger from the Listener via the `resetCallback` ``` @@ -183,7 +183,7 @@ Triggerable TriggerHandle Listener Event_t | | via resetCallback | ------------> | ``` -- **Listener goes out of scope:** The d'tor of the `Event_t` invalidates the +- **Listener goes out of scope:** The d'tor of the `Event_t` invalidates the Trigger inside the Triggerable via the `invalidationCallback` ``` diff --git a/doc/design/relocatable_pointer.md b/doc/design/relocatable_pointer.md index 1b457288db..0d80f467d4 100644 --- a/doc/design/relocatable_pointer.md +++ b/doc/design/relocatable_pointer.md @@ -224,7 +224,7 @@ the operations incur slightly more overhead compared to relocatable pointers. ## Atomic usage -There is a technical problem using both `relocatable_ptr` and `RelativePointer` as a type in a `std::atomic`. +There is a technical problem using both `relocatable_ptr` and `RelativePointer` as a type in a `iox::concurrent::Atomic`. This is essentially impossible as an atomic requires its type to be copyable/movable (to be loaded) but on the other hand, this copy constructor must be trivial, i.e. performable with a (shallow) memcpy. Therefore, the types used in atomic cannot implement custom copy/move. This is not possible for `relocatable_ptr` and `RelativePointer` as both require operations performed diff --git a/iceoryx_binding_c/test/moduletests/test_listener.cpp b/iceoryx_binding_c/test/moduletests/test_listener.cpp index b81187570f..24bca8f21c 100644 --- a/iceoryx_binding_c/test/moduletests/test_listener.cpp +++ b/iceoryx_binding_c/test/moduletests/test_listener.cpp @@ -47,7 +47,6 @@ extern "C" { #include "test.hpp" -#include #include namespace diff --git a/iceoryx_binding_c/test/moduletests/test_wait_set.cpp b/iceoryx_binding_c/test/moduletests/test_wait_set.cpp index 56845685ec..c3f37e44f3 100644 --- a/iceoryx_binding_c/test/moduletests/test_wait_set.cpp +++ b/iceoryx_binding_c/test/moduletests/test_wait_set.cpp @@ -24,6 +24,7 @@ #include "iceoryx_posh/popo/untyped_server.hpp" #include "iceoryx_posh/popo/user_trigger.hpp" #include "iceoryx_posh/runtime/service_discovery.hpp" +#include "iox/atomic.hpp" #include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" @@ -45,7 +46,6 @@ extern "C" { #include "test.hpp" -#include #include namespace @@ -986,7 +986,7 @@ TIMING_TEST_F(iox_ws_test, WaitIsBlockingTillTriggered, Repeat(5), [&] { ::testing::Test::RecordProperty("TEST_ID", "6d8a476d-5bcd-45a5-bbd4-7b3b709ac967"); iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, userTriggerCallback); - std::atomic_bool waitWasCalled{false}; + iox::concurrent::Atomic waitWasCalled{false}; std::thread t([&] { iox_ws_wait(m_sut, NULL, 0U, &m_missedElements); waitWasCalled.store(true); @@ -1003,7 +1003,7 @@ TIMING_TEST_F(iox_ws_test, WaitIsBlockingTillTriggered, Repeat(5), [&] { TIMING_TEST_F(iox_ws_test, WaitIsNonBlockingAfterMarkForDestruction, Repeat(5), [&] { ::testing::Test::RecordProperty("TEST_ID", "4e576665-fda1-4f3c-8588-e9d2cffcb3f4"); - std::atomic_bool waitWasCalled{false}; + iox::concurrent::Atomic waitWasCalled{false}; std::thread t([&] { iox_ws_wait(m_sut, NULL, 0U, &m_missedElements); iox_ws_wait(m_sut, NULL, 0U, &m_missedElements); @@ -1025,7 +1025,7 @@ TIMING_TEST_F(iox_ws_test, TimedWaitIsBlockingTillTriggered, Repeat(5), [&] { ::testing::Test::RecordProperty("TEST_ID", "e79edc1d-8b8a-4dd0-97ba-e2f41c9c8b31"); iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, userTriggerCallback); - std::atomic_bool waitWasCalled{false}; + iox::concurrent::Atomic waitWasCalled{false}; std::thread t([&] { iox_ws_timed_wait(m_sut, {1000, 1000}, NULL, 0U, &m_missedElements); waitWasCalled.store(true); @@ -1042,7 +1042,7 @@ TIMING_TEST_F(iox_ws_test, TimedWaitIsBlockingTillTriggered, Repeat(5), [&] { TIMING_TEST_F(iox_ws_test, TimedWaitIsNonBlockingAfterMarkForDestruction, Repeat(5), [&] { ::testing::Test::RecordProperty("TEST_ID", "a6da4f49-b162-4c70-b0fa-c4ef1f988c57"); - std::atomic_bool waitWasCalled{false}; + iox::concurrent::Atomic waitWasCalled{false}; std::thread t([&] { iox_ws_timed_wait(m_sut, {1000, 1000}, NULL, 0U, &m_missedElements); iox_ws_timed_wait(m_sut, {1000, 1000}, NULL, 0U, &m_missedElements); @@ -1063,7 +1063,7 @@ TIMING_TEST_F(iox_ws_test, TimedWaitBlocksTillTimeout, Repeat(5), [&] { ::testing::Test::RecordProperty("TEST_ID", "12fbbbc8-80b2-4e7e-af41-1376b2e48f4a"); iox_ws_attach_user_trigger_event(m_sut, m_userTrigger[0U], 0U, userTriggerCallback); - std::atomic_bool waitWasCalled{false}; + iox::concurrent::Atomic waitWasCalled{false}; std::thread t([&] { constexpr long hundredMsInNanoSeconds = 100000000L; iox_ws_timed_wait(m_sut, {0, hundredMsInNanoSeconds}, NULL, 0U, &m_missedElements); diff --git a/iceoryx_examples/experimental/node/iox_cpp_node_subscriber.cpp b/iceoryx_examples/experimental/node/iox_cpp_node_subscriber.cpp index 5e513b9aa1..1c172b7ec9 100644 --- a/iceoryx_examples/experimental/node/iox_cpp_node_subscriber.cpp +++ b/iceoryx_examples/experimental/node/iox_cpp_node_subscriber.cpp @@ -16,13 +16,14 @@ #include "topic_data.hpp" +#include "iox/atomic.hpp" #include "iox/optional.hpp" #include "iox/posh/experimental/node.hpp" #include "iox/signal_handler.hpp" #include -std::atomic_bool keep_running{true}; +iox::concurrent::Atomic keep_running{true}; using WaitSet = iox::popo::WaitSet<>; volatile WaitSet* waitsetSigHandlerAccess{nullptr}; diff --git a/iceoryx_examples/icediscovery/include/discovery_blocking.hpp b/iceoryx_examples/icediscovery/include/discovery_blocking.hpp index ceff302495..d80d0a653c 100644 --- a/iceoryx_examples/icediscovery/include/discovery_blocking.hpp +++ b/iceoryx_examples/icediscovery/include/discovery_blocking.hpp @@ -19,8 +19,8 @@ #include "iceoryx_posh/popo/wait_set.hpp" #include "iceoryx_posh/runtime/service_discovery.hpp" +#include "iox/atomic.hpp" -#include #include namespace discovery @@ -61,7 +61,7 @@ class Discovery private: ServiceDiscovery* m_discovery{nullptr}; iox::popo::WaitSet<1> m_waitset; - std::atomic_bool m_blocking{true}; + iox::concurrent::Atomic m_blocking{true}; }; //! [wait until condition] diff --git a/iceoryx_examples/request_response/client_cxx_waitset.cpp b/iceoryx_examples/request_response/client_cxx_waitset.cpp index 83256ef6df..d316c14c97 100644 --- a/iceoryx_examples/request_response/client_cxx_waitset.cpp +++ b/iceoryx_examples/request_response/client_cxx_waitset.cpp @@ -24,7 +24,6 @@ #include "iox/signal_watcher.hpp" //! [iceoryx includes] -#include #include constexpr char APP_NAME[] = "iox-cpp-request-response-client-waitset"; diff --git a/iceoryx_examples/singleprocess/single_process.cpp b/iceoryx_examples/singleprocess/single_process.cpp index 98162fd52a..ada254d2f3 100644 --- a/iceoryx_examples/singleprocess/single_process.cpp +++ b/iceoryx_examples/singleprocess/single_process.cpp @@ -26,7 +26,6 @@ #include "iox/logging.hpp" #include "iox/signal_watcher.hpp" -#include #include #include #include diff --git a/iceoryx_examples/user_header/publisher_cxx_api.cpp b/iceoryx_examples/user_header/publisher_cxx_api.cpp index 78599083af..1aa157c81c 100644 --- a/iceoryx_examples/user_header/publisher_cxx_api.cpp +++ b/iceoryx_examples/user_header/publisher_cxx_api.cpp @@ -22,7 +22,6 @@ #include "iox/signal_watcher.hpp" //! [iceoryx includes] -#include #include int main() diff --git a/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp b/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp index 02c4116daf..5dcef4fd6f 100644 --- a/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp +++ b/iceoryx_examples/user_header/publisher_untyped_cxx_api.cpp @@ -24,7 +24,6 @@ #include "iceoryx_posh/runtime/posh_runtime.hpp" //! [iceoryx includes] -#include #include int main() diff --git a/iceoryx_examples/user_header/subscriber_cxx_api.cpp b/iceoryx_examples/user_header/subscriber_cxx_api.cpp index 74bb00d22b..feede09f71 100644 --- a/iceoryx_examples/user_header/subscriber_cxx_api.cpp +++ b/iceoryx_examples/user_header/subscriber_cxx_api.cpp @@ -22,7 +22,6 @@ #include "iox/signal_watcher.hpp" //! [iceoryx includes] -#include #include int main() diff --git a/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp b/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp index 9272a3671f..d8737e527e 100644 --- a/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp +++ b/iceoryx_examples/user_header/subscriber_untyped_cxx_api.cpp @@ -22,7 +22,6 @@ #include "iox/signal_watcher.hpp" //! [iceoryx includes] -#include #include int main() diff --git a/iceoryx_examples/waitset/ice_waitset_basic.cpp b/iceoryx_examples/waitset/ice_waitset_basic.cpp index e529f284c5..91ebce2284 100644 --- a/iceoryx_examples/waitset/ice_waitset_basic.cpp +++ b/iceoryx_examples/waitset/ice_waitset_basic.cpp @@ -22,7 +22,6 @@ #include "iox/signal_handler.hpp" #include "topic_data.hpp" -#include #include //! [sig handler] diff --git a/iceoryx_examples/waitset/ice_waitset_gateway.cpp b/iceoryx_examples/waitset/ice_waitset_gateway.cpp index b0890042a3..9e7eed7388 100644 --- a/iceoryx_examples/waitset/ice_waitset_gateway.cpp +++ b/iceoryx_examples/waitset/ice_waitset_gateway.cpp @@ -18,6 +18,7 @@ #include "iceoryx_posh/popo/user_trigger.hpp" #include "iceoryx_posh/popo/wait_set.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/atomic.hpp" #include "iox/signal_handler.hpp" #include "topic_data.hpp" @@ -26,7 +27,7 @@ constexpr uint64_t NUMBER_OF_SUBSCRIBERS = 2U; -std::atomic_bool keepRunning{true}; +iox::concurrent::Atomic keepRunning{true}; //! [waitset type alias] using WaitSet = iox::popo::WaitSet; diff --git a/iceoryx_examples/waitset/ice_waitset_grouping.cpp b/iceoryx_examples/waitset/ice_waitset_grouping.cpp index cb057d34f5..43b0782b86 100644 --- a/iceoryx_examples/waitset/ice_waitset_grouping.cpp +++ b/iceoryx_examples/waitset/ice_waitset_grouping.cpp @@ -18,13 +18,14 @@ #include "iceoryx_posh/popo/user_trigger.hpp" #include "iceoryx_posh/popo/wait_set.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/atomic.hpp" #include "iox/signal_handler.hpp" #include "topic_data.hpp" #include #include -std::atomic_bool keepRunning{true}; +iox::concurrent::Atomic keepRunning{true}; constexpr uint64_t NUMBER_OF_SUBSCRIBERS = 4U; using WaitSet = iox::popo::WaitSet; diff --git a/iceoryx_examples/waitset/ice_waitset_individual.cpp b/iceoryx_examples/waitset/ice_waitset_individual.cpp index c7960e868e..7a66c42899 100644 --- a/iceoryx_examples/waitset/ice_waitset_individual.cpp +++ b/iceoryx_examples/waitset/ice_waitset_individual.cpp @@ -18,13 +18,14 @@ #include "iceoryx_posh/popo/user_trigger.hpp" #include "iceoryx_posh/popo/wait_set.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/atomic.hpp" #include "iox/signal_handler.hpp" #include "topic_data.hpp" #include #include -std::atomic_bool keepRunning{true}; +iox::concurrent::Atomic keepRunning{true}; using WaitSet = iox::popo::WaitSet<>; volatile WaitSet* waitsetSigHandlerAccess{nullptr}; diff --git a/iceoryx_examples/waitset/ice_waitset_timer_driven_execution.cpp b/iceoryx_examples/waitset/ice_waitset_timer_driven_execution.cpp index 04c2baf7cf..3e46468e11 100644 --- a/iceoryx_examples/waitset/ice_waitset_timer_driven_execution.cpp +++ b/iceoryx_examples/waitset/ice_waitset_timer_driven_execution.cpp @@ -18,13 +18,14 @@ #include "iceoryx_posh/popo/user_trigger.hpp" #include "iceoryx_posh/popo/wait_set.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/atomic.hpp" #include "iox/signal_handler.hpp" #include "topic_data.hpp" #include #include -std::atomic_bool keepRunning{true}; +iox::concurrent::Atomic keepRunning{true}; using WaitSet = iox::popo::WaitSet<>; volatile iox::popo::WaitSet<>* waitsetSigHandlerAccess{nullptr}; diff --git a/iceoryx_examples/waitset/ice_waitset_trigger.cpp b/iceoryx_examples/waitset/ice_waitset_trigger.cpp index a72dfa32f6..85d2538db1 100644 --- a/iceoryx_examples/waitset/ice_waitset_trigger.cpp +++ b/iceoryx_examples/waitset/ice_waitset_trigger.cpp @@ -17,12 +17,13 @@ #include "iceoryx_posh/popo/enum_trigger_type.hpp" #include "iceoryx_posh/popo/wait_set.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/atomic.hpp" #include "iox/optional.hpp" #include #include -std::atomic_bool keepRunning{true}; +iox::concurrent::Atomic keepRunning{true}; using WaitSet = iox::popo::WaitSet<>; diff --git a/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_lockfree_queue.hpp b/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_lockfree_queue.hpp index ff09f77580..ff19b0d091 100644 --- a/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_lockfree_queue.hpp +++ b/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_lockfree_queue.hpp @@ -18,13 +18,11 @@ #ifndef IOX_HOOFS_CONCURRENT_BUFFER_MPMC_LOCKFREE_QUEUE_HPP #define IOX_HOOFS_CONCURRENT_BUFFER_MPMC_LOCKFREE_QUEUE_HPP +#include "iox/atomic.hpp" #include "iox/detail/mpmc_lockfree_queue/mpmc_index_queue.hpp" #include "iox/optional.hpp" #include "iox/uninitialized_array.hpp" -#include - - namespace iox { namespace concurrent @@ -112,7 +110,7 @@ class MpmcLockFreeQueue UninitializedArray m_buffer; - std::atomic m_size{0U}; + Atomic m_size{0U}; // template is needed to distinguish between lvalue and rvalue T references // (universal reference type deduction) diff --git a/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_lockfree_queue/mpmc_index_queue.hpp b/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_lockfree_queue/mpmc_index_queue.hpp index c6a8a932b1..c0e0d80882 100644 --- a/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_lockfree_queue/mpmc_index_queue.hpp +++ b/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_lockfree_queue/mpmc_index_queue.hpp @@ -18,10 +18,10 @@ #ifndef IOX_HOOFS_CONCURRENT_BUFFER_MPMC_LOCKFREE_QUEUE_MPMC_INDEX_QUEUE_HPP #define IOX_HOOFS_CONCURRENT_BUFFER_MPMC_LOCKFREE_QUEUE_MPMC_INDEX_QUEUE_HPP +#include "iox/atomic.hpp" #include "iox/detail/mpmc_lockfree_queue/cyclic_index.hpp" #include "iox/optional.hpp" -#include #include namespace iox @@ -109,7 +109,7 @@ class MpmcIndexQueue // remark: a compile time check whether Index is actually lock free would be nice // note: there is a way with is_always_lock_free in c++17 (which we cannot use here) using Index = CyclicIndex; - using Cell = std::atomic; + using Cell = Atomic; /// the array entries have to be initialized explicitly in the constructor since /// the default atomic constructor does not call the default constructor of the @@ -119,8 +119,8 @@ class MpmcIndexQueue // NOLINTNEXTLINE(*avoid-c-arrays) Cell m_cells[Capacity]; - std::atomic m_readPosition; - std::atomic m_writePosition; + Atomic m_readPosition; + Atomic m_writePosition; /// @brief load the value from m_cells at a position with a given memory order /// @param position position to load the value from diff --git a/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_loffli.hpp b/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_loffli.hpp index ec1536a62f..7948e101d7 100644 --- a/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_loffli.hpp +++ b/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_loffli.hpp @@ -18,10 +18,10 @@ #ifndef IOX_HOOFS_CONCURRENT_BUFFER_MPMC_LOFFLI_HPP #define IOX_HOOFS_CONCURRENT_BUFFER_MPMC_LOFFLI_HPP +#include "iox/atomic.hpp" #include "iox/not_null.hpp" #include "iox/relative_pointer.hpp" -#include #include namespace iox @@ -71,7 +71,7 @@ class MpmcLoFFLi uint32_t m_size{0U}; Index_t m_invalidIndex{0U}; - std::atomic m_head{{0U, 1U}}; + Atomic m_head{{0U, 1U}}; iox::RelativePointer m_nextFreeIndex; public: diff --git a/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_resizeable_lockfree_queue.hpp b/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_resizeable_lockfree_queue.hpp index 1483829087..c9a0d0feda 100644 --- a/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_resizeable_lockfree_queue.hpp +++ b/iceoryx_hoofs/concurrent/buffer/include/iox/detail/mpmc_resizeable_lockfree_queue.hpp @@ -17,12 +17,11 @@ #ifndef IOX_HOOFS_CONCURRENT_BUFFER_MPMC_RESIZEABLE_LOCKFREE_QUEUE_HPP #define IOX_HOOFS_CONCURRENT_BUFFER_MPMC_RESIZEABLE_LOCKFREE_QUEUE_HPP +#include "iox/atomic.hpp" #include "iox/detail/mpmc_lockfree_queue.hpp" #include "iox/type_traits.hpp" #include "iox/vector.hpp" -#include - namespace iox { namespace concurrent @@ -123,9 +122,9 @@ class MpmcResizeableLockFreeQueue : protected MpmcLockFreeQueue m_capacity{MaxCapacity}; + Atomic m_capacity{MaxCapacity}; // must be operator= otherwise it is undefined, see https://en.cppreference.com/w/cpp/atomic/ATOMIC_FLAG_INIT - std::atomic_flag m_resizeInProgress = ATOMIC_FLAG_INIT; + AtomicFlag m_resizeInProgress = ATOMIC_FLAG_INIT; iox::vector m_unusedIndices; /// @brief Increase the capacity by some value. diff --git a/iceoryx_hoofs/concurrent/buffer/include/iox/detail/spsc_fifo.hpp b/iceoryx_hoofs/concurrent/buffer/include/iox/detail/spsc_fifo.hpp index 62ba68a8bb..50cc89ba0a 100644 --- a/iceoryx_hoofs/concurrent/buffer/include/iox/detail/spsc_fifo.hpp +++ b/iceoryx_hoofs/concurrent/buffer/include/iox/detail/spsc_fifo.hpp @@ -18,11 +18,10 @@ #ifndef IOX_HOOFS_CONCURRENT_BUFFER_SPSC_FIFO_HPP #define IOX_HOOFS_CONCURRENT_BUFFER_SPSC_FIFO_HPP +#include "iox/atomic.hpp" #include "iox/optional.hpp" #include "iox/uninitialized_array.hpp" -#include - namespace iox { namespace concurrent @@ -67,8 +66,8 @@ class SpscFifo private: UninitializedArray m_data; - std::atomic m_writePos{0}; - std::atomic m_readPos{0}; + Atomic m_writePos{0}; + Atomic m_readPos{0}; }; } // namespace concurrent diff --git a/iceoryx_hoofs/concurrent/buffer/include/iox/detail/spsc_sofi.hpp b/iceoryx_hoofs/concurrent/buffer/include/iox/detail/spsc_sofi.hpp index a4329fd13a..7b60a8b1c5 100644 --- a/iceoryx_hoofs/concurrent/buffer/include/iox/detail/spsc_sofi.hpp +++ b/iceoryx_hoofs/concurrent/buffer/include/iox/detail/spsc_sofi.hpp @@ -19,10 +19,10 @@ #define IOX_HOOFS_CONCURRENT_BUFFER_SPSC_SOFI_HPP #include "iceoryx_platform/platform_correction.hpp" +#include "iox/atomic.hpp" #include "iox/type_traits.hpp" #include "iox/uninitialized_array.hpp" -#include #include #include @@ -159,8 +159,8 @@ class SpscSofi /// @brief the write/read pointers are "atomic pointers" so that they are not /// reordered (read or written too late) - std::atomic m_readPosition{0}; - std::atomic m_writePosition{0}; + Atomic m_readPosition{0}; + Atomic m_writePosition{0}; }; } // namespace concurrent diff --git a/iceoryx_hoofs/concurrent/buffer/source/mpmc_loffli.cpp b/iceoryx_hoofs/concurrent/buffer/source/mpmc_loffli.cpp index 77f6f87e21..2d700fe114 100644 --- a/iceoryx_hoofs/concurrent/buffer/source/mpmc_loffli.cpp +++ b/iceoryx_hoofs/concurrent/buffer/source/mpmc_loffli.cpp @@ -29,7 +29,6 @@ void MpmcLoFFLi::init(not_null freeIndicesMemory, const uint32_t capac constexpr uint32_t INTERNALLY_RESERVED_INDICES{1U}; IOX_ENFORCE(capacity < (std::numeric_limits::max() - INTERNALLY_RESERVED_INDICES), "Requested capacity exceeds limits!"); - IOX_ENFORCE(m_head.is_lock_free(), "std::atomic must be lock-free!"); m_nextFreeIndex = freeIndicesMemory; m_size = capacity; diff --git a/iceoryx_hoofs/design/include/iox/detail/polymorphic_handler.inl b/iceoryx_hoofs/design/include/iox/detail/polymorphic_handler.inl index 659da64620..d9a50e215f 100644 --- a/iceoryx_hoofs/design/include/iox/detail/polymorphic_handler.inl +++ b/iceoryx_hoofs/design/include/iox/detail/polymorphic_handler.inl @@ -19,7 +19,7 @@ #include "iox/polymorphic_handler.hpp" #include "iox/static_lifetime_guard.hpp" -#include + #include #include diff --git a/iceoryx_hoofs/design/include/iox/detail/static_lifetime_guard.inl b/iceoryx_hoofs/design/include/iox/detail/static_lifetime_guard.inl index deda54131c..afcd7028ed 100644 --- a/iceoryx_hoofs/design/include/iox/detail/static_lifetime_guard.inl +++ b/iceoryx_hoofs/design/include/iox/detail/static_lifetime_guard.inl @@ -17,9 +17,9 @@ #ifndef IOX_HOOFS_DESIGN_STATIC_LIFETIME_GUARD_INL #define IOX_HOOFS_DESIGN_STATIC_LIFETIME_GUARD_INL +#include "iox/atomic.hpp" #include "iox/static_lifetime_guard.hpp" -#include #include namespace iox @@ -30,9 +30,9 @@ namespace iox template typename StaticLifetimeGuard::storage_t StaticLifetimeGuard::s_storage; template -std::atomic StaticLifetimeGuard::s_count{0}; +concurrent::Atomic StaticLifetimeGuard::s_count{0}; template -std::atomic StaticLifetimeGuard::s_instanceState{UNINITIALIZED}; +concurrent::Atomic StaticLifetimeGuard::s_instanceState{UNINITIALIZED}; template T* StaticLifetimeGuard::s_instance{nullptr}; // NOLINTEND (cppcoreguidelines-avoid-non-const-global-variables) diff --git a/iceoryx_hoofs/design/include/iox/polymorphic_handler.hpp b/iceoryx_hoofs/design/include/iox/polymorphic_handler.hpp index 5ca79371d4..d4d0589f8d 100644 --- a/iceoryx_hoofs/design/include/iox/polymorphic_handler.hpp +++ b/iceoryx_hoofs/design/include/iox/polymorphic_handler.hpp @@ -17,11 +17,11 @@ #ifndef IOX_HOOFS_DESIGN_POLYMORPHIC_HANDLER_HPP #define IOX_HOOFS_DESIGN_POLYMORPHIC_HANDLER_HPP -#include -#include - +#include "iox/atomic.hpp" #include "iox/static_lifetime_guard.hpp" +#include + namespace iox { namespace detail @@ -118,8 +118,8 @@ class PolymorphicHandler // should a defaultHandler be created, the guard prevents its destruction StaticLifetimeGuard m_defaultGuard; - std::atomic_bool m_isFinal{false}; - std::atomic m_current{nullptr}; + concurrent::Atomic m_isFinal{false}; + concurrent::Atomic m_current{nullptr}; }; } // namespace iox diff --git a/iceoryx_hoofs/design/include/iox/static_lifetime_guard.hpp b/iceoryx_hoofs/design/include/iox/static_lifetime_guard.hpp index 361b0bf7b9..b1ee639869 100644 --- a/iceoryx_hoofs/design/include/iox/static_lifetime_guard.hpp +++ b/iceoryx_hoofs/design/include/iox/static_lifetime_guard.hpp @@ -17,7 +17,8 @@ #ifndef IOX_HOOFS_DESIGN_STATIC_LIFETIME_GUARD_HPP #define IOX_HOOFS_DESIGN_STATIC_LIFETIME_GUARD_HPP -#include +#include "iox/atomic.hpp" + #include #include @@ -94,8 +95,8 @@ class StaticLifetimeGuard // NOLINTJUSTIFICATION these static variables are private and mutability is required // NOLINTBEGIN (cppcoreguidelines-avoid-non-const-global-variables) static storage_t s_storage; - static std::atomic s_count; - static std::atomic s_instanceState; + static concurrent::Atomic s_count; + static concurrent::Atomic s_instanceState; static T* s_instance; // NOLINTEND (cppcoreguidelines-avoid-non-const-global-variables) diff --git a/iceoryx_hoofs/posix/ipc/include/iox/named_pipe.hpp b/iceoryx_hoofs/posix/ipc/include/iox/named_pipe.hpp index 8c20ecfcc0..6517654751 100644 --- a/iceoryx_hoofs/posix/ipc/include/iox/named_pipe.hpp +++ b/iceoryx_hoofs/posix/ipc/include/iox/named_pipe.hpp @@ -19,6 +19,7 @@ #define IOX_HOOFS_POSIX_IPC_NAMED_PIPE_HPP #include "iceoryx_platform/semaphore.hpp" +#include "iox/atomic.hpp" #include "iox/builder.hpp" #include "iox/detail/mpmc_lockfree_queue.hpp" #include "iox/duration.hpp" @@ -193,7 +194,7 @@ class NamedPipe static constexpr units::Duration WAIT_FOR_INIT_TIMEOUT = units::Duration::fromSeconds(1); static constexpr units::Duration WAIT_FOR_INIT_SLEEP_TIME = units::Duration::fromMilliseconds(1); - std::atomic initializationGuard{INVALID_DATA}; + concurrent::Atomic initializationGuard{INVALID_DATA}; optional m_sendSemaphore; optional m_receiveSemaphore; }; diff --git a/iceoryx_hoofs/posix/sync/include/iox/signal_watcher.hpp b/iceoryx_hoofs/posix/sync/include/iox/signal_watcher.hpp index e7d745f7f5..8e306d144c 100644 --- a/iceoryx_hoofs/posix/sync/include/iox/signal_watcher.hpp +++ b/iceoryx_hoofs/posix/sync/include/iox/signal_watcher.hpp @@ -17,12 +17,11 @@ #ifndef IOX_HOOFS_POSIX_WRAPPER_SIGNAL_WATCHER_HPP #define IOX_HOOFS_POSIX_WRAPPER_SIGNAL_WATCHER_HPP +#include "iox/atomic.hpp" #include "iox/optional.hpp" #include "iox/signal_handler.hpp" #include "iox/unnamed_semaphore.hpp" -#include - namespace iox { /// @brief The SignalWatcher waits for SIGINT and SIGTERM. One can wait until the @@ -68,10 +67,10 @@ class SignalWatcher private: friend void internalSignalHandler(int) noexcept; - mutable std::atomic m_numberOfWaiters{0U}; + mutable concurrent::Atomic m_numberOfWaiters{0U}; mutable optional m_semaphore; - std::atomic_bool m_hasSignalOccurred{false}; + concurrent::Atomic m_hasSignalOccurred{false}; SignalGuard m_sigTermGuard; SignalGuard m_sigIntGuard; }; diff --git a/iceoryx_hoofs/posix/sync/include/iox/thread.hpp b/iceoryx_hoofs/posix/sync/include/iox/thread.hpp index 26fb78c37a..5e2e0f4e6d 100644 --- a/iceoryx_hoofs/posix/sync/include/iox/thread.hpp +++ b/iceoryx_hoofs/posix/sync/include/iox/thread.hpp @@ -24,7 +24,6 @@ #include "iox/posix_call.hpp" #include "iox/string.hpp" -#include #include namespace iox diff --git a/iceoryx_hoofs/reporting/include/iox/detail/log/building_blocks/logger.inl b/iceoryx_hoofs/reporting/include/iox/detail/log/building_blocks/logger.inl index f5d6583fff..f7525a1890 100644 --- a/iceoryx_hoofs/reporting/include/iox/detail/log/building_blocks/logger.inl +++ b/iceoryx_hoofs/reporting/include/iox/detail/log/building_blocks/logger.inl @@ -20,7 +20,6 @@ #include "iox/log/building_blocks/logger.hpp" -#include #include #include #include diff --git a/iceoryx_hoofs/reporting/include/iox/log/building_blocks/console_logger.hpp b/iceoryx_hoofs/reporting/include/iox/log/building_blocks/console_logger.hpp index dd28bafdc5..f0fcc5b55a 100644 --- a/iceoryx_hoofs/reporting/include/iox/log/building_blocks/console_logger.hpp +++ b/iceoryx_hoofs/reporting/include/iox/log/building_blocks/console_logger.hpp @@ -18,10 +18,10 @@ #ifndef IOX_HOOFS_REPORTING_LOG_BUILDING_BLOCKS_CONSOLE_LOGGER_HPP #define IOX_HOOFS_REPORTING_LOG_BUILDING_BLOCKS_CONSOLE_LOGGER_HPP +#include "iox/atomic.hpp" #include "iox/iceoryx_hoofs_types.hpp" #include "iox/log/building_blocks/logformat.hpp" -#include #include #include #include @@ -138,7 +138,7 @@ class ConsoleLogger private: // NOLINTJUSTIFICATION needed for the functionality and a private member of the class // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) - static std::atomic s_activeLogLevel; // initialized in corresponding cpp file + static concurrent::Atomic s_activeLogLevel; // initialized in corresponding cpp file }; } // namespace log diff --git a/iceoryx_hoofs/reporting/include/iox/log/building_blocks/logger.hpp b/iceoryx_hoofs/reporting/include/iox/log/building_blocks/logger.hpp index 9a2c2a876e..08821e841a 100644 --- a/iceoryx_hoofs/reporting/include/iox/log/building_blocks/logger.hpp +++ b/iceoryx_hoofs/reporting/include/iox/log/building_blocks/logger.hpp @@ -19,9 +19,9 @@ #define IOX_HOOFS_REPORTING_LOG_BUILDING_BLOCKS_LOGGER_HPP #include "iceoryx_platform/logging.hpp" +#include "iox/atomic.hpp" #include "iox/iceoryx_hoofs_types.hpp" -#include #include #include #include @@ -103,8 +103,8 @@ class Logger : public BaseLogger void initLoggerInternal(const LogLevel logLevel) noexcept; private: - std::atomic m_isActive{true}; - std::atomic m_isFinalized{false}; + concurrent::Atomic m_isActive{true}; + concurrent::Atomic m_isFinalized{false}; }; } // namespace internal diff --git a/iceoryx_hoofs/reporting/source/console_logger.cpp b/iceoryx_hoofs/reporting/source/console_logger.cpp index ebd1f780b9..8f7ed35a72 100644 --- a/iceoryx_hoofs/reporting/source/console_logger.cpp +++ b/iceoryx_hoofs/reporting/source/console_logger.cpp @@ -31,7 +31,7 @@ namespace log { // NOLINTJUSTIFICATION See at declaration in header // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) -std::atomic ConsoleLogger::s_activeLogLevel{LogLevel::INFO}; +concurrent::Atomic ConsoleLogger::s_activeLogLevel{LogLevel::INFO}; ConsoleLogger::ThreadLocalData& ConsoleLogger::getThreadLocalData() noexcept { diff --git a/iceoryx_hoofs/test/moduletests/test_concurrent_smart_lock.cpp b/iceoryx_hoofs/test/moduletests/test_concurrent_smart_lock.cpp index 67269909a6..95c6218f26 100644 --- a/iceoryx_hoofs/test/moduletests/test_concurrent_smart_lock.cpp +++ b/iceoryx_hoofs/test/moduletests/test_concurrent_smart_lock.cpp @@ -15,12 +15,12 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/testing/watch_dog.hpp" +#include "iox/atomic.hpp" #include "iox/optional.hpp" #include "iox/smart_lock.hpp" #include "iox/vector.hpp" #include "test.hpp" -#include #include using namespace ::testing; @@ -134,7 +134,7 @@ class smart_lock_test : public Test Watchdog m_watchdog{iox::units::Duration::fromSeconds(60U)}; using SutType_t = smart_lock; iox::optional m_sut; - std::atomic m_numberOfThreadWaiter{0U}; + iox::concurrent::Atomic m_numberOfThreadWaiter{0U}; }; constexpr uint64_t NUMBER_OF_RUNS_PER_THREAD = 100000U; constexpr uint64_t NUMBER_OF_THREADS = 4; diff --git a/iceoryx_hoofs/test/moduletests/test_design_polymorphic_handler.cpp b/iceoryx_hoofs/test/moduletests/test_design_polymorphic_handler.cpp index 0d98b5bedc..8ce6f5f02a 100644 --- a/iceoryx_hoofs/test/moduletests/test_design_polymorphic_handler.cpp +++ b/iceoryx_hoofs/test/moduletests/test_design_polymorphic_handler.cpp @@ -14,11 +14,12 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iox/atomic.hpp" #include "iox/polymorphic_handler.hpp" #include "iox/static_lifetime_guard.hpp" #include "test.hpp" -#include + #include #include #include @@ -180,7 +181,7 @@ TEST_F(PolymorphicHandler_test, defaultHandlerIsVisibleInAllThreads) Handler::set(defaultGuard); - std::atomic count{0}; + iox::concurrent::Atomic count{0}; auto checkHandler = [&]() { auto& h = Handler::get(); @@ -198,7 +199,7 @@ TEST_F(PolymorphicHandler_test, defaultHandlerIsVisibleInAllThreads) checkHandler(); - EXPECT_EQ(count, NUM_THREADS); + EXPECT_EQ(count.load(), NUM_THREADS); } TEST_F(PolymorphicHandler_test, handlerChangePropagatesBetweenThreads) diff --git a/iceoryx_hoofs/test/moduletests/test_posix_ipc_unix_domain_sockets.cpp b/iceoryx_hoofs/test/moduletests/test_posix_ipc_unix_domain_sockets.cpp index df1dee4f10..466ae2bfab 100644 --- a/iceoryx_hoofs/test/moduletests/test_posix_ipc_unix_domain_sockets.cpp +++ b/iceoryx_hoofs/test/moduletests/test_posix_ipc_unix_domain_sockets.cpp @@ -18,13 +18,13 @@ #if !defined(_WIN32) #include "iceoryx_hoofs/testing/timing_test.hpp" #include "iceoryx_platform/socket.hpp" +#include "iox/atomic.hpp" #include "iox/posix_call.hpp" #include "iox/string.hpp" #include "iox/unix_domain_socket.hpp" #include "test.hpp" -#include #include #include @@ -128,7 +128,7 @@ class UnixDomainSocket_test : public Test } const std::chrono::milliseconds WAIT_IN_MS{10}; - std::atomic_bool doWaitForThread{true}; + iox::concurrent::Atomic doWaitForThread{true}; static constexpr uint64_t MaxMsgNumber = 10U; UnixDomainSocket server{UnixDomainSocketBuilder() .name(goodName) @@ -808,4 +808,4 @@ TIMING_TEST_F(UnixDomainSocket_test, TimedReceiveBlocksUntilMessageIsReceivedMsg }) #endif } // namespace -#endif \ No newline at end of file +#endif diff --git a/iceoryx_hoofs/test/moduletests/test_posix_mutex.cpp b/iceoryx_hoofs/test/moduletests/test_posix_mutex.cpp index 27009a1b0d..5bc695d3e5 100644 --- a/iceoryx_hoofs/test/moduletests/test_posix_mutex.cpp +++ b/iceoryx_hoofs/test/moduletests/test_posix_mutex.cpp @@ -17,10 +17,10 @@ #include "iceoryx_hoofs/testing/test.hpp" #include "iceoryx_hoofs/testing/watch_dog.hpp" +#include "iox/atomic.hpp" #include "iox/deadline_timer.hpp" #include "iox/mutex.hpp" -#include #include namespace @@ -63,7 +63,7 @@ class Mutex_test : public Test return std::chrono::duration_cast(end - start).count(); } - std::atomic_bool doWaitForThread{true}; + iox::concurrent::Atomic doWaitForThread{true}; iox::optional sutNonRecursive; iox::optional sutRecursive; iox::units::Duration watchdogTimeout = 5_s; @@ -109,7 +109,7 @@ TEST_F(Mutex_test, RepeatedLockAndUnlockWithNonRecursiveMutexWorks) void tryLockReturnsFalseWhenMutexLockedInOtherThread(mutex& mutex) { - std::atomic tryLockState = {MutexTryLock::LOCK_SUCCEEDED}; + iox::concurrent::Atomic tryLockState{MutexTryLock::LOCK_SUCCEEDED}; ASSERT_FALSE(mutex.lock().has_error()); std::thread lockThread([&] { auto tryLockResult = mutex.try_lock(); diff --git a/iceoryx_hoofs/test/moduletests/test_posix_semaphore_interface.cpp b/iceoryx_hoofs/test/moduletests/test_posix_semaphore_interface.cpp index 438789bd8b..8f0ae6b1a5 100644 --- a/iceoryx_hoofs/test/moduletests/test_posix_semaphore_interface.cpp +++ b/iceoryx_hoofs/test/moduletests/test_posix_semaphore_interface.cpp @@ -28,7 +28,6 @@ #include "test.hpp" #include "test_posix_semaphore_common.hpp" -#include #include #include #include diff --git a/iceoryx_hoofs/test/moduletests/test_posix_signal_handler.cpp b/iceoryx_hoofs/test/moduletests/test_posix_signal_handler.cpp index 877f4d15c7..fcca8241d8 100644 --- a/iceoryx_hoofs/test/moduletests/test_posix_signal_handler.cpp +++ b/iceoryx_hoofs/test/moduletests/test_posix_signal_handler.cpp @@ -14,17 +14,17 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iox/atomic.hpp" #include "iox/signal_handler.hpp" #include "test.hpp" -#include namespace { using namespace ::testing; using namespace iox; -std::atomic_int signalOfCallback1{0}; -std::atomic_int signalOfCallback2{0}; +iox::concurrent::Atomic signalOfCallback1{0}; +iox::concurrent::Atomic signalOfCallback2{0}; template struct SignalType @@ -88,8 +88,8 @@ TYPED_TEST(SignalHandler_test, RegisteringSignalGuardCallbackWorks) ASSERT_EQ(raise(static_cast(signalValue)), 0); - EXPECT_THAT(signalOfCallback1, Eq(static_cast(signalValue))); - EXPECT_THAT(signalOfCallback2, Eq(this->INVALID_SIGNAL)); + EXPECT_THAT(signalOfCallback1.load(), Eq(static_cast(signalValue))); + EXPECT_THAT(signalOfCallback2.load(), Eq(this->INVALID_SIGNAL)); } TYPED_TEST(SignalHandler_test, WhenSignalGuardGoesOutOfScopePreviousStateIsRestored) @@ -103,8 +103,8 @@ TYPED_TEST(SignalHandler_test, WhenSignalGuardGoesOutOfScopePreviousStateIsResto ASSERT_EQ(raise(static_cast(signalValue)), 0); - EXPECT_THAT(signalOfCallback1, Eq(this->INVALID_SIGNAL)); - EXPECT_THAT(signalOfCallback2, Eq(static_cast(signalValue))); + EXPECT_THAT(signalOfCallback1.load(), Eq(this->INVALID_SIGNAL)); + EXPECT_THAT(signalOfCallback2.load(), Eq(static_cast(signalValue))); } TYPED_TEST(SignalHandler_test, MoveConstructedSignalGuardCallbackWorks) @@ -118,8 +118,8 @@ TYPED_TEST(SignalHandler_test, MoveConstructedSignalGuardCallbackWorks) ASSERT_EQ(raise(static_cast(signalValue)), 0); - EXPECT_THAT(signalOfCallback1, Eq(static_cast(signalValue))); - EXPECT_THAT(signalOfCallback2, Eq(this->INVALID_SIGNAL)); + EXPECT_THAT(signalOfCallback1.load(), Eq(static_cast(signalValue))); + EXPECT_THAT(signalOfCallback2.load(), Eq(this->INVALID_SIGNAL)); } TYPED_TEST(SignalHandler_test, MoveConstructedSignalGuardRestoresPreviousState) @@ -136,7 +136,7 @@ TYPED_TEST(SignalHandler_test, MoveConstructedSignalGuardRestoresPreviousState) ASSERT_EQ(raise(static_cast(signalValue)), 0); - EXPECT_THAT(signalOfCallback1, Eq(this->INVALID_SIGNAL)); - EXPECT_THAT(signalOfCallback2, Eq(static_cast(signalValue))); + EXPECT_THAT(signalOfCallback1.load(), Eq(this->INVALID_SIGNAL)); + EXPECT_THAT(signalOfCallback2.load(), Eq(static_cast(signalValue))); } } // namespace diff --git a/iceoryx_hoofs/test/moduletests/test_posix_sync_signal_watcher.cpp b/iceoryx_hoofs/test/moduletests/test_posix_sync_signal_watcher.cpp index ab00e1ebd6..39b09d1666 100644 --- a/iceoryx_hoofs/test/moduletests/test_posix_sync_signal_watcher.cpp +++ b/iceoryx_hoofs/test/moduletests/test_posix_sync_signal_watcher.cpp @@ -16,9 +16,9 @@ #include "iceoryx_hoofs/testing/barrier.hpp" #include "iceoryx_hoofs/testing/watch_dog.hpp" +#include "iox/atomic.hpp" #include "iox/signal_watcher.hpp" #include "test.hpp" -#include namespace { @@ -88,7 +88,7 @@ void unblocksWhenSignalWasRaisedForWaiters(SignalWatcher_test& test, const std::function& wait) { Barrier isThreadStarted(numberOfWaiters); - std::atomic isThreadFinished{0}; + iox::concurrent::Atomic isThreadFinished{0}; std::vector threads; diff --git a/iceoryx_hoofs/test/moduletests/test_time_adaptive_wait.cpp b/iceoryx_hoofs/test/moduletests/test_time_adaptive_wait.cpp index 92a79e214f..7298caceb4 100644 --- a/iceoryx_hoofs/test/moduletests/test_time_adaptive_wait.cpp +++ b/iceoryx_hoofs/test/moduletests/test_time_adaptive_wait.cpp @@ -17,9 +17,9 @@ #include "test.hpp" using namespace ::testing; +#include "iox/atomic.hpp" #include "iox/detail/adaptive_wait.hpp" -#include #include using namespace iox::detail; @@ -88,8 +88,8 @@ TEST(AdaptiveWaitTest, wait_loopWaitsAtLeastAsLongAsTheConditionsReturnsTrue) using adaptive_wait::INITIAL_REPETITIONS; }; - std::atomic_bool continueToWait{true}; - std::atomic_bool threadIsStarted{false}; + iox::concurrent::Atomic continueToWait{true}; + iox::concurrent::Atomic threadIsStarted{false}; std::thread waitThread{[&] { threadIsStarted = true; AdaptiveWaitSut().wait_loop([&] { return continueToWait.load(); }); diff --git a/iceoryx_hoofs/test/moduletests/test_time_deadline_timer.cpp b/iceoryx_hoofs/test/moduletests/test_time_deadline_timer.cpp index 1ebe7af1a9..70bd37f22f 100644 --- a/iceoryx_hoofs/test/moduletests/test_time_deadline_timer.cpp +++ b/iceoryx_hoofs/test/moduletests/test_time_deadline_timer.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/testing/timing_test.hpp" +#include "iox/atomic.hpp" #include "iox/deadline_timer.hpp" #include "iox/duration.hpp" #include "test.hpp" @@ -46,7 +47,7 @@ class DeadlineTimer_test : public Test Duration second{1_s}; - std::atomic numberOfCalls{0}; + iox::concurrent::Atomic numberOfCalls{0}; static const Duration TIMEOUT; static const uint64_t SLEEPTIME; }; diff --git a/iceoryx_hoofs/test/stresstests/benchmark_optional_and_expected/benchmark.hpp b/iceoryx_hoofs/test/stresstests/benchmark_optional_and_expected/benchmark.hpp index 7e8fb72f52..152871fa51 100644 --- a/iceoryx_hoofs/test/stresstests/benchmark_optional_and_expected/benchmark.hpp +++ b/iceoryx_hoofs/test/stresstests/benchmark_optional_and_expected/benchmark.hpp @@ -15,9 +15,9 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iox/atomic.hpp" #include "iox/duration.hpp" -#include #include #include #include @@ -37,7 +37,7 @@ std::string compiler = "msvc-" + std::to_string(_MSC_VER); template void PerformBenchmark(Return (&f)(), const char* functionName, const iox::units::Duration& duration) { - std::atomic_bool keepRunning{true}; + iox::concurrent::Atomic keepRunning{true}; uint64_t numberOfCalls{0U}; uint64_t actualDurationNanoSeconds{0}; std::thread t([&] { diff --git a/iceoryx_hoofs/test/stresstests/sofi/test_stress_spsc_sofi.cpp b/iceoryx_hoofs/test/stresstests/sofi/test_stress_spsc_sofi.cpp index 24453dd3af..1760c8a4dc 100644 --- a/iceoryx_hoofs/test/stresstests/sofi/test_stress_spsc_sofi.cpp +++ b/iceoryx_hoofs/test/stresstests/sofi/test_stress_spsc_sofi.cpp @@ -15,6 +15,7 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iox/atomic.hpp" #include "iox/detail/spsc_sofi.hpp" #include "iox/logging.hpp" @@ -90,10 +91,10 @@ TEST_F(SpscSofiStress, SimultaneouslyPushAndPopOnEmptySoFi) SoFiData popCounter{0}; SoFiData tryPopCounter{0}; SoFiData pushCounter{0}; - std::atomic allowPush{false}; - std::atomic isPushing{false}; - std::atomic stopPushThread{false}; - std::atomic stopPopThread{false}; + iox::concurrent::Atomic allowPush{false}; + iox::concurrent::Atomic isPushing{false}; + iox::concurrent::Atomic stopPushThread{false}; + iox::concurrent::Atomic stopPopThread{false}; auto popThread = std::thread([&] { allowPush = true; @@ -222,11 +223,11 @@ TEST_F(SpscSofiStress, PopFromContinuouslyOverflowingSoFi) SoFiData pushCounter{0}; SoFiData dataCounter{0}; SoFiData popCounter{0}; - std::atomic lastPopValue{INVALID_SOFI_DATA}; - std::atomic allowPop{false}; - std::atomic isPopping{false}; - std::atomic stopPushThread{false}; - std::atomic stopPopThread{false}; + iox::concurrent::Atomic lastPopValue{INVALID_SOFI_DATA}; + iox::concurrent::Atomic allowPop{false}; + iox::concurrent::Atomic isPopping{false}; + iox::concurrent::Atomic stopPushThread{false}; + iox::concurrent::Atomic stopPopThread{false}; auto pushThread = std::thread([&] { SoFiData valOut{INVALID_SOFI_DATA}; @@ -278,9 +279,10 @@ TEST_F(SpscSofiStress, PopFromContinuouslyOverflowingSoFi) // the popped value must match our data counter, because our data counter already didn't match with // the overflow value - if (lastPopValue != dataCounter) + if (lastPopValue.load(std::memory_order_relaxed) != dataCounter) { - EXPECT_THAT(lastPopValue, Eq(dataCounter)) << "There was a data loss!"; + EXPECT_THAT(lastPopValue.load(std::memory_order_relaxed), Eq(dataCounter)) + << "There was a data loss!"; stopPushThread = true; stopPopThread = true; } @@ -371,9 +373,9 @@ TEST_F(SpscSofiStress, PopFromContinuouslyOverflowingSoFi) // after stopping the threads, there might still be values in the SpscSofi and an unchecked popped value; get them // out and check for validity - if (lastPopValue >= 0) + if (lastPopValue.load() >= 0) { - EXPECT_THAT(lastPopValue, Eq(dataCounter)) << "There was a data loss!"; + EXPECT_THAT(lastPopValue.load(), Eq(dataCounter)) << "There was a data loss!"; dataCounter++; } auto valOut{INVALID_SOFI_DATA}; @@ -418,12 +420,12 @@ TEST_F(SpscSofiStress, PushAndPopFromNonOverflowingNonEmptySoFi) using SoFi_t = iox::concurrent::SpscSofi; std::unique_ptr sofi{new SoFi_t}; - std::atomic pushCounter{0}; - std::atomic popCounter{0}; + iox::concurrent::Atomic pushCounter{0}; + iox::concurrent::Atomic popCounter{0}; bool slowDownPush{false}; bool slowDownPop{false}; - std::atomic stopPushThread{false}; - std::atomic stopPopThread{false}; + iox::concurrent::Atomic stopPushThread{false}; + iox::concurrent::Atomic stopPopThread{false}; auto pushThread = std::thread([&] { auto localPushCounter = pushCounter.load(); @@ -530,7 +532,7 @@ TEST_F(SpscSofiStress, PushAndPopFromNonOverflowingNonEmptySoFi) SoFiData valOut{INVALID_SOFI_DATA}; while (sofi->pop(valOut)) { - if (valOut != popCounter) + if (valOut != popCounter.load()) { EXPECT_THAT(valOut, Eq(popCounter.load())) << "There was a data loss!"; break; @@ -539,8 +541,9 @@ TEST_F(SpscSofiStress, PushAndPopFromNonOverflowingNonEmptySoFi) popCounter++; } - EXPECT_THAT(pushCounter / 1000, Gt(STRESS_TIME.count())) << "There should be at least 1000 pushes per millisecond!"; - EXPECT_THAT(pushCounter, Eq(popCounter.load())) << "Push and Pop Counter should be Equal after the Test!"; + EXPECT_THAT(pushCounter.load() / 1000, Gt(STRESS_TIME.count())) + << "There should be at least 1000 pushes per millisecond!"; + EXPECT_THAT(pushCounter.load(), Eq(popCounter.load())) << "Push and Pop Counter should be Equal after the Test!"; IOX_LOG(INFO, "push & pop counter: " << pushCounter.load()); } diff --git a/iceoryx_hoofs/test/stresstests/test_mpmc_lockfree_queue_stresstest.cpp b/iceoryx_hoofs/test/stresstests/test_mpmc_lockfree_queue_stresstest.cpp index 425ab78fae..fb70d307c3 100644 --- a/iceoryx_hoofs/test/stresstests/test_mpmc_lockfree_queue_stresstest.cpp +++ b/iceoryx_hoofs/test/stresstests/test_mpmc_lockfree_queue_stresstest.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/testing/test.hpp" +#include "iox/atomic.hpp" #include "iox/logging.hpp" #include "iox/detail/mpmc_lockfree_queue.hpp" @@ -23,7 +24,6 @@ using namespace ::testing; #include "iceoryx_hoofs/testing/barrier.hpp" -#include #include #include #include @@ -71,8 +71,10 @@ void produce(Queue& queue, uint64_t id, uint64_t iterations) } template -//NOLINTNEXTLINE(bugprone-easily-swappable-parameters, readability-function-size) This is okay since it is limited to the stress test -void consume(Queue& queue, std::atomic& run, uint64_t expectedFinalCount, uint64_t maxId, bool& testResult) +//NOLINTBEGIN(bugprone-easily-swappable-parameters, readability-function-size) This is okay since it is limited to the stress test +void consume( + Queue& queue, iox::concurrent::Atomic& run, uint64_t expectedFinalCount, uint64_t maxId, bool& testResult) +//NOLINTEND(bugprone-easily-swappable-parameters, readability-function-size) { g_barrier.notify(); @@ -111,7 +113,7 @@ void consume(Queue& queue, std::atomic& run, uint64_t expectedFinalCount, /// since this would allow us to run the test much longer (currently we will exhaust memory /// by using the list), but this rework is somewhat nontrivial template -void consumeAndStore(Queue& queue, std::atomic& run, std::list& consumed) +void consumeAndStore(Queue& queue, iox::concurrent::Atomic& run, std::list& consumed) { g_barrier.notify(); @@ -220,7 +222,7 @@ bool checkTwoConsumerResult(std::list& consumed1, // alternates between push and pop template -void work(Queue& queue, uint64_t id, std::atomic& run) +void work(Queue& queue, uint64_t id, iox::concurrent::Atomic& run) { g_barrier.notify(); @@ -269,7 +271,7 @@ template //NOLINTNEXTLINE(readability-function-size) This is okay since it is limited to the stress test void randomWork(Queue& queue, uint64_t id, - std::atomic& run, + iox::concurrent::Atomic& run, uint64_t& overflowCount, std::list& items, double popProbability = 0.5) @@ -371,7 +373,7 @@ TYPED_TEST(MpmcLockFreeQueueStressTest, SingleProducerSingleConsumer) using Queue = typename TestFixture::Queue; auto& queue = this->sut; - std::atomic run{true}; + iox::concurrent::Atomic run{true}; bool testResult{false}; int iterations = 10000000; @@ -395,7 +397,7 @@ TYPED_TEST(MpmcLockFreeQueueStressTest, MultiProducerSingleConsumer) using Queue = typename TestFixture::Queue; auto& queue = this->sut; - std::atomic run{true}; + iox::concurrent::Atomic run{true}; bool testResult{false}; uint64_t iterations = 1000000U; uint64_t numProducers = 8U; @@ -435,7 +437,7 @@ TYPED_TEST(MpmcLockFreeQueueStressTest, MultiProducerTwoConsumer) using Queue = typename TestFixture::Queue; auto& queue = this->sut; - std::atomic run{true}; + iox::concurrent::Atomic run{true}; uint64_t iterations = 1000000U; uint64_t numProducers = 4; @@ -495,7 +497,7 @@ TYPED_TEST(MpmcLockFreeQueueStressTest, TimedMultiProducerMultiConsumer) } } - std::atomic run{true}; + iox::concurrent::Atomic run{true}; std::vector threads; @@ -559,7 +561,7 @@ TYPED_TEST(MpmcLockFreeQueueStressTest, TimedMultiProducerMultiConsumer0verflow) auto capacity = q.capacity(); - std::atomic run{true}; + iox::concurrent::Atomic run{true}; std::vector threads; std::vector overflowCount(numThreads); diff --git a/iceoryx_hoofs/test/stresstests/test_mpmc_resizeable_lockfree_queue_stresstest.cpp b/iceoryx_hoofs/test/stresstests/test_mpmc_resizeable_lockfree_queue_stresstest.cpp index 054bb4c3df..198eee7567 100644 --- a/iceoryx_hoofs/test/stresstests/test_mpmc_resizeable_lockfree_queue_stresstest.cpp +++ b/iceoryx_hoofs/test/stresstests/test_mpmc_resizeable_lockfree_queue_stresstest.cpp @@ -16,6 +16,7 @@ #include "iceoryx_hoofs/testing/test.hpp" +#include "iox/atomic.hpp" #include "iox/detail/mpmc_resizeable_lockfree_queue.hpp" // Remark: It would be nice to have way to configure the (maximum) runtime in a general way. @@ -25,8 +26,6 @@ using namespace ::testing; #include "iceoryx_hoofs/testing/barrier.hpp" #include "iceoryx_hoofs/testing/watch_dog.hpp" -#include -#include #include #include #include @@ -53,10 +52,10 @@ struct Data // (requires lambdas and/or modification of the functions run by the threads) Barrier g_barrier; -using CountArray = std::vector>; +using CountArray = std::vector>; template -void producePeriodic(Queue& queue, const uint32_t id, CountArray& producedCount, std::atomic_bool& run) +void producePeriodic(Queue& queue, const uint32_t id, CountArray& producedCount, iox::concurrent::Atomic& run) { g_barrier.notify(); @@ -73,7 +72,7 @@ void producePeriodic(Queue& queue, const uint32_t id, CountArray& producedCount, } template -void consume(Queue& queue, CountArray& consumedCount, std::atomic_bool& run) +void consume(Queue& queue, CountArray& consumedCount, iox::concurrent::Atomic& run) { g_barrier.notify(); @@ -90,7 +89,7 @@ void consume(Queue& queue, CountArray& consumedCount, std::atomic_bool& run) } template -void produceMonotonic(Queue& queue, const uint32_t id, std::atomic_bool& run) +void produceMonotonic(Queue& queue, const uint32_t id, iox::concurrent::Atomic& run) { g_barrier.notify(); @@ -104,9 +103,13 @@ void produceMonotonic(Queue& queue, const uint32_t id, std::atomic_bool& run) } } +//NOLINTBEGIN(bugprone-easily-swappable-parameters) This is okay since it is limited to the stress test template -//NOLINTNEXTLINE(bugprone-easily-swappable-parameters) This is okay since it is limited to the stress test -void consumeAndCheckOrder(Queue& queue, const uint32_t maxId, std::atomic_bool& run, std::atomic_bool& orderOk) +void consumeAndCheckOrder(Queue& queue, + const uint32_t maxId, + iox::concurrent::Atomic& run, + iox::concurrent::Atomic& orderOk) +//NOLINTEND(bugprone-easily-swappable-parameters) { g_barrier.notify(); @@ -147,7 +150,7 @@ void consumeAndCheckOrder(Queue& queue, const uint32_t maxId, std::atomic_bool& // alternates between push and pop template -void work(Queue& queue, uint32_t id, std::atomic& run) +void work(Queue& queue, uint32_t id, iox::concurrent::Atomic& run) { g_barrier.notify(); @@ -195,7 +198,7 @@ template //NOLINTNEXTLINE(readability-function-size) This is okay since it is limited to the stress test void randomWork(Queue& queue, uint32_t id, - std::atomic& run, + iox::concurrent::Atomic& run, uint64_t numItems, int& overflowCount, std::list& items, @@ -257,7 +260,7 @@ void randomWork(Queue& queue, template //NOLINTNEXTLINE(readability-function-size) This is okay since it is limited to the stress test void changeCapacity(Queue& queue, - std::atomic& run, + iox::concurrent::Atomic& run, std::list& items, std::vector& capacities, uint64_t& numChanges) @@ -408,7 +411,7 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, MultiProducerMultiConsumerComp using Queue = typename TestFixture::Queue; auto& queue = this->sut; - std::atomic_bool run{true}; + iox::concurrent::Atomic run{true}; const int numProducers{4}; const int numConsumers{4}; @@ -482,7 +485,7 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, MultiProducerMultiConsumerOrde using Queue = typename TestFixture::Queue; auto& queue = this->sut; - std::atomic_bool run{true}; + iox::concurrent::Atomic run{true}; const int numProducers{4}; const int numConsumers{4}; @@ -490,7 +493,7 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, MultiProducerMultiConsumerOrde // need only one variable, any consumer that detects an error will set it to false // and no consumer will ever set it to true again - std::atomic_bool orderOk{true}; + iox::concurrent::Atomic orderOk{true}; std::vector producers; std::vector consumers; @@ -552,7 +555,7 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, HybridMultiProducerMultiConsum } } - std::atomic run{true}; + iox::concurrent::Atomic run{true}; std::vector threads; @@ -614,7 +617,7 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, HybridMultiProducerMultiConsum const double popProbability = 0.45; // tends to overflow const auto capacity = q.capacity(); - std::atomic run{true}; + iox::concurrent::Atomic run{true}; std::vector threads; std::vector overflowCount(numThreads); @@ -715,7 +718,7 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, HybridMultiProducerMultiConsum const double popProbability = 0.45; // tends to overflow const auto capacity = q.capacity(); - std::atomic run{true}; + iox::concurrent::Atomic run{true}; std::vector threads; std::vector overflowCount(numThreads); diff --git a/iceoryx_hoofs/testing/error_reporting/testing_error_handler.cpp b/iceoryx_hoofs/testing/error_reporting/testing_error_handler.cpp index a0f3de2d7c..ee2739d70d 100644 --- a/iceoryx_hoofs/testing/error_reporting/testing_error_handler.cpp +++ b/iceoryx_hoofs/testing/error_reporting/testing_error_handler.cpp @@ -62,7 +62,7 @@ void TestingErrorHandler::onReportViolation(er::ErrorDescriptor desc) bool TestingErrorHandler::hasPanicked() const noexcept { - return m_panicked; + return m_panicked.load(std::memory_order_relaxed); } void TestingErrorHandler::reset() noexcept @@ -133,7 +133,7 @@ bool TestingErrorHandler::fatalFailureTestContext(const function_ref tes void TestingErrorHandler::jump() noexcept { - if (m_jumpState == JumpState::Pending) + if (m_jumpState.load(std::memory_order_relaxed) == JumpState::Pending) { // NOLINTNEXTLINE(cert-err52-cpp) exception handling is not used by design longjmp(&m_jumpBuffer[0], JUMPED_INDICATOR); diff --git a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/error_reporting/testing_error_handler.hpp b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/error_reporting/testing_error_handler.hpp index cf2732c53d..52cada5553 100644 --- a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/error_reporting/testing_error_handler.hpp +++ b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/error_reporting/testing_error_handler.hpp @@ -18,6 +18,7 @@ #ifndef IOX_HOOFS_TESTING_ERROR_REPORTING_TESTING_ERROR_HANDLER_HPP #define IOX_HOOFS_TESTING_ERROR_REPORTING_TESTING_ERROR_HANDLER_HPP +#include "iox/atomic.hpp" #include "iox/error_reporting/custom/default/error_handler_interface.hpp" #include "iox/error_reporting/error_logging.hpp" #include "iox/error_reporting/source_location.hpp" @@ -28,7 +29,6 @@ #include "iceoryx_hoofs/testing/test.hpp" -#include #include // we can use this for test code @@ -110,7 +110,7 @@ class TestingErrorHandler : public iox::er::ErrorHandlerInterface static constexpr int JUMPED_INDICATOR{1}; mutable std::mutex m_mutex; - std::atomic m_panicked{false}; + iox::concurrent::Atomic m_panicked{false}; std::vector m_errors; // we track violations separately (leads to simple search) @@ -129,7 +129,7 @@ class TestingErrorHandler : public iox::er::ErrorHandlerInterface // (longjmp does not support this) // We need to ensure though that only one jump buffer is considered by panic and controlling // ownership of the buffer is one way to accomplish that. - std::atomic m_jumpState{JumpState::Obtainable}; + iox::concurrent::Atomic m_jumpState{JumpState::Obtainable}; }; /// @brief This class hooks into gTest to automatically resets the error handler on the start of a test diff --git a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp index 11edb6f9b8..006ebbe82a 100644 --- a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp +++ b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure.hpp @@ -25,7 +25,6 @@ #include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" #include "test.hpp" -#include #include // NOLINTNEXTLINE(hicpp-deprecated-headers) required to work on some platforms diff --git a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/timing_test.hpp b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/timing_test.hpp index 0503e1df17..347bd0ffd1 100644 --- a/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/timing_test.hpp +++ b/iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/timing_test.hpp @@ -17,7 +17,8 @@ #ifndef IOX_HOOFS_TESTUTILS_TIMING_TEST_HPP #define IOX_HOOFS_TESTUTILS_TIMING_TEST_HPP -#include +#include "iox/atomic.hpp" + #include #include #include @@ -36,7 +37,7 @@ /// class MyClass_test : public Test {}; /// /// TIMING_TEST_F(MyClass_test, WaitForSleep, Repeat(3), [&]{ -/// std::atomic_bool threadFinished{false}; +/// iox::concurrent::Atomic threadFinished{false}; /// std::thread t([&]{ sleep(2); threadFinished = true; }); /// /// TIMING_TEST_EXPECT_FALSE(threadFinished.load()); @@ -70,7 +71,7 @@ #define TIMING_TEST_CONSTRUCT(name, testcase, repetition, test, GTestType) \ GTestType(name, TimingTest_##testcase) \ { \ - std::atomic_bool timingTestResult{true}; \ + iox::concurrent::Atomic timingTestResult{true}; \ std::string errorMessages; \ bool testResult = \ iox::utils::testing::performingTimingTest(test, iox::utils::testing::repetition, timingTestResult); \ @@ -129,7 +130,7 @@ class Repeat bool performingTimingTest(const std::function& testCallback, const Repeat repeat, - std::atomic_bool& testResult) noexcept; + concurrent::Atomic& testResult) noexcept; std::string verifyTimingTestResult(const char* file, @@ -137,7 +138,7 @@ std::string verifyTimingTestResult(const char* file, const char* valueStr, const bool value, const bool expected, - std::atomic_bool& result) noexcept; + concurrent::Atomic& result) noexcept; } // namespace testing } // namespace utils diff --git a/iceoryx_hoofs/testing/timing_test.cpp b/iceoryx_hoofs/testing/timing_test.cpp index bf38b3e5dd..b585a0e23c 100644 --- a/iceoryx_hoofs/testing/timing_test.cpp +++ b/iceoryx_hoofs/testing/timing_test.cpp @@ -16,6 +16,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_hoofs/testing/timing_test.hpp" +#include "iox/atomic.hpp" namespace iox { @@ -35,7 +36,7 @@ uint64_t Repeat::repetitions() const noexcept bool performingTimingTest(const std::function& testCallback, const Repeat repeat, - std::atomic_bool& testResult) noexcept + concurrent::Atomic& testResult) noexcept { for (uint64_t i = 0; i < repeat.repetitions(); ++i) { @@ -58,7 +59,7 @@ std::string verifyTimingTestResult(const char* file, const char* valueStr, const bool value, const bool expected, - std::atomic_bool& result) noexcept + concurrent::Atomic& result) noexcept { std::string errorMessage; if (value != expected) diff --git a/iceoryx_hoofs/utility/include/iox/detail/unique_id.hpp b/iceoryx_hoofs/utility/include/iox/detail/unique_id.hpp index 3af0afa2bf..816525fc94 100644 --- a/iceoryx_hoofs/utility/include/iox/detail/unique_id.hpp +++ b/iceoryx_hoofs/utility/include/iox/detail/unique_id.hpp @@ -17,10 +17,9 @@ #ifndef IOX_HOOFS_UTILITY_UNIQUE_ID_HPP #define IOX_HOOFS_UTILITY_UNIQUE_ID_HPP +#include "iox/atomic.hpp" #include "iox/newtype.hpp" -#include - namespace iox { /// @brief Unique IDs within a process starting with 1. Monotonic increasing IDs are @@ -47,7 +46,7 @@ class UniqueId : public NewType m_IdCounter; // initialized in corresponding cpp file + static concurrent::Atomic m_IdCounter; // initialized in corresponding cpp file }; } // namespace iox diff --git a/iceoryx_hoofs/utility/source/unique_id.cpp b/iceoryx_hoofs/utility/source/unique_id.cpp index edfc837c0e..568bc4b497 100644 --- a/iceoryx_hoofs/utility/source/unique_id.cpp +++ b/iceoryx_hoofs/utility/source/unique_id.cpp @@ -21,7 +21,7 @@ namespace iox // start with 1, just in case we want to use 0 for a special purpose later on // NOLINTJUSTIFICATION see argument in header // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) -std::atomic UniqueId::m_IdCounter{1U}; +concurrent::Atomic UniqueId::m_IdCounter{1U}; UniqueId::UniqueId() noexcept : ThisType(newtype::internal::ProtectedConstructor, m_IdCounter.fetch_add(1U, std::memory_order_relaxed)) diff --git a/iceoryx_platform/generic/source/logging.cpp b/iceoryx_platform/generic/source/logging.cpp index 9a8bb817e5..b660ac5262 100644 --- a/iceoryx_platform/generic/source/logging.cpp +++ b/iceoryx_platform/generic/source/logging.cpp @@ -15,8 +15,8 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_platform/logging.hpp" +#include "iceoryx_platform/atomic.hpp" -#include #include #include #include @@ -77,8 +77,8 @@ enum class LoggerExchangeState : uint8_t struct IceoryxPlatformLogger { - std::atomic log_backend{&iox_platform_detail_default_log_backend}; - std::atomic logger_exchange_state{LoggerExchangeState::DEFAULT}; + iox::concurrent::Atomic log_backend{&iox_platform_detail_default_log_backend}; + iox::concurrent::Atomic logger_exchange_state{LoggerExchangeState::DEFAULT}; }; IceoryxPlatformLogger& active_logger(IceoryxPlatformLogBackend new_log_backend) diff --git a/iceoryx_platform/mac/include/iceoryx_platform/semaphore.hpp b/iceoryx_platform/mac/include/iceoryx_platform/semaphore.hpp index 899c886279..853f033ac5 100644 --- a/iceoryx_platform/mac/include/iceoryx_platform/semaphore.hpp +++ b/iceoryx_platform/mac/include/iceoryx_platform/semaphore.hpp @@ -17,7 +17,8 @@ #ifndef IOX_HOOFS_MAC_PLATFORM_SEMAPHORE_HPP #define IOX_HOOFS_MAC_PLATFORM_SEMAPHORE_HPP -#include +#include "iceoryx_platform/atomic.hpp" + #include #include #include @@ -47,7 +48,7 @@ struct iox_sem_t } m_handle; bool m_hasPosixHandle{true}; - std::atomic m_value{0U}; + iox::concurrent::Atomic m_value{0U}; }; int iox_sem_getvalue(iox_sem_t* sem, int* sval); diff --git a/iceoryx_platform/mac/include/iceoryx_platform/time.hpp b/iceoryx_platform/mac/include/iceoryx_platform/time.hpp index a31d4291fa..34ff3da970 100644 --- a/iceoryx_platform/mac/include/iceoryx_platform/time.hpp +++ b/iceoryx_platform/mac/include/iceoryx_platform/time.hpp @@ -17,7 +17,6 @@ #ifndef IOX_HOOFS_MAC_PLATFORM_TIME_HPP #define IOX_HOOFS_MAC_PLATFORM_TIME_HPP -#include #include #include #include diff --git a/iceoryx_platform/test/moduletests/test_platform_logging.cpp b/iceoryx_platform/test/moduletests/test_platform_logging.cpp index bf4f50316f..181eda7669 100644 --- a/iceoryx_platform/test/moduletests/test_platform_logging.cpp +++ b/iceoryx_platform/test/moduletests/test_platform_logging.cpp @@ -14,11 +14,11 @@ // // SPDX-License-Identifier: Apache-2.0 +#include "iceoryx_platform/atomic.hpp" #include "iceoryx_platform/logging.hpp" #include "test.hpp" -#include #include #include #include @@ -30,9 +30,9 @@ namespace using namespace ::testing; // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) for testing only -std::atomic has_custom_backend{false}; +iox::concurrent::Atomic has_custom_backend{false}; // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) for testing only -std::atomic dummy_backend_output_counter{0}; +iox::concurrent::Atomic dummy_backend_output_counter{0}; class LogOutput { @@ -143,13 +143,13 @@ TEST(Logging_test, SettingCustomBackendTwiceFails) ASSERT_TRUE(has_custom_backend); constexpr uint64_t DUMMY_MESSAGE_COUNT_AFTER_FAILED_SETUP{1}; - ASSERT_THAT(dummy_backend_output_counter, Eq(0)); + ASSERT_THAT(dummy_backend_output_counter.load(), Eq(0)); iox_platform_set_log_backend(&dummy_log_backend); - ASSERT_THAT(dummy_backend_output_counter, Eq(DUMMY_MESSAGE_COUNT_AFTER_FAILED_SETUP)); + ASSERT_THAT(dummy_backend_output_counter.load(), Eq(DUMMY_MESSAGE_COUNT_AFTER_FAILED_SETUP)); IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_INFO, "Hypnotoad"); - ASSERT_THAT(dummy_backend_output_counter, Eq(DUMMY_MESSAGE_COUNT_AFTER_FAILED_SETUP)); + ASSERT_THAT(dummy_backend_output_counter.load(), Eq(DUMMY_MESSAGE_COUNT_AFTER_FAILED_SETUP)); } } // namespace diff --git a/iceoryx_platform/win/include/iceoryx_platform/unique_system_id.hpp b/iceoryx_platform/win/include/iceoryx_platform/unique_system_id.hpp index 25fb8fc155..0864cf237b 100644 --- a/iceoryx_platform/win/include/iceoryx_platform/unique_system_id.hpp +++ b/iceoryx_platform/win/include/iceoryx_platform/unique_system_id.hpp @@ -16,7 +16,8 @@ #ifndef IOX_HOOFS_WIN_PLATFORM_UNIQUE_SYSTEM_ID_HPP #define IOX_HOOFS_WIN_PLATFORM_UNIQUE_SYSTEM_ID_HPP -#include +#include "iceoryx_platform/atomic.hpp" + #include #include @@ -44,7 +45,7 @@ class UniqueSystemId uint64_t m_timestamp = 0U; uint64_t m_sequenceNumber = 0U; - static std::atomic sequenceCounter; + static iox::concurrent::Atomic sequenceCounter; }; #endif diff --git a/iceoryx_platform/win/source/unique_system_id.cpp b/iceoryx_platform/win/source/unique_system_id.cpp index 2c60a1d882..89b11b5d59 100644 --- a/iceoryx_platform/win/source/unique_system_id.cpp +++ b/iceoryx_platform/win/source/unique_system_id.cpp @@ -15,13 +15,14 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_platform/unique_system_id.hpp" +#include "iceoryx_platform/atomic.hpp" #include "iceoryx_platform/windows.hpp" #include #include -std::atomic UniqueSystemId::sequenceCounter{0U}; +iox::concurrent::Atomic UniqueSystemId::sequenceCounter{0U}; UniqueSystemId::UniqueSystemId() noexcept : m_processId{GetCurrentProcessId()} diff --git a/iceoryx_posh/include/iceoryx_posh/gateway/gateway_generic.hpp b/iceoryx_posh/include/iceoryx_posh/gateway/gateway_generic.hpp index 4529717969..f14f4ceb44 100644 --- a/iceoryx_posh/include/iceoryx_posh/gateway/gateway_generic.hpp +++ b/iceoryx_posh/include/iceoryx_posh/gateway/gateway_generic.hpp @@ -23,6 +23,7 @@ #include "iceoryx_posh/gateway/gateway_config.hpp" #include "iceoryx_posh/iceoryx_posh_config.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iox/atomic.hpp" #include "iox/duration.hpp" #include "iox/expected.hpp" #include "iox/function_ref.hpp" @@ -31,7 +32,6 @@ #include "iox/string.hpp" #include "iox/vector.hpp" -#include #include namespace iox @@ -140,7 +140,7 @@ class GatewayGeneric : public gateway_t private: ConcurrentChannelVector m_channels; - std::atomic_bool m_isRunning{false}; + concurrent::Atomic m_isRunning{false}; units::Duration m_discoveryPeriod; units::Duration m_forwardingPeriod; diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/chunk_management.hpp b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/chunk_management.hpp index 1128a05cf8..6f3d905bb9 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/chunk_management.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/chunk_management.hpp @@ -17,10 +17,10 @@ #ifndef IOX_POSH_MEPOO_CHUNK_MANAGEMENT_HPP #define IOX_POSH_MEPOO_CHUNK_MANAGEMENT_HPP +#include "iox/atomic.hpp" #include "iox/not_null.hpp" #include "iox/relative_pointer.hpp" -#include #include namespace iox @@ -34,7 +34,7 @@ struct ChunkManagement { using base_t = ChunkHeader; using referenceCounterBase_t = uint64_t; - using referenceCounter_t = std::atomic; + using referenceCounter_t = concurrent::Atomic; ChunkManagement(const not_null chunkHeader, const not_null mempool, diff --git a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mem_pool.hpp b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mem_pool.hpp index 0627997475..0609928461 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mem_pool.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/mepoo/mem_pool.hpp @@ -20,11 +20,11 @@ #include "iceoryx_posh/mepoo/chunk_header.hpp" #include "iox/algorithm.hpp" +#include "iox/atomic.hpp" #include "iox/bump_allocator.hpp" #include "iox/detail/mpmc_loffli.hpp" #include "iox/relative_pointer.hpp" -#include #include @@ -96,8 +96,8 @@ class MemPool /// (cas is only 64 bit and we need the other 32 bit for the aba counter) uint32_t m_numberOfChunks{0U}; - std::atomic m_usedChunks{0U}; - std::atomic m_minFree{0U}; + concurrent::Atomic m_usedChunks{0U}; + concurrent::Atomic m_minFree{0U}; freeList_t m_freeIndices; }; diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_queue_data.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_queue_data.hpp index e4def6059e..8bc9eaab55 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_queue_data.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/chunk_queue_data.hpp @@ -22,6 +22,7 @@ #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp" #include "iceoryx_posh/internal/popo/building_blocks/variant_queue.hpp" #include "iceoryx_posh/popo/port_queue_policies.hpp" +#include "iox/atomic.hpp" #include "iox/detail/unique_id.hpp" #include "iox/relative_pointer.hpp" @@ -44,7 +45,7 @@ struct ChunkQueueData : public LockingPolicy static constexpr uint64_t MAX_CAPACITY = ChunkQueueDataProperties_t::MAX_QUEUE_CAPACITY; VariantQueue m_queue; - std::atomic_bool m_queueHasLostChunks{false}; + concurrent::Atomic m_queueHasLostChunks{false}; RelativePointer m_conditionVariableDataPtr; optional m_conditionVariableNotificationIndex; diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_listener.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_listener.hpp index c3f570ab21..48cc9b0eb2 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_listener.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_listener.hpp @@ -20,6 +20,7 @@ #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp" #include "iceoryx_posh/mepoo/memory_info.hpp" #include "iox/algorithm.hpp" +#include "iox/atomic.hpp" namespace iox { @@ -76,7 +77,7 @@ class ConditionListener private: ConditionVariableData* m_condVarDataPtr{nullptr}; - std::atomic_bool m_toBeDestroyed{false}; + concurrent::Atomic m_toBeDestroyed{false}; }; } // namespace popo diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp index 6483a72316..532539c19a 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp @@ -19,10 +19,9 @@ #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/posh_error_reporting.hpp" +#include "iox/atomic.hpp" #include "iox/unnamed_semaphore.hpp" -#include - namespace iox { namespace popo @@ -40,9 +39,9 @@ struct ConditionVariableData optional m_semaphore; RuntimeName_t m_runtimeName; - std::atomic_bool m_toBeDestroyed{false}; - std::atomic_bool m_activeNotifications[MAX_NUMBER_OF_NOTIFIERS]; - std::atomic_bool m_wasNotified{false}; + concurrent::Atomic m_toBeDestroyed{false}; + concurrent::Atomic m_activeNotifications[MAX_NUMBER_OF_NOTIFIERS]; + concurrent::Atomic m_wasNotified{false}; }; } // namespace popo diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp index 60b9fdb19e..68cece59bc 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp @@ -19,9 +19,9 @@ #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/posh_error_reporting.hpp" +#include "iox/atomic.hpp" #include "iox/newtype.hpp" -#include #include namespace iox @@ -77,7 +77,7 @@ class UniquePortId : public NewType globalIDCounter; // initialized in cpp file + static concurrent::Atomic globalIDCounter; // initialized in cpp file }; } // namespace popo diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/base_port_data.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/base_port_data.hpp index 6076ee38d6..12d6d845db 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/base_port_data.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/base_port_data.hpp @@ -21,10 +21,9 @@ #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/capro/capro_message.hpp" #include "iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp" +#include "iox/atomic.hpp" #include "iox/relative_pointer.hpp" -#include - namespace iox { namespace popo @@ -50,7 +49,7 @@ struct BasePortData capro::ServiceDescription m_serviceDescription; RuntimeName_t m_runtimeName; UniquePortId m_uniqueId; - std::atomic_bool m_toBeDestroyed{false}; + concurrent::Atomic m_toBeDestroyed{false}; }; } // namespace popo diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/client_port_data.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/client_port_data.hpp index 7b08d51a92..6bfedcb128 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/client_port_data.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/client_port_data.hpp @@ -24,8 +24,8 @@ #include "iceoryx_posh/internal/popo/ports/client_server_port_types.hpp" #include "iceoryx_posh/popo/client_options.hpp" #include "iceoryx_posh/popo/rpc_header.hpp" +#include "iox/atomic.hpp" -#include #include namespace iox @@ -45,8 +45,8 @@ struct ClientPortData : public BasePortData ClientChunkSenderData_t m_chunkSenderData; ClientChunkReceiverData_t m_chunkReceiverData; - std::atomic_bool m_connectRequested{false}; - std::atomic m_connectionState{ConnectionState::NOT_CONNECTED}; + concurrent::Atomic m_connectRequested{false}; + concurrent::Atomic m_connectionState{ConnectionState::NOT_CONNECTED}; }; } // namespace popo diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/publisher_port_data.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/publisher_port_data.hpp index f0fd09f825..30484bc6e2 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/publisher_port_data.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/publisher_port_data.hpp @@ -27,8 +27,8 @@ #include "iceoryx_posh/internal/popo/ports/subscriber_port_data.hpp" #include "iceoryx_posh/mepoo/memory_info.hpp" #include "iceoryx_posh/popo/publisher_options.hpp" +#include "iox/atomic.hpp" -#include #include namespace iox @@ -54,8 +54,8 @@ struct PublisherPortData : public BasePortData PublisherOptions m_options; - std::atomic_bool m_offeringRequested{false}; - std::atomic_bool m_offered{false}; + concurrent::Atomic m_offeringRequested{false}; + concurrent::Atomic m_offered{false}; }; } // namespace popo diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/server_port_data.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/server_port_data.hpp index 8c6237af21..ecd5cf4777 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/server_port_data.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/server_port_data.hpp @@ -23,8 +23,8 @@ #include "iceoryx_posh/internal/popo/ports/base_port_data.hpp" #include "iceoryx_posh/internal/popo/ports/client_server_port_types.hpp" #include "iceoryx_posh/popo/server_options.hpp" +#include "iox/atomic.hpp" -#include #include namespace iox @@ -42,8 +42,8 @@ struct ServerPortData : public BasePortData ServerChunkSenderData_t m_chunkSenderData; ServerChunkReceiverData_t m_chunkReceiverData; - std::atomic_bool m_offeringRequested{false}; - std::atomic_bool m_offered{false}; + concurrent::Atomic m_offeringRequested{false}; + concurrent::Atomic m_offered{false}; static constexpr uint64_t HISTORY_REQUEST_OF_ZERO{0U}; }; diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/subscriber_port_data.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/subscriber_port_data.hpp index 26c812df02..6cbbcf656b 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/subscriber_port_data.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/ports/subscriber_port_data.hpp @@ -23,8 +23,7 @@ #include "iceoryx_posh/internal/popo/ports/base_port_data.hpp" #include "iceoryx_posh/internal/popo/ports/pub_sub_port_types.hpp" #include "iceoryx_posh/popo/subscriber_options.hpp" - -#include +#include "iox/atomic.hpp" namespace iox { @@ -50,8 +49,8 @@ struct SubscriberPortData : public BasePortData SubscriberOptions m_options; - std::atomic_bool m_subscribeRequested{false}; - std::atomic m_subscriptionState{SubscribeState::NOT_SUBSCRIBED}; + concurrent::Atomic m_subscribeRequested{false}; + concurrent::Atomic m_subscriptionState{SubscribeState::NOT_SUBSCRIBED}; }; } // namespace popo diff --git a/iceoryx_posh/include/iceoryx_posh/internal/popo/used_chunk_list.hpp b/iceoryx_posh/include/iceoryx_posh/internal/popo/used_chunk_list.hpp index 8eda98bbb4..1fa92a32be 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/popo/used_chunk_list.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/popo/used_chunk_list.hpp @@ -20,8 +20,8 @@ #include "iceoryx_posh/internal/mepoo/shared_chunk.hpp" #include "iceoryx_posh/internal/mepoo/shm_safe_unmanaged_chunk.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" +#include "iox/atomic.hpp" -#include #include namespace iox @@ -75,7 +75,7 @@ class UsedChunkList static constexpr DataElement_t DATA_ELEMENT_LOGICAL_NULLPTR{}; private: - std::atomic_flag m_synchronizer = ATOMIC_FLAG_INIT; + concurrent::AtomicFlag m_synchronizer = ATOMIC_FLAG_INIT; uint32_t m_usedListHead{INVALID_INDEX}; uint32_t m_freeListHead{0u}; uint32_t m_listIndices[Capacity]; diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/port_introspection.hpp b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/port_introspection.hpp index b485237e84..ce9f0ef534 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/port_introspection.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/port_introspection.hpp @@ -21,11 +21,11 @@ #include "iceoryx_posh/internal/popo/ports/publisher_port_data.hpp" #include "iceoryx_posh/roudi/introspection_types.hpp" #include "iox/assertions.hpp" +#include "iox/atomic.hpp" #include "iox/detail/periodic_task.hpp" #include "iox/fixed_position_container.hpp" #include "iox/function.hpp" -#include #include #include @@ -221,7 +221,7 @@ class PortIntrospection PublisherContainer m_publisherContainer; ConnectionContainer m_connectionContainer; - std::atomic m_newData; + concurrent::Atomic m_newData; std::mutex m_mutex; }; diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/process.hpp b/iceoryx_posh/include/iceoryx_posh/internal/roudi/process.hpp index 41659087a8..d683051409 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/process.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/process.hpp @@ -23,6 +23,7 @@ #include "iceoryx_posh/mepoo/chunk_header.hpp" #include "iceoryx_posh/roudi/heartbeat_pool.hpp" #include "iceoryx_posh/version/version_info.hpp" +#include "iox/atomic.hpp" #include "iox/posix_user.hpp" #include @@ -79,7 +80,7 @@ class Process runtime::IpcInterfaceUser m_ipcChannel; HeartbeatPoolIndexType m_heartbeatPoolIndex; PosixUser m_user; - std::atomic m_sessionId{0U}; + concurrent::Atomic m_sessionId{0U}; }; } // namespace roudi diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp b/iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp index 57b8e1303b..ee11585a3c 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp @@ -27,6 +27,7 @@ #include "iceoryx_posh/roudi/memory/roudi_memory_manager.hpp" #include "iceoryx_posh/roudi/roudi_app.hpp" #include "iceoryx_posh/roudi/roudi_config.hpp" +#include "iox/atomic.hpp" #include "iox/posix_user.hpp" #include "iox/relative_pointer.hpp" #include "iox/scope_guard.hpp" @@ -104,8 +105,8 @@ class RouDi ScopeGuard m_unregisterRelativePtr{[] { UntypedRelativePointer::unregisterAll(); }}; const config::RouDiConfig m_roudiConfig; - std::atomic_bool m_runMonitoringAndDiscoveryThread; - std::atomic_bool m_runHandleRuntimeMessageThread; + concurrent::Atomic m_runMonitoringAndDiscoveryThread; + concurrent::Atomic m_runHandleRuntimeMessageThread; popo::UserTrigger m_discoveryLoopTrigger; optional m_discoveryFinishedSemaphore; diff --git a/iceoryx_posh/include/iceoryx_posh/internal/runtime/heartbeat.hpp b/iceoryx_posh/include/iceoryx_posh/internal/runtime/heartbeat.hpp index 33ad6f1c16..0ca04bb912 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/runtime/heartbeat.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/runtime/heartbeat.hpp @@ -17,7 +17,9 @@ #ifndef IOX_POSH_RUNTIME_HEARTBEAT_HPP #define IOX_POSH_RUNTIME_HEARTBEAT_HPP -#include +#include "iox/atomic.hpp" + +#include namespace iox { @@ -45,7 +47,7 @@ class Heartbeat static uint64_t milliseconds_since_epoch() noexcept; private: - std::atomic m_timestamp_last_beat{0}; + concurrent::Atomic m_timestamp_last_beat{0}; }; } // namespace runtime } // namespace iox diff --git a/iceoryx_posh/include/iceoryx_posh/popo/listener.hpp b/iceoryx_posh/include/iceoryx_posh/popo/listener.hpp index 3ce7410cfe..f8397a32b0 100644 --- a/iceoryx_posh/include/iceoryx_posh/popo/listener.hpp +++ b/iceoryx_posh/include/iceoryx_posh/popo/listener.hpp @@ -23,6 +23,7 @@ #include "iceoryx_posh/popo/notification_callback.hpp" #include "iceoryx_posh/popo/trigger_handle.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" +#include "iox/atomic.hpp" #include "iox/detail/mpmc_loffli.hpp" #include "iox/expected.hpp" #include "iox/function.hpp" @@ -203,7 +204,7 @@ class Listener MpmcLoFFLi::Index_t m_loffliStorage[MpmcLoFFLi::requiredIndexMemorySize(MAX_NUMBER_OF_EVENTS) / sizeof(uint32_t)]; MpmcLoFFLi m_loffli; - std::atomic m_indicesInUse{0U}; + concurrent::Atomic m_indicesInUse{0U}; } m_indexManager; @@ -211,7 +212,7 @@ class Listener concurrent::smart_lock m_events[MAX_NUMBER_OF_EVENTS]; std::mutex m_addEventMutex; - std::atomic_bool m_wasDtorCalled{false}; + concurrent::Atomic m_wasDtorCalled{false}; ConditionVariableData* m_conditionVariableData = nullptr; ConditionListener m_conditionListener; }; diff --git a/iceoryx_posh/include/iceoryx_posh/popo/user_trigger.hpp b/iceoryx_posh/include/iceoryx_posh/popo/user_trigger.hpp index b970f811e7..6da828bfc2 100644 --- a/iceoryx_posh/include/iceoryx_posh/popo/user_trigger.hpp +++ b/iceoryx_posh/include/iceoryx_posh/popo/user_trigger.hpp @@ -20,7 +20,6 @@ #include "iceoryx_posh/popo/trigger.hpp" #include "iceoryx_posh/popo/wait_set.hpp" -#include #include namespace iox diff --git a/iceoryx_posh/include/iceoryx_posh/runtime/posh_runtime.hpp b/iceoryx_posh/include/iceoryx_posh/runtime/posh_runtime.hpp index b9f87361e7..fc7ab782c3 100644 --- a/iceoryx_posh/include/iceoryx_posh/runtime/posh_runtime.hpp +++ b/iceoryx_posh/include/iceoryx_posh/runtime/posh_runtime.hpp @@ -30,11 +30,10 @@ #include "iceoryx_posh/popo/server_options.hpp" #include "iceoryx_posh/popo/subscriber_options.hpp" #include "iceoryx_posh/runtime/port_config_info.hpp" +#include "iox/atomic.hpp" #include "iox/optional.hpp" #include "iox/scope_guard.hpp" -#include - namespace iox { namespace roudi_env @@ -181,7 +180,7 @@ class PoshRuntime const RuntimeName_t& verifyInstanceName(optional name) noexcept; const RuntimeName_t m_appName; - std::atomic m_shutdownRequested{false}; + concurrent::Atomic m_shutdownRequested{false}; }; } // namespace runtime diff --git a/iceoryx_posh/roudi_env/include/iceoryx_posh/roudi_env/runtime_test_interface.hpp b/iceoryx_posh/roudi_env/include/iceoryx_posh/roudi_env/runtime_test_interface.hpp index 85db1f3ebc..ffb56bd68d 100644 --- a/iceoryx_posh/roudi_env/include/iceoryx_posh/roudi_env/runtime_test_interface.hpp +++ b/iceoryx_posh/roudi_env/include/iceoryx_posh/roudi_env/runtime_test_interface.hpp @@ -18,9 +18,9 @@ #define IOX_POSH_ROUDI_ENVIRONMENT_RUNTIME_TEST_INTERFACE_HPP #include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iox/atomic.hpp" #include "iox/optional.hpp" -#include #include #include @@ -42,8 +42,8 @@ class RuntimeTestInterface bool m_doCleanupOnDestruction{true}; thread_local static runtime::PoshRuntime* t_activeRuntime; - thread_local static std::atomic t_currentRouDiContext; - static std::atomic s_currentRouDiContext; + thread_local static concurrent::Atomic t_currentRouDiContext; + static concurrent::Atomic s_currentRouDiContext; static std::mutex s_runtimeAccessMutex; diff --git a/iceoryx_posh/roudi_env/source/runtime_test_interface.cpp b/iceoryx_posh/roudi_env/source/runtime_test_interface.cpp index a4417301ed..4573f83c15 100644 --- a/iceoryx_posh/roudi_env/source/runtime_test_interface.cpp +++ b/iceoryx_posh/roudi_env/source/runtime_test_interface.cpp @@ -18,6 +18,7 @@ #include "iceoryx_posh/roudi_env/runtime_test_interface.hpp" #include "iceoryx_posh/internal/runtime/posh_runtime_impl.hpp" #include "iox/assertions.hpp" +#include "iox/atomic.hpp" namespace iox { @@ -26,8 +27,8 @@ namespace roudi_env using runtime::PoshRuntime; thread_local PoshRuntime* RuntimeTestInterface::t_activeRuntime{nullptr}; -thread_local std::atomic RuntimeTestInterface::t_currentRouDiContext{0}; -std::atomic RuntimeTestInterface::s_currentRouDiContext{0}; +thread_local concurrent::Atomic RuntimeTestInterface::t_currentRouDiContext{0}; +concurrent::Atomic RuntimeTestInterface::s_currentRouDiContext{0}; std::mutex RuntimeTestInterface::s_runtimeAccessMutex; diff --git a/iceoryx_posh/source/iceoryx_posh_types.cpp b/iceoryx_posh/source/iceoryx_posh_types.cpp index 6e1fd48d56..b4d8ac24e6 100644 --- a/iceoryx_posh/source/iceoryx_posh_types.cpp +++ b/iceoryx_posh/source/iceoryx_posh_types.cpp @@ -15,10 +15,9 @@ // SPDX-License-Identifier: Apache-2.0 #include "iceoryx_posh/iceoryx_posh_types.hpp" +#include "iox/atomic.hpp" #include "iox/size.hpp" -#include - namespace iox { @@ -47,7 +46,7 @@ namespace experimental { bool hasExperimentalPoshFeaturesEnabled(const optional& newValue) noexcept { - static std::atomic experimentalEnabled{build::IOX_EXPERIMENTAL_POSH_FLAG}; + static concurrent::Atomic experimentalEnabled{build::IOX_EXPERIMENTAL_POSH_FLAG}; if (newValue.has_value()) { diff --git a/iceoryx_posh/source/popo/building_blocks/unique_port_id.cpp b/iceoryx_posh/source/popo/building_blocks/unique_port_id.cpp index 116481b5f2..7dc8264477 100644 --- a/iceoryx_posh/source/popo/building_blocks/unique_port_id.cpp +++ b/iceoryx_posh/source/popo/building_blocks/unique_port_id.cpp @@ -18,13 +18,14 @@ #include "iceoryx_posh/internal/popo/building_blocks/unique_port_id.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/posh_error_reporting.hpp" +#include "iox/atomic.hpp" namespace iox { namespace popo { // start with 1 to prevent accidentally generating an invalid ID when unique roudi ID is 0 -std::atomic UniquePortId::globalIDCounter{1U}; +concurrent::Atomic UniquePortId::globalIDCounter{1U}; UniquePortId::UniquePortId(const roudi::UniqueRouDiId uniqueRouDiId) noexcept : ThisType(newtype::internal::ProtectedConstructor, diff --git a/iceoryx_posh/source/popo/ports/client_port_user.cpp b/iceoryx_posh/source/popo/ports/client_port_user.cpp index 1dbdd233fc..29cc110809 100644 --- a/iceoryx_posh/source/popo/ports/client_port_user.cpp +++ b/iceoryx_posh/source/popo/ports/client_port_user.cpp @@ -113,7 +113,7 @@ void ClientPortUser::disconnect() noexcept ConnectionState ClientPortUser::getConnectionState() const noexcept { - return getMembers()->m_connectionState; + return getMembers()->m_connectionState.load(std::memory_order_relaxed); } expected ClientPortUser::getResponse() noexcept diff --git a/iceoryx_posh/source/popo/ports/subscriber_port_user.cpp b/iceoryx_posh/source/popo/ports/subscriber_port_user.cpp index 53c89192a4..d2ced21766 100644 --- a/iceoryx_posh/source/popo/ports/subscriber_port_user.cpp +++ b/iceoryx_posh/source/popo/ports/subscriber_port_user.cpp @@ -60,7 +60,7 @@ void SubscriberPortUser::unsubscribe() noexcept SubscribeState SubscriberPortUser::getSubscriptionState() const noexcept { - return getMembers()->m_subscriptionState; + return getMembers()->m_subscriptionState.load(std::memory_order_relaxed); } expected SubscriberPortUser::tryGetChunk() noexcept diff --git a/iceoryx_posh/source/runtime/posh_runtime.cpp b/iceoryx_posh/source/runtime/posh_runtime.cpp index 877b92bd0a..bc84a50dfa 100644 --- a/iceoryx_posh/source/runtime/posh_runtime.cpp +++ b/iceoryx_posh/source/runtime/posh_runtime.cpp @@ -18,11 +18,11 @@ #include "iceoryx_posh/runtime/posh_runtime.hpp" #include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/internal/runtime/posh_runtime_impl.hpp" +#include "iox/atomic.hpp" #include "iox/detail/system_configuration.hpp" #include "iox/filesystem.hpp" #include "iox/logging.hpp" -#include #include #include #include @@ -37,9 +37,9 @@ namespace // A refcount for use in getLifetimeParticipant(). The refcount being > 0 does not // necessarily mean that the runtime is initialized yet, it only controls the point // at which the runtime is destroyed. -std::atomic& poshRuntimeStaticRefCount() +concurrent::Atomic& poshRuntimeStaticRefCount() { - static std::atomic s_refcount{0U}; + static concurrent::Atomic s_refcount{0U}; return s_refcount; } // Tracks whether the refcount lifetime mechanism is used by the factory function. @@ -49,9 +49,9 @@ std::atomic& poshRuntimeStaticRefCount() // classes that are not PoshRuntimeImpl, and also guards against the destructor // being called on a non-existent object in the case where a lifetime participant // goes out of scope before the PoshRuntimeImpl instance was constructed. -std::atomic& poshRuntimeNeedsManualDestruction() +concurrent::Atomic& poshRuntimeNeedsManualDestruction() { - static std::atomic s_needsManualDestruction{false}; + static concurrent::Atomic s_needsManualDestruction{false}; return s_needsManualDestruction; } diff --git a/iceoryx_posh/test/integrationtests/test_client_server.cpp b/iceoryx_posh/test/integrationtests/test_client_server.cpp index d15bc451fc..e6c9ba1a06 100644 --- a/iceoryx_posh/test/integrationtests/test_client_server.cpp +++ b/iceoryx_posh/test/integrationtests/test_client_server.cpp @@ -24,6 +24,7 @@ #include "iceoryx_posh/roudi_env/minimal_iceoryx_config.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" #include "iceoryx_posh/testing/roudi_gtest.hpp" +#include "iox/atomic.hpp" #include "test.hpp" @@ -392,7 +393,7 @@ TEST_F(ClientServer_test, ServerTakeRequestUnblocksClientSendingRequest) ASSERT_TRUE(server.hasClients()); ASSERT_THAT(client.getConnectionState(), Eq(iox::ConnectionState::CONNECTED)); - std::atomic_bool wasRequestSent{false}; + iox::concurrent::Atomic wasRequestSent{false}; // block in a separate thread Barrier isThreadStarted(1U); @@ -453,7 +454,7 @@ TEST_F(ClientServer_test, ClientTakesResponseUnblocksServerSendingResponse) EXPECT_FALSE(clientLoanResult.value().send().has_error()); } - std::atomic_bool wasResponseSent{false}; + iox::concurrent::Atomic wasResponseSent{false}; // block in a separate thread Barrier isThreadStarted(1U); diff --git a/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp b/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp index 4e029d2a6d..6230e7458d 100644 --- a/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp +++ b/iceoryx_posh/test/integrationtests/test_mq_interface_startup_race.cpp @@ -20,6 +20,7 @@ #include "iceoryx_posh/internal/runtime/ipc_message.hpp" #include "iceoryx_posh/internal/runtime/ipc_runtime_interface.hpp" +#include "iox/atomic.hpp" #include "iox/duration.hpp" #include "iox/message_queue.hpp" #include "iox/posix_call.hpp" @@ -134,7 +135,7 @@ TEST_F(CMqInterfaceStartupRace_test, ObsoleteRouDiMq) /// up and tries to use the obsolet mqueue while RouDi gets restarted and cleans its resources up and creates a new /// mqueue - std::atomic shutdown; + iox::concurrent::Atomic shutdown; shutdown = false; auto roudi = std::thread([&] { std::lock_guard lock(m_roudiQueueMutex); @@ -186,7 +187,7 @@ TEST_F(CMqInterfaceStartupRace_test, ObsoleteRouDiMqWithFullMq) /// up and tries to use the obsolet mqueue while RouDi gets restarted and cleans its resources up and creates a new /// mqueue, the obsolete mqueue was filled up to the max message size, e.g. by the KEEP_ALIVE messages - std::atomic shutdown; + iox::concurrent::Atomic shutdown; shutdown = false; auto roudi = std::thread([&] { // fill the roudi mqueue @@ -247,7 +248,7 @@ TEST_F(CMqInterfaceStartupRace_test, ObsoleteRegAck) /// this results in a message in the application mqueue which will be read with the next command and results in a /// wrong response - std::atomic shutdown; + iox::concurrent::Atomic shutdown; shutdown = false; auto roudi = std::thread([&] { std::lock_guard lock(m_roudiQueueMutex); diff --git a/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp b/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp index a487bff0c9..420add5424 100644 --- a/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp +++ b/iceoryx_posh/test/integrationtests/test_popo_chunk_building_blocks.cpp @@ -21,6 +21,7 @@ #include "iceoryx_posh/internal/popo/building_blocks/locking_policy.hpp" #include "iceoryx_posh/internal/popo/ports/base_port.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" +#include "iox/atomic.hpp" #include "iox/scope_guard.hpp" #include "test.hpp" @@ -82,12 +83,14 @@ class ChunkBuildingBlocks_IntegrationTest : public Test EXPECT_THAT(m_memoryManager.getMemPoolInfo(0).m_usedChunks, Eq(1U)); } - void SetUp() + void SetUp() override { ASSERT_FALSE(m_chunkSender.tryAddQueue(&m_chunkQueueData).has_error()); ASSERT_FALSE(m_chunkDistributor.tryAddQueue(&m_chunkReceiverData).has_error()); } - void TearDown(){}; + void TearDown() override + { + } void publish() { @@ -198,8 +201,8 @@ class ChunkBuildingBlocks_IntegrationTest : public Test uint64_t m_sendCounter{0}; uint64_t m_receiveCounter{0}; - std::atomic m_publisherRun{true}; - std::atomic m_forwarderRun{true}; + iox::concurrent::Atomic m_publisherRun{true}; + iox::concurrent::Atomic m_forwarderRun{true}; // Memory objects iox::BumpAllocator m_memoryAllocator{g_memory, MEMORY_SIZE}; diff --git a/iceoryx_posh/test/integrationtests/test_popo_port_user_building_blocks.cpp b/iceoryx_posh/test/integrationtests/test_popo_port_user_building_blocks.cpp index 29153c5c36..63011721ad 100644 --- a/iceoryx_posh/test/integrationtests/test_popo_port_user_building_blocks.cpp +++ b/iceoryx_posh/test/integrationtests/test_popo_port_user_building_blocks.cpp @@ -24,6 +24,7 @@ #include "iceoryx_posh/internal/popo/ports/subscriber_port_single_producer.hpp" #include "iceoryx_posh/internal/popo/ports/subscriber_port_user.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" +#include "iox/atomic.hpp" #include "iox/scope_guard.hpp" #include "iox/smart_lock.hpp" #include "test.hpp" @@ -112,9 +113,9 @@ class PortUser_IntegrationTest : public Test Watchdog m_deadlockWatchdog{DEADLOCK_TIMEOUT}; - std::atomic m_receiveCounter{0U}; - std::atomic m_sendCounter{0U}; - std::atomic m_publisherRunFinished{false}; + iox::concurrent::Atomic m_receiveCounter{0U}; + iox::concurrent::Atomic m_sendCounter{0U}; + iox::concurrent::Atomic m_publisherRunFinished{false}; // Memory objects iox::BumpAllocator m_memoryAllocator{g_memory, MEMORY_SIZE}; diff --git a/iceoryx_posh/test/integrationtests/test_publisher_subscriber_communication.cpp b/iceoryx_posh/test/integrationtests/test_publisher_subscriber_communication.cpp index 2b5832d046..749869f943 100644 --- a/iceoryx_posh/test/integrationtests/test_publisher_subscriber_communication.cpp +++ b/iceoryx_posh/test/integrationtests/test_publisher_subscriber_communication.cpp @@ -23,6 +23,7 @@ #include "iceoryx_posh/roudi_env/minimal_iceoryx_config.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" #include "iceoryx_posh/testing/roudi_gtest.hpp" +#include "iox/atomic.hpp" #include "iox/forward_list.hpp" #include "iox/list.hpp" #include "iox/optional.hpp" @@ -70,12 +71,14 @@ class PublisherSubscriberCommunication_test : public RouDi_GTest { } - void SetUp() + void SetUp() override { runtime::PoshRuntime::initRuntime("PublisherSubscriberCommunication_test"); m_watchdog.watchAndActOnFailure([] { std::terminate(); }); }; - void TearDown(){}; + void TearDown() override + { + } template std::unique_ptr> @@ -576,7 +579,7 @@ TEST_F(PublisherSubscriberCommunication_test, PublisherBlocksWhenBlockingActivat EXPECT_FALSE(publisher->publishCopyOf("start your day with a smile").has_error()); EXPECT_FALSE(publisher->publishCopyOf("and hypnotoad will smile back").has_error()); - std::atomic_bool wasSampleDelivered{false}; + iox::concurrent::Atomic wasSampleDelivered{false}; Barrier isThreadStarted(1U); std::thread t1([&] { isThreadStarted.notify(); @@ -617,7 +620,7 @@ TEST_F(PublisherSubscriberCommunication_test, PublisherDoesNotBlockAndDiscardsSa EXPECT_FALSE(publisher->publishCopyOf("first there was a blubb named mantua").has_error()); EXPECT_FALSE(publisher->publishCopyOf("second hypnotoad ate it").has_error()); - std::atomic_bool wasSampleDelivered{false}; + iox::concurrent::Atomic wasSampleDelivered{false}; Barrier isThreadStarted(1U); std::thread t1([&] { isThreadStarted.notify(); @@ -679,7 +682,7 @@ TEST_F(PublisherSubscriberCommunication_test, MixedOptionsSetupWorksWithBlocking EXPECT_FALSE(publisherBlocking->publishCopyOf("hypnotoad wants a cookie").has_error()); EXPECT_FALSE(publisherNonBlocking->publishCopyOf("hypnotoad has a sister named hypnoodle").has_error()); - std::atomic_bool wasSampleDelivered{false}; + iox::concurrent::Atomic wasSampleDelivered{false}; Barrier isThreadStarted(1U); std::thread t1([&] { isThreadStarted.notify(); diff --git a/iceoryx_posh/test/integrationtests/test_service_discovery.cpp b/iceoryx_posh/test/integrationtests/test_service_discovery.cpp index da9d271108..f8d052506f 100644 --- a/iceoryx_posh/test/integrationtests/test_service_discovery.cpp +++ b/iceoryx_posh/test/integrationtests/test_service_discovery.cpp @@ -27,6 +27,7 @@ #include "iceoryx_posh/runtime/service_discovery.hpp" #include "iceoryx_posh/testing/mocks/posh_runtime_mock.hpp" #include "iceoryx_posh/testing/roudi_gtest.hpp" +#include "iox/atomic.hpp" #include "test.hpp" #include @@ -49,7 +50,7 @@ using iox::popo::MessagingPattern; using ServiceContainer = std::vector; -static std::atomic_bool callbackWasCalled; +static iox::concurrent::Atomic callbackWasCalled; ServiceContainer serviceContainer; // We use various test fixtures to group the tests and diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp index 1fea4c17b7..04e9f65a0d 100644 --- a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp @@ -27,6 +27,7 @@ #include "iceoryx_posh/internal/popo/building_blocks/variant_queue.hpp" #include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iceoryx_posh/mepoo/chunk_header.hpp" +#include "iox/atomic.hpp" #include "iox/detail/hoofs_error_reporting.hpp" #include "iceoryx_hoofs/testing/error_reporting/testing_support.hpp" @@ -621,7 +622,7 @@ TYPED_TEST(ChunkDistributor_test, DeliverToQueueWithBlockingOptionBlocksDelivery Barrier isThreadStarted(1U); auto chunk = this->allocateChunk(7373); - std::atomic_bool wasChunkDelivered{false}; + iox::concurrent::Atomic wasChunkDelivered{false}; std::thread t1([&] { isThreadStarted.notify(); ASSERT_FALSE(sut.deliverToQueue(queueData->m_uniqueId, EXPECTED_QUEUE_INDEX, chunk).has_error()); @@ -738,7 +739,7 @@ TYPED_TEST(ChunkDistributor_test, DeliverToSingleQueueBlocksWhenOptionsAreSetToB sut.deliverToAllStoredQueues(this->allocateChunk(155U)); Barrier isThreadStarted(1U); - std::atomic_bool wasChunkDelivered{false}; + iox::concurrent::Atomic wasChunkDelivered{false}; std::thread t1([&] { isThreadStarted.notify(); sut.deliverToAllStoredQueues(this->allocateChunk(152U)); @@ -785,7 +786,7 @@ TYPED_TEST(ChunkDistributor_test, MultipleBlockingQueuesWillBeFilledWhenThereBec sut.deliverToAllStoredQueues(this->allocateChunk(425U)); Barrier isThreadStarted(1U); - std::atomic_bool wasChunkDelivered{false}; + iox::concurrent::Atomic wasChunkDelivered{false}; std::thread t1([&] { isThreadStarted.notify(); sut.deliverToAllStoredQueues(this->allocateChunk(1152U)); diff --git a/iceoryx_posh/test/moduletests/test_popo_client_port.cpp b/iceoryx_posh/test/moduletests/test_popo_client_port.cpp index d1c53d75c4..fa992f98b6 100644 --- a/iceoryx_posh/test/moduletests/test_popo_client_port.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_client_port.cpp @@ -82,7 +82,8 @@ class ClientPort_test : public Test void tryAdvanceToState(SutClientPort& clientPort, const iox::ConnectionState targetState) { auto maybeCaProMessage = clientPort.portRouDi.tryGetCaProMessage(); - if (targetState == iox::ConnectionState::NOT_CONNECTED && clientPort.portData.m_connectionState == targetState) + if (targetState == iox::ConnectionState::NOT_CONNECTED + && clientPort.portData.m_connectionState.load() == targetState) { return; } @@ -91,8 +92,8 @@ class ClientPort_test : public Test auto& clientMessage = maybeCaProMessage.value(); ASSERT_THAT(clientMessage.m_type, Eq(CaproMessageType::CONNECT)); ASSERT_THAT(clientMessage.m_chunkQueueData, Ne(nullptr)); - ASSERT_THAT(clientPort.portData.m_connectionState, Eq(iox::ConnectionState::CONNECT_REQUESTED)); - if (clientPort.portData.m_connectionState == targetState) + ASSERT_THAT(clientPort.portData.m_connectionState.load(), Eq(iox::ConnectionState::CONNECT_REQUESTED)); + if (clientPort.portData.m_connectionState.load() == targetState) { return; } @@ -101,23 +102,23 @@ class ClientPort_test : public Test { CaproMessage serverMessageNack{CaproMessageType::NACK, m_serviceDescription}; clientPort.portRouDi.dispatchCaProMessageAndGetPossibleResponse(serverMessageNack); - ASSERT_THAT(clientPort.portData.m_connectionState, Eq(targetState)); + ASSERT_THAT(clientPort.portData.m_connectionState.load(), Eq(targetState)); return; } CaproMessage serverMessageAck{CaproMessageType::ACK, m_serviceDescription}; serverMessageAck.m_chunkQueueData = &serverChunkQueueData; clientPort.portRouDi.dispatchCaProMessageAndGetPossibleResponse(serverMessageAck); - ASSERT_THAT(clientPort.portData.m_connectionState, Eq(iox::ConnectionState::CONNECTED)); - if (clientPort.portData.m_connectionState == targetState) + ASSERT_THAT(clientPort.portData.m_connectionState.load(), Eq(iox::ConnectionState::CONNECTED)); + if (clientPort.portData.m_connectionState.load() == targetState) { return; } CaproMessage serverMessageDisconnect{CaproMessageType::DISCONNECT, m_serviceDescription}; clientPort.portRouDi.dispatchCaProMessageAndGetPossibleResponse(serverMessageDisconnect); - ASSERT_THAT(clientPort.portData.m_connectionState, Eq(iox::ConnectionState::DISCONNECT_REQUESTED)); - if (clientPort.portData.m_connectionState == targetState) + ASSERT_THAT(clientPort.portData.m_connectionState.load(), Eq(iox::ConnectionState::DISCONNECT_REQUESTED)); + if (clientPort.portData.m_connectionState.load() == targetState) { return; } diff --git a/iceoryx_posh/test/moduletests/test_popo_condition_variable.cpp b/iceoryx_posh/test/moduletests/test_popo_condition_variable.cpp index 88aa65e544..38df80585f 100644 --- a/iceoryx_posh/test/moduletests/test_popo_condition_variable.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_condition_variable.cpp @@ -22,9 +22,9 @@ #include "iceoryx_posh/internal/popo/building_blocks/condition_notifier.hpp" #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp" #include "iox/algorithm.hpp" +#include "iox/atomic.hpp" #include "test.hpp" -#include #include #include #include @@ -100,7 +100,7 @@ TEST_F(ConditionVariable_test, WaitResetsAllNotificationsInWait) m_signaler.notify(); m_waiter.wait(); - std::atomic_bool isThreadFinished{false}; + iox::concurrent::Atomic isThreadFinished{false}; std::thread t([&] { m_waiter.wait(); isThreadFinished = true; @@ -116,13 +116,13 @@ TEST_F(ConditionVariable_test, WaitResetsAllNotificationsInWait) TEST_F(ConditionVariable_test, WaitAndNotifyResultsInImmediateTriggerMultiThreaded) { ::testing::Test::RecordProperty("TEST_ID", "39b40c73-3dcc-4af6-9682-b62816c69854"); - std::atomic counter{0}; + iox::concurrent::Atomic counter{0}; Barrier isThreadStarted(1U); std::thread waiter([&] { - EXPECT_THAT(counter, Eq(0)); + EXPECT_THAT(counter.load(), Eq(0)); isThreadStarted.notify(); m_waiter.wait(); - EXPECT_THAT(counter, Eq(1)); + EXPECT_THAT(counter.load(), Eq(1)); }); isThreadStarted.wait(); @@ -137,7 +137,7 @@ TEST_F(ConditionVariable_test, AllNotificationsAreFalseAfterConstruction) ConditionVariableData sut; for (auto& notification : sut.m_activeNotifications) { - EXPECT_THAT(notification, Eq(false)); + EXPECT_THAT(notification.load(), Eq(false)); } } @@ -152,7 +152,7 @@ TEST_F(ConditionVariable_test, AllNotificationsAreFalseAfterConstructionWithRunt ::testing::Test::RecordProperty("TEST_ID", "4825e152-08e3-414e-a34f-d93d048f84b8"); for (auto& notification : m_condVarData.m_activeNotifications) { - EXPECT_THAT(notification, Eq(false)); + EXPECT_THAT(notification.load(), Eq(false)); } } @@ -166,11 +166,11 @@ TEST_F(ConditionVariable_test, NotifyActivatesCorrectIndex) { if (i == EVENT_INDEX) { - EXPECT_THAT(m_condVarData.m_activeNotifications[i], Eq(true)); + EXPECT_THAT(m_condVarData.m_activeNotifications[i].load(), Eq(true)); } else { - EXPECT_THAT(m_condVarData.m_activeNotifications[i], Eq(false)); + EXPECT_THAT(m_condVarData.m_activeNotifications[i].load(), Eq(false)); } } } @@ -237,7 +237,7 @@ TIMING_TEST_F(ConditionVariable_test, TimedWaitBlocksUntilTimeout, Repeat(5), [& ::testing::Test::RecordProperty("TEST_ID", "c755aec9-43c3-4bf4-bec4-5672c76561ef"); ConditionListener listener(m_condVarData); NotificationVector_t activeNotifications; - std::atomic_bool hasWaited{false}; + iox::concurrent::Atomic hasWaited{false}; std::thread waiter([&] { activeNotifications = listener.timedWait(m_timingTestTime); @@ -246,9 +246,9 @@ TIMING_TEST_F(ConditionVariable_test, TimedWaitBlocksUntilTimeout, Repeat(5), [& }); std::this_thread::sleep_for(std::chrono::milliseconds(2 * m_timingTestTime.toMilliseconds() / 3)); - EXPECT_THAT(hasWaited, Eq(false)); + EXPECT_THAT(hasWaited.load(), Eq(false)); std::this_thread::sleep_for(std::chrono::milliseconds(2 * m_timingTestTime.toMilliseconds() / 3)); - EXPECT_THAT(hasWaited, Eq(true)); + EXPECT_THAT(hasWaited.load(), Eq(true)); waiter.join(); }) @@ -256,7 +256,7 @@ TIMING_TEST_F(ConditionVariable_test, TimedWaitBlocksUntilNotification, Repeat(5 ::testing::Test::RecordProperty("TEST_ID", "b2999ddd-d072-4c9f-975e-fc8acc31397d"); ConditionListener listener(m_condVarData); NotificationVector_t activeNotifications; - std::atomic_bool hasWaited{false}; + iox::concurrent::Atomic hasWaited{false}; std::thread waiter([&] { activeNotifications = listener.timedWait(m_timingTestTime); @@ -266,10 +266,10 @@ TIMING_TEST_F(ConditionVariable_test, TimedWaitBlocksUntilNotification, Repeat(5 }); std::this_thread::sleep_for(std::chrono::milliseconds(m_timingTestTime.toMilliseconds() / 4)); - EXPECT_THAT(hasWaited, Eq(false)); + EXPECT_THAT(hasWaited.load(), Eq(false)); ConditionNotifier(m_condVarData, 13U).notify(); std::this_thread::sleep_for(std::chrono::milliseconds(m_timingTestTime.toMilliseconds() / 4)); - EXPECT_THAT(hasWaited, Eq(true)); + EXPECT_THAT(hasWaited.load(), Eq(true)); waiter.join(); }) @@ -370,7 +370,7 @@ TIMING_TEST_F(ConditionVariable_test, WaitBlocks, Repeat(5), [&] { ConditionListener listener(m_condVarData); NotificationVector_t activeNotifications; Barrier isThreadStarted(1U); - std::atomic_bool hasWaited{false}; + iox::concurrent::Atomic hasWaited{false}; std::thread waiter([&] { isThreadStarted.notify(); @@ -383,10 +383,10 @@ TIMING_TEST_F(ConditionVariable_test, WaitBlocks, Repeat(5), [&] { isThreadStarted.wait(); std::this_thread::sleep_for(std::chrono::milliseconds(10)); - EXPECT_THAT(hasWaited, Eq(false)); + EXPECT_THAT(hasWaited.load(), Eq(false)); notifier.notify(); std::this_thread::sleep_for(std::chrono::milliseconds(10)); - EXPECT_THAT(hasWaited, Eq(true)); + EXPECT_THAT(hasWaited.load(), Eq(true)); waiter.join(); }) @@ -397,7 +397,7 @@ TIMING_TEST_F(ConditionVariable_test, SecondWaitBlocksUntilNewNotification, Repe ConditionNotifier notifier1(m_condVarData, FIRST_EVENT_INDEX); ConditionNotifier notifier2(m_condVarData, SECOND_EVENT_INDEX); ConditionListener listener(m_condVarData); - std::atomic_bool hasWaited{false}; + iox::concurrent::Atomic hasWaited{false}; Watchdog watchdogFirstWait(m_timeToWait); watchdogFirstWait.watchAndActOnFailure([&] { listener.destroy(); }); @@ -422,17 +422,17 @@ TIMING_TEST_F(ConditionVariable_test, SecondWaitBlocksUntilNewNotification, Repe EXPECT_THAT(activeNotifications[0], Eq(FIRST_EVENT_INDEX)); for (const auto& notification : m_condVarData.m_activeNotifications) { - EXPECT_THAT(notification, Eq(false)); + EXPECT_THAT(notification.load(), Eq(false)); } }); isThreadStarted.wait(); std::this_thread::sleep_for(std::chrono::milliseconds(10)); - EXPECT_THAT(hasWaited, Eq(false)); + EXPECT_THAT(hasWaited.load(), Eq(false)); notifier1.notify(); std::this_thread::sleep_for(std::chrono::milliseconds(10)); - EXPECT_THAT(hasWaited, Eq(true)); + EXPECT_THAT(hasWaited.load(), Eq(true)); waiter.join(); }) diff --git a/iceoryx_posh/test/moduletests/test_popo_listener.cpp b/iceoryx_posh/test/moduletests/test_popo_listener.cpp index 70f5542b73..556d697ad7 100644 --- a/iceoryx_posh/test/moduletests/test_popo_listener.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_listener.cpp @@ -14,13 +14,13 @@ // // SPDX-License-Identifier: Apache-2.0 - #include "iceoryx_hoofs/testing/timing_test.hpp" #include "iceoryx_hoofs/testing/watch_dog.hpp" #include "iceoryx_posh/iceoryx_posh_types.hpp" #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp" #include "iceoryx_posh/popo/listener.hpp" #include "iceoryx_posh/popo/user_trigger.hpp" +#include "iox/atomic.hpp" #include "iox/optional.hpp" #include "iox/smart_lock.hpp" #include "iox/unnamed_semaphore.hpp" @@ -147,8 +147,8 @@ struct EventAndSutPair_t struct TriggerSourceAndCount { - std::atomic m_source{nullptr}; - std::atomic m_count{0U}; + iox::concurrent::Atomic m_source{nullptr}; + iox::concurrent::Atomic m_count{0U}; }; iox::concurrent::smart_lock> g_toBeAttached; @@ -209,7 +209,7 @@ class Listener_test : public Test } - void SetUp() + void SetUp() override { g_callbackBlocker.reset(); for (auto& e : g_triggerCallbackArg) @@ -272,9 +272,9 @@ class Listener_test : public Test return true; } - - void TearDown(){}; - + void TearDown() override + { + } static constexpr uint64_t OVERFLOW_TEST_APPENDIX = 1U; using eventArray_t = SimpleEventClass[iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER + OVERFLOW_TEST_APPENDIX]; @@ -664,8 +664,8 @@ TIMING_TEST_F(Listener_test, CallbackIsCalledAfterNotify, Repeat(5), [&] { fuu.triggerStoepsel(); std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS)); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source == &fuu); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count == 1U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source.load() == &fuu); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count.load() == 1U); }) TIMING_TEST_F(Listener_test, CallbackWithEventAndUserTypeIsCalledAfterNotify, Repeat(5), [&] { @@ -682,7 +682,7 @@ TIMING_TEST_F(Listener_test, CallbackWithEventAndUserTypeIsCalledAfterNotify, Re fuu.triggerStoepsel(); std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS)); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source == &fuu); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source.load() == &fuu); TIMING_TEST_EXPECT_TRUE(userType == 1U); }) @@ -698,7 +698,7 @@ TIMING_TEST_F(Listener_test, CallbackWithUserTypeIsCalledAfterNotify, Repeat(5), fuu.triggerNoEventType(); std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS)); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source == &fuu); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source.load() == &fuu); TIMING_TEST_EXPECT_TRUE(userType == 1U); }) @@ -723,10 +723,10 @@ TIMING_TEST_F(Listener_test, CallbackIsCalledOnlyOnceWhenTriggered, Repeat(5), [ fuu2.triggerStoepsel(); std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS)); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source == &fuu1); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count == 1U); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_source == &fuu2); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_count == 1U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source.load() == &fuu1); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count.load() == 1U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_source.load() == &fuu2); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_count.load() == 1U); }) TIMING_TEST_F(Listener_test, TriggerWhileInCallbackLeadsToAnotherCallback, Repeat(5), [&] { @@ -750,8 +750,8 @@ TIMING_TEST_F(Listener_test, TriggerWhileInCallbackLeadsToAnotherCallback, Repea unblockTriggerCallback(NUMBER_OF_TRIGGER_UNBLOCKS); std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS)); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source == &fuu); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count == 2U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source.load() == &fuu); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count.load() == 2U); }) TIMING_TEST_F(Listener_test, TriggerWhileInCallbackLeadsToAnotherCallbackOnce, Repeat(5), [&] { @@ -782,10 +782,10 @@ TIMING_TEST_F(Listener_test, TriggerWhileInCallbackLeadsToAnotherCallbackOnce, R unblockTriggerCallback(NUMBER_OF_TRIGGER_UNBLOCKS); std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS)); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source == &fuu); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count == 2U); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_source == &bar); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_count == 1U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source.load() == &fuu); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count.load() == 2U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_source.load() == &bar); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_count.load() == 1U); }) TIMING_TEST_F(Listener_test, TriggerMultipleTimesWhileInCallbackLeadsToAnotherCallback, Repeat(5), [&] { @@ -812,8 +812,8 @@ TIMING_TEST_F(Listener_test, TriggerMultipleTimesWhileInCallbackLeadsToAnotherCa unblockTriggerCallback(NUMBER_OF_RETRIGGERS); std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS)); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source == &fuu); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count == 2U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source.load() == &fuu); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count.load() == 2U); }) TIMING_TEST_F(Listener_test, TriggerMultipleTimesWhileInCallbackLeadsToAnotherCallbackOnce, Repeat(5), [&] { @@ -847,10 +847,10 @@ TIMING_TEST_F(Listener_test, TriggerMultipleTimesWhileInCallbackLeadsToAnotherCa unblockTriggerCallback(NUMBER_OF_RETRIGGERS + 1U); std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS)); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source == &fuu); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count == 2U); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_source == &bar); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_count == 1U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source.load() == &fuu); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count.load() == 2U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_source.load() == &bar); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_count.load() == 1U); }) TIMING_TEST_F(Listener_test, NoTriggerLeadsToNoCallback, Repeat(5), [&] { @@ -865,8 +865,8 @@ TIMING_TEST_F(Listener_test, NoTriggerLeadsToNoCallback, Repeat(5), [&] { std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS)); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source == nullptr); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count == 0U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source.load() == nullptr); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count.load() == 0U); }) TIMING_TEST_F(Listener_test, TriggeringAllEventsCallsAllCallbacks, Repeat(5), [&] { @@ -890,12 +890,12 @@ TIMING_TEST_F(Listener_test, TriggeringAllEventsCallsAllCallbacks, Repeat(5), [& unblockTriggerCallback(10U * iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER); std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS)); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_source == &events[0U]); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_count == 2U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_source.load() == &events[0U]); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_count.load() == 2U); for (uint64_t i = 1U; i < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) { - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_source == &events[i]); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_count == 1U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_source.load() == &events[i]); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_count.load() == 1U); } }) @@ -923,12 +923,12 @@ TIMING_TEST_F(Listener_test, TriggeringAllEventsCallsAllCallbacksOnce, Repeat(5) events[0U].triggerStoepsel(); std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS)); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_source == &events[0U]); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_count == 3U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_source.load() == &events[0U]); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_count.load() == 3U); for (uint64_t i = 1U; i < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) { - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_source == &events[i]); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_count == 1U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_source.load() == &events[i]); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_count.load() == 1U); } }) ////////////////////////////////// @@ -961,8 +961,8 @@ TIMING_TEST_F(Listener_test, AttachingWhileCallbackIsRunningWorks, Repeat(5), [& events[1U].triggerStoepsel(); std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS * 2U)); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_source == &events[1U]); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_count == 1U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_source.load() == &events[1U]); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_count.load() == 1U); }) TIMING_TEST_F(Listener_test, AttachingMultipleWhileCallbackIsRunningWorks, Repeat(5), [&] { @@ -992,8 +992,8 @@ TIMING_TEST_F(Listener_test, AttachingMultipleWhileCallbackIsRunningWorks, Repea for (uint64_t i = 0U; i + 1U < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) { - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_source == &events[i]); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_count == 1U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_source.load() == &events[i]); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_count.load() == 1U); } }) @@ -1017,8 +1017,8 @@ TIMING_TEST_F(Listener_test, DetachingWhileCallbackIsRunningWorks, Repeat(5), [& events[0U].triggerStoepsel(); std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS)); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count == 1U); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source == nullptr); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count.load() == 1U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source.load() == nullptr); }) TIMING_TEST_F(Listener_test, DetachingWhileCallbackIsRunningBlocksDetach, Repeat(5), [&] { @@ -1091,7 +1091,7 @@ TIMING_TEST_F(Listener_test, DetachingMultipleWhileCallbackIsRunningWorks, Repea for (uint64_t i = 0U; i < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) { - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_source == nullptr); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[i].m_source.load() == nullptr); } }) @@ -1207,10 +1207,10 @@ TIMING_TEST_F(Listener_test, DetachedCallbacksAreNotBeingCalledWhenTriggeredBefo std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS)); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source == nullptr); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_source == nullptr); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count == 0U); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_count == 1U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source.load() == nullptr); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_source.load() == nullptr); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count.load() == 0U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[1U].m_count.load() == 1U); }) TIMING_TEST_F(Listener_test, AttachingInCallbackWorks, Repeat(5), [&] { @@ -1230,8 +1230,8 @@ TIMING_TEST_F(Listener_test, AttachingInCallbackWorks, Repeat(5), [&] { std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS / 2U)); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source == &events[1U]); - TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count == 1U); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_source.load() == &events[1U]); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0U].m_count.load() == 1U); }) ////////////////////////////////// // END diff --git a/iceoryx_posh/test/moduletests/test_popo_trigger_handle.cpp b/iceoryx_posh/test/moduletests/test_popo_trigger_handle.cpp index 6bed50ad1e..dad8588249 100644 --- a/iceoryx_posh/test/moduletests/test_popo_trigger_handle.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_trigger_handle.cpp @@ -18,6 +18,7 @@ #include "iceoryx_posh/internal/popo/building_blocks/condition_listener.hpp" #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp" #include "iceoryx_posh/popo/trigger_handle.hpp" +#include "iox/atomic.hpp" #include "iox/deadline_timer.hpp" #include "test.hpp" @@ -122,7 +123,7 @@ TEST_F(TriggerHandle_test, triggerNotifiesConditionVariable) { ::testing::Test::RecordProperty("TEST_ID", "11e752c8-d473-4bfd-b973-869c3b2d9fbc"); - std::atomic_int stage{0}; + iox::concurrent::Atomic stage{0}; std::thread t([&] { stage.store(1); diff --git a/iceoryx_posh/test/moduletests/test_popo_waitset.cpp b/iceoryx_posh/test/moduletests/test_popo_waitset.cpp index 4fdf484d02..a6c6fc1ca6 100644 --- a/iceoryx_posh/test/moduletests/test_popo_waitset.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_waitset.cpp @@ -21,6 +21,7 @@ #include "iceoryx_posh/internal/popo/building_blocks/condition_variable_data.hpp" #include "iceoryx_posh/popo/user_trigger.hpp" #include "iceoryx_posh/popo/wait_set.hpp" +#include "iox/atomic.hpp" #include "iox/optional.hpp" #include "iox/vector.hpp" #include "test.hpp" @@ -432,7 +433,7 @@ class WaitSet_test : public Test iox::popo::TriggerHandle m_eventHandle; iox::popo::TriggerHandle m_stateHandle; - mutable std::atomic_bool m_hasTriggered{false}; + mutable iox::concurrent::Atomic m_hasTriggered{false}; static std::vector m_invalidateTriggerId; static SimpleEvent1 m_simpleEvent1; @@ -1133,8 +1134,8 @@ TEST_F(WaitSet_test, AttachmentsGoingOutOfScopeReducesSize) TEST_F(WaitSet_test, WaitBlocksWhenNothingTriggered) { ::testing::Test::RecordProperty("TEST_ID", "66c4d11f-f330-4629-b74a-faa87440a9a0"); - std::atomic_bool doStartWaiting{false}; - std::atomic_bool isThreadFinished{false}; + iox::concurrent::Atomic doStartWaiting{false}; + iox::concurrent::Atomic isThreadFinished{false}; for (uint64_t i = 0U; i < iox::MAX_NUMBER_OF_ATTACHMENTS_PER_WAITSET; ++i) { ASSERT_FALSE(m_sut->attachEvent(m_simpleEvents[i], 5U + i).has_error()); @@ -1707,8 +1708,8 @@ TEST_F(WaitSet_test, MixingEventAndStateBasedTriggerHandlesEventTriggeresWithWai TEST_F(WaitSet_test, WaitUnblocksAfterMarkForDestructionCall) { ::testing::Test::RecordProperty("TEST_ID", "a7c0b153-65da-4603-bd82-5f5db5841a2b"); - std::atomic_bool doStartWaiting{false}; - std::atomic_bool isThreadFinished{false}; + iox::concurrent::Atomic doStartWaiting{false}; + iox::concurrent::Atomic isThreadFinished{false}; ASSERT_FALSE(m_sut->attachEvent(m_simpleEvents[0U], 0U).has_error()); std::thread t([&] { @@ -1735,8 +1736,8 @@ TEST_F(WaitSet_test, WaitUnblocksAfterMarkForDestructionCall) TEST_F(WaitSet_test, TimedWaitUnblocksAfterMarkForDestructionCall) { ::testing::Test::RecordProperty("TEST_ID", "63573915-bb36-4ece-93be-2adc853582e6"); - std::atomic_bool doStartWaiting{false}; - std::atomic_bool isThreadFinished{false}; + iox::concurrent::Atomic doStartWaiting{false}; + iox::concurrent::Atomic isThreadFinished{false}; ASSERT_FALSE(m_sut->attachEvent(m_simpleEvents[0U], 0U).has_error()); std::thread t([&] { diff --git a/iceoryx_posh/test/moduletests/test_posh_runtime.cpp b/iceoryx_posh/test/moduletests/test_posh_runtime.cpp index 41d668f7a0..b42d960a31 100644 --- a/iceoryx_posh/test/moduletests/test_posh_runtime.cpp +++ b/iceoryx_posh/test/moduletests/test_posh_runtime.cpp @@ -28,6 +28,7 @@ #include "iceoryx_posh/roudi_env/roudi_env.hpp" #include "iceoryx_posh/runtime/posh_runtime.hpp" #include "iceoryx_posh/testing/mocks/posh_runtime_mock.hpp" +#include "iox/atomic.hpp" #include "iox/detail/convert.hpp" #include "iox/std_string_support.hpp" @@ -75,7 +76,7 @@ class PoshRuntime_test : public Test EXPECT_EQ(portData->m_serviceDescription, sd); EXPECT_EQ(portData->m_runtimeName, m_runtimeName); - EXPECT_EQ(portData->m_connectRequested, options.connectOnCreate); + EXPECT_EQ(portData->m_connectRequested.load(), options.connectOnCreate); EXPECT_EQ(portData->m_chunkReceiverData.m_queue.capacity(), options.responseQueueCapacity); EXPECT_EQ(portData->m_chunkReceiverData.m_queueFullPolicy, options.responseQueueFullPolicy); EXPECT_EQ(portData->m_chunkReceiverData.m_memoryInfo.deviceId, memoryInfo.deviceId); @@ -95,7 +96,7 @@ class PoshRuntime_test : public Test EXPECT_EQ(portData->m_serviceDescription, sd); EXPECT_EQ(portData->m_runtimeName, m_runtimeName); - EXPECT_EQ(portData->m_offeringRequested, options.offerOnCreate); + EXPECT_EQ(portData->m_offeringRequested.load(), options.offerOnCreate); EXPECT_EQ(portData->m_chunkReceiverData.m_queue.capacity(), options.requestQueueCapacity); EXPECT_EQ(portData->m_chunkReceiverData.m_queueFullPolicy, options.requestQueueFullPolicy); EXPECT_EQ(portData->m_chunkReceiverData.m_memoryInfo.deviceId, memoryInfo.deviceId); @@ -203,7 +204,7 @@ TEST_F(PoshRuntime_test, GetMiddlewareInterfaceIsSuccessful) ASSERT_NE(nullptr, interfacePortData); EXPECT_EQ(m_runtimeName, interfacePortData->m_runtimeName); - EXPECT_EQ(false, interfacePortData->m_toBeDestroyed); + EXPECT_EQ(false, interfacePortData->m_toBeDestroyed.load()); } TEST_F(PoshRuntime_test, GetMiddlewareInterfaceInterfacelistOverflow) @@ -623,7 +624,7 @@ TEST_F(PoshRuntime_test, GetMiddlewareClientWithDefaultArgsIsSuccessful) ASSERT_THAT(clientPort, Ne(nullptr)); checkClientInitialization(clientPort, sd, defaultOptions, defaultPortConfigInfo.memoryInfo); - EXPECT_EQ(clientPort->m_connectionState, iox::ConnectionState::WAIT_FOR_OFFER); + EXPECT_EQ(clientPort->m_connectionState.load(), iox::ConnectionState::WAIT_FOR_OFFER); } TEST_F(PoshRuntime_test, GetMiddlewareClientWithCustomClientOptionsIsSuccessful) @@ -643,7 +644,7 @@ TEST_F(PoshRuntime_test, GetMiddlewareClientWithCustomClientOptionsIsSuccessful) ASSERT_THAT(clientPort, Ne(nullptr)); checkClientInitialization(clientPort, sd, clientOptions, portConfig.memoryInfo); - EXPECT_EQ(clientPort->m_connectionState, iox::ConnectionState::NOT_CONNECTED); + EXPECT_EQ(clientPort->m_connectionState.load(), iox::ConnectionState::NOT_CONNECTED); } TEST_F(PoshRuntime_test, GetMiddlewareClientWithQueueGreaterMaxCapacityClampsQueueToMaximum) @@ -720,7 +721,7 @@ TEST_F(PoshRuntime_test, GetMiddlewareServerWithDefaultArgsIsSuccessful) ASSERT_THAT(serverPort, Ne(nullptr)); checkServerInitialization(serverPort, sd, defaultOptions, defaultPortConfigInfo.memoryInfo); - EXPECT_EQ(serverPort->m_offered, true); + EXPECT_EQ(serverPort->m_offered.load(), true); } TEST_F(PoshRuntime_test, GetMiddlewareServerWithCustomServerOptionsIsSuccessful) @@ -739,7 +740,7 @@ TEST_F(PoshRuntime_test, GetMiddlewareServerWithCustomServerOptionsIsSuccessful) ASSERT_THAT(serverPort, Ne(nullptr)); checkServerInitialization(serverPort, sd, serverOptions, portConfig.memoryInfo); - EXPECT_EQ(serverPort->m_offered, false); + EXPECT_EQ(serverPort->m_offered.load(), false); } TEST_F(PoshRuntime_test, GetMiddlewareServerWithQueueGreaterMaxCapacityClampsQueueToMaximum) @@ -850,7 +851,7 @@ TEST_F(PoshRuntime_test, ShutdownUnblocksBlockingPublisher) // send samples to fill subscriber queue ASSERT_FALSE(publisher.publishCopyOf(42U).has_error()); - std::atomic_bool wasSampleSent{false}; + iox::concurrent::Atomic wasSampleSent{false}; constexpr iox::units::Duration DEADLOCK_TIMEOUT{5_s}; Watchdog deadlockWatchdog{DEADLOCK_TIMEOUT}; @@ -898,7 +899,7 @@ TEST_F(PoshRuntime_test, ShutdownUnblocksBlockingClient) ASSERT_TRUE(server.hasClients()); ASSERT_THAT(client.getConnectionState(), Eq(iox::ConnectionState::CONNECTED)); - std::atomic_bool wasRequestSent{false}; + iox::concurrent::Atomic wasRequestSent{false}; constexpr iox::units::Duration DEADLOCK_TIMEOUT{5_s}; Watchdog deadlockWatchdog{DEADLOCK_TIMEOUT}; @@ -974,7 +975,7 @@ TEST_F(PoshRuntime_test, ShutdownUnblocksBlockingServer) EXPECT_FALSE(client.send(clientLoanResult.value()).has_error()); } - std::atomic_bool wasResponseSent{false}; + iox::concurrent::Atomic wasResponseSent{false}; constexpr iox::units::Duration DEADLOCK_TIMEOUT{5_s}; Watchdog deadlockWatchdog{DEADLOCK_TIMEOUT}; diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp index 9f1e5f0924..25724b35d5 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager.cpp @@ -17,6 +17,7 @@ #include "iceoryx_hoofs/testing/barrier.hpp" #include "iceoryx_posh/internal/posh_error_reporting.hpp" +#include "iox/atomic.hpp" #include "iox/std_string_support.hpp" #include "test_roudi_portmanager_fixture.hpp" @@ -747,7 +748,7 @@ void PortManager_test::setupAndTestBlockingPublisher(const iox::RuntimeName_t& p ASSERT_FALSE(maybeChunk.has_error()); publisher.sendChunk(maybeChunk.value()); - std::atomic_bool wasChunkSent{false}; + iox::concurrent::Atomic wasChunkSent{false}; constexpr iox::units::Duration DEADLOCK_TIMEOUT{5_s}; Watchdog deadlockWatchdog{DEADLOCK_TIMEOUT}; diff --git a/iceoryx_posh/test/moduletests/test_roudi_portmanager_client_server.cpp b/iceoryx_posh/test/moduletests/test_roudi_portmanager_client_server.cpp index 0d27522715..8440a20efb 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portmanager_client_server.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portmanager_client_server.cpp @@ -51,10 +51,10 @@ TEST_F(PortManager_test, AcquireClientPortDataReturnsPort) .and_then([&](const auto& clientPortData) { EXPECT_THAT(clientPortData->m_serviceDescription, Eq(sd)); EXPECT_THAT(clientPortData->m_runtimeName, Eq(runtimeName)); - EXPECT_THAT(clientPortData->m_toBeDestroyed, Eq(false)); + EXPECT_THAT(clientPortData->m_toBeDestroyed.load(), Eq(false)); EXPECT_THAT(clientPortData->m_chunkReceiverData.m_queue.capacity(), Eq(clientOptions.responseQueueCapacity)); - EXPECT_THAT(clientPortData->m_connectRequested, Eq(clientOptions.connectOnCreate)); + EXPECT_THAT(clientPortData->m_connectRequested.load(), Eq(clientOptions.connectOnCreate)); EXPECT_THAT(clientPortData->m_chunkReceiverData.m_queueFullPolicy, Eq(clientOptions.responseQueueFullPolicy)); EXPECT_THAT(clientPortData->m_chunkSenderData.m_consumerTooSlowPolicy, @@ -82,9 +82,9 @@ TEST_F(PortManager_test, AcquireServerPortDataReturnsPort) .and_then([&](const auto& serverPortData) { EXPECT_THAT(serverPortData->m_serviceDescription, Eq(sd)); EXPECT_THAT(serverPortData->m_runtimeName, Eq(runtimeName)); - EXPECT_THAT(serverPortData->m_toBeDestroyed, Eq(false)); + EXPECT_THAT(serverPortData->m_toBeDestroyed.load(), Eq(false)); EXPECT_THAT(serverPortData->m_chunkReceiverData.m_queue.capacity(), Eq(serverOptions.requestQueueCapacity)); - EXPECT_THAT(serverPortData->m_offeringRequested, Eq(serverOptions.offerOnCreate)); + EXPECT_THAT(serverPortData->m_offeringRequested.load(), Eq(serverOptions.offerOnCreate)); EXPECT_THAT(serverPortData->m_chunkReceiverData.m_queueFullPolicy, Eq(serverOptions.requestQueueFullPolicy)); EXPECT_THAT(serverPortData->m_chunkSenderData.m_consumerTooSlowPolicy, diff --git a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp index 976d7895bb..c6fa428638 100644 --- a/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp +++ b/iceoryx_posh/test/moduletests/test_roudi_portpool.cpp @@ -339,8 +339,8 @@ TEST_F(PortPool_test, AddClientPortIsSuccessful) addClientPorts(NUMBER_OF_CLIENTS_TO_ADD, [&](const auto& sd, const auto& runtimeName, const auto& clientPort) { EXPECT_EQ(clientPort.m_serviceDescription, sd); EXPECT_EQ(clientPort.m_runtimeName, runtimeName); - EXPECT_EQ(clientPort.m_connectRequested, m_clientOptions.connectOnCreate); - EXPECT_EQ(clientPort.m_connectionState, ConnectionState::NOT_CONNECTED); + EXPECT_EQ(clientPort.m_connectRequested.load(), m_clientOptions.connectOnCreate); + EXPECT_EQ(clientPort.m_connectionState.load(), ConnectionState::NOT_CONNECTED); EXPECT_EQ(clientPort.m_chunkReceiverData.m_queue.capacity(), QUEUE_CAPACITY); EXPECT_EQ(clientPort.m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); EXPECT_EQ(clientPort.m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); @@ -433,8 +433,8 @@ TEST_F(PortPool_test, AddServerPortIsSuccessful) addServerPorts(NUMBER_OF_SERVERS_TO_ADD, [&](const auto& sd, const auto& runtimeName, const auto& serverPort) { EXPECT_EQ(serverPort.m_serviceDescription, sd); EXPECT_EQ(serverPort.m_runtimeName, runtimeName); - EXPECT_EQ(serverPort.m_offeringRequested, m_serverOptions.offerOnCreate); - EXPECT_EQ(serverPort.m_offered, false); + EXPECT_EQ(serverPort.m_offeringRequested.load(), m_serverOptions.offerOnCreate); + EXPECT_EQ(serverPort.m_offered.load(), false); EXPECT_EQ(serverPort.m_chunkReceiverData.m_queue.capacity(), QUEUE_CAPACITY); EXPECT_EQ(serverPort.m_chunkReceiverData.m_memoryInfo.deviceId, DEFAULT_DEVICE_ID); EXPECT_EQ(serverPort.m_chunkReceiverData.m_memoryInfo.memoryType, DEFAULT_MEMORY_TYPE); From 4540486a47f37c39d72e0e8e3f2aa36f8fc3f72a Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Wed, 21 Aug 2024 14:15:18 +0200 Subject: [PATCH 2/4] iox-#2329 Fix typo --- iceoryx_platform/test/moduletests/test_platform_atomic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iceoryx_platform/test/moduletests/test_platform_atomic.cpp b/iceoryx_platform/test/moduletests/test_platform_atomic.cpp index 8a8850d8d4..69b4ab57bd 100644 --- a/iceoryx_platform/test/moduletests/test_platform_atomic.cpp +++ b/iceoryx_platform/test/moduletests/test_platform_atomic.cpp @@ -381,7 +381,7 @@ TYPED_TEST(Atomic_test, CompareExchangeWeakWorks) EXPECT_THAT(sut_struct.load(), Eq(EXPECTED_NEW_STRUCT)); } -TYPED_TEST(Atomic_test, CompareExchangeStronWorks) +TYPED_TEST(Atomic_test, CompareExchangeStrongWorks) { ::testing::Test::RecordProperty("TEST_ID", "9f39293c-5d84-4d59-ab91-58fb738b5386"); From 8513ab3ba4e53e2fd7f73842f29abd869c92c5be Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Wed, 21 Aug 2024 14:46:56 +0200 Subject: [PATCH 3/4] iox-#2329 Add script to check for invalid usage of std::atomic --- .cirrus.yaml | 1 + .github/workflows/build-test.yml | 1 + tools/git-hooks/pre-commit | 6 +++++ tools/scripts/check_atomic_usage.sh | 42 +++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100755 tools/scripts/check_atomic_usage.sh diff --git a/.cirrus.yaml b/.cirrus.yaml index cd6511d1d3..56447d7d39 100644 --- a/.cirrus.yaml +++ b/.cirrus.yaml @@ -110,6 +110,7 @@ preflight_check_task: clang_format_script: tools/scripts/clang_format.sh check check_test_ids_script: tools/scripts/check_test_ids.sh check_invalid_characters_script: tools/scripts/check_invalid_characters.sh + check_atomic_usage: tools/scripts/check_atomic_usage.sh cmake_linter_script: tools/ci/cmake-linter.sh # diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 936f89b554..753ef62f70 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -21,6 +21,7 @@ jobs: - run: ./tools/scripts/clang_format.sh check - run: ./tools/scripts/check_test_ids.sh - run: ./tools/scripts/check_invalid_characters.sh + - run: ./tools/scripts/check_atomic_usage.sh - run: ./tools/ci/cmake-linter.sh check-status-of-nightly-action: diff --git a/tools/git-hooks/pre-commit b/tools/git-hooks/pre-commit index db7fd5d204..4a70cab0af 100755 --- a/tools/git-hooks/pre-commit +++ b/tools/git-hooks/pre-commit @@ -62,4 +62,10 @@ if ! tools/scripts/check_invalid_characters.sh; then exit 1 fi +## check for test IDs +if ! tools/scripts/check_atomic_usage.sh; then + echo "Error checking atomic usage" + exit 1 +fi + cd "${current_dir}" || exit diff --git a/tools/scripts/check_atomic_usage.sh b/tools/scripts/check_atomic_usage.sh new file mode 100755 index 0000000000..22740a0a16 --- /dev/null +++ b/tools/scripts/check_atomic_usage.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Copyright (c) 2024 by ekxide IO GmbH. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 + +# This script does a sanity check for the number of tests and the number of test IDs and +# checks for unique test IDs + +# NOTE: don't use 'set -e' since this will abort the script whit an error when nothing is found + +COLOR_OFF='\033[0m' +COLOR_RED='\033[1;31m' +COLOR_GREEN='\033[1;32m' +COLOR_YELLOW='\033[1;33m' + +ICEORYX_PATH=$(git rev-parse --show-toplevel) +cd $ICEORYX_PATH + +# search for 'std::atomic' and ignore 'std::atomic_thread_fence' and the files for the implementation and tests for 'iox::concurrent::Atomic' +INVALID_ATOMIC_USAGE=$(grep -Ern "std::atomic" iceoryx_* | rg -Fv "std::atomic_thread_fence" | rg -Fv "test_platform_atomic.cpp" | rg -Fv "iceoryx_platform/atomic.hpp") + +if [[ -n "${INVALID_ATOMIC_USAGE}" ]]; then + echo -e "${COLOR_RED}ERROR: ${COLOR_YELLOW}There are invalid occurrences of 'std::atomic'${COLOR_OFF}" + echo -e "${INVALID_ATOMIC_USAGE}" + echo -e "${COLOR_YELLOW}If these are false positives, please add them to 'tools/scripts/check_atomic_usage.sh'${COLOR_OFF}" + exit 1 +fi + +echo -e "${COLOR_GREEN}No invalid use of 'std::atomic' found${COLOR_OFF}" From bf4e66a366fedab04074a65ad9255a7d1d9378c1 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Thu, 22 Aug 2024 01:19:47 +0200 Subject: [PATCH 4/4] iox-#2329 Increase timeout detection for triggerNotifiesConditionVariable test due to sporadic failures on macOS --- iceoryx_posh/test/moduletests/test_popo_trigger_handle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iceoryx_posh/test/moduletests/test_popo_trigger_handle.cpp b/iceoryx_posh/test/moduletests/test_popo_trigger_handle.cpp index dad8588249..28e787b2bb 100644 --- a/iceoryx_posh/test/moduletests/test_popo_trigger_handle.cpp +++ b/iceoryx_posh/test/moduletests/test_popo_trigger_handle.cpp @@ -137,7 +137,7 @@ TEST_F(TriggerHandle_test, triggerNotifiesConditionVariable) std::this_thread::yield(); } - iox::deadline_timer timeout{100_ms}; + iox::deadline_timer timeout{200_ms}; EXPECT_THAT(stage.load(), Eq(1)); std::this_thread::sleep_for(std::chrono::milliseconds(10)); EXPECT_THAT(stage.load(), Eq(1));