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/actions/install-iceoryx-deps-and-clang/action.yml b/.github/actions/install-iceoryx-deps-and-clang/action.yml index 5b4c51da03..b4fd5e2afc 100644 --- a/.github/actions/install-iceoryx-deps-and-clang/action.yml +++ b/.github/actions/install-iceoryx-deps-and-clang/action.yml @@ -5,10 +5,12 @@ runs: - name: Install iceoryx dependencies and clang-tidy shell: bash run: | + sudo dpkg --add-architecture i386 sudo wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main" sudo apt-get update sudo apt-get install -y libacl1-dev libncurses5-dev + sudo apt-get install -y libacl1-dev:i386 libc6-dev-i386 libc6-dev-i386-cross libstdc++6-i386-cross gcc-multilib g++-multilib sudo apt-get install -y clang-format-15 clang-tidy-15 clang-tools-15 clang-15 lld sudo rm /usr/bin/clang sudo rm /usr/bin/clang++ diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index d7ccc9233c..e2387562b4 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: @@ -54,17 +55,24 @@ jobs: runs-on: ubuntu-20.04 needs: pre-flight-check steps: - - uses: actions/checkout@v4 - - uses: egor-tensin/setup-gcc@v1.3 + - name: Checkout + uses: actions/checkout@v4 + - name: Install iceoryx dependencies and clang-tidy + uses: ./.github/actions/install-iceoryx-deps-and-clang + - name: Setup GCC + uses: egor-tensin/setup-gcc@v1.3 with: # gcc 8.3 is compiler used in QNX 7.1 version: 8 platform: x64 - - uses: jwlawson/actions-setup-cmake@v2.0 + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v2.0 with: cmake-version: '3.16.3' # version used in Ubuntu 20.04 LTS - run: ./tools/ci/build-test-ubuntu.sh + + build-test-windows-msvc: # prevent stuck jobs consuming runners for 6 hours timeout-minutes: 60 @@ -171,6 +179,18 @@ jobs: - name: Run Thread Sanitizer run: ./tools/ci/build-test-ubuntu-with-sanitizers.sh clang tsan + build-test-ubuntu-32-bit: + # prevent stuck jobs consuming runners for 6 hours + timeout-minutes: 60 + runs-on: ubuntu-latest + needs: pre-flight-check + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install iceoryx dependencies and clang-tidy + uses: ./.github/actions/install-iceoryx-deps-and-clang + - run: ./tools/ci/build-test-ubuntu.sh 32-bit-x86 + # Bazel sanity check build-test-ubuntu-bazel: # prevent stuck jobs consuming runners for 6 hours 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/doc/website/getting-started/installation.md b/doc/website/getting-started/installation.md index 27963728a9..2e01dea1ac 100644 --- a/doc/website/getting-started/installation.md +++ b/doc/website/getting-started/installation.md @@ -43,6 +43,13 @@ You will need to install the following packages: sudo apt install gcc g++ cmake libacl1-dev libncurses5-dev pkg-config ``` +To build iceoryx as 32-bit library, the following packages need to be installed additionally: + +```bash +sudo dpkg --add-architecture i386 +sudo apt install libacl1-dev:i386 libc6-dev-i386 libc6-dev-i386-cross libstdc++6-i386-cross gcc-multilib g++-multilib +``` + Additionally, there is an optional dependency to the [cpptoml](https://github.com/skystrife/cpptoml) library, which is used to parse the RouDi config file containing mempool configuration. ### QNX diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index da1acc58f0..07f658caa5 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -8,6 +8,7 @@ - The minimal supported GCC compiler is now 8.3 - The required C++ standard is now C++17 +- Experimental 32-bit support for all platforms supporting 64-bit atomic operations **Features:** @@ -73,6 +74,7 @@ class to enable or disable systemd support when running iceoryx [#2330](https:// **Bugfixes:** +- Fix compile-time conflict with Apache Arrow [\#2327](https://github.com/eclipse-iceoryx/iceoryx/issues/2327) - FreeBSD CI build is broken [\#1338](https://github.com/eclipse-iceoryx/iceoryx/issues/1338) - High CPU load in blocked publisher is reduced by introducing smart busy loop waiting (adaptive_wait) [\#1347](https://github.com/eclipse-iceoryx/iceoryx/issues/1347) - Compile Error : iceoryx_dds/Mempool.hpp: No such file or directory [\#1364](https://github.com/eclipse-iceoryx/iceoryx/issues/1364) @@ -139,6 +141,8 @@ class to enable or disable systemd support when running iceoryx [#2330](https:// - Listener examples need to take all samples in the callback [#2251](https://github.com/eclipse-iceoryx/iceoryx/issues/2251) - 'iox::string' tests can exceed the translation unit compilation timeout [#2278](https://github.com/eclipse-iceoryx/iceoryx/issues/2278) - Building iceoryx with bazel on Windows is broken [#2320](https://github.com/eclipse-iceoryx/iceoryx/issues/2320) +- Fix wrong memory orders in SpscSoFi [#2177](https://github.com/eclipse-iceoryx/iceoryx/issues/2177) +- ssize_t: redefinition; different basic types [#2209](https://github.com/eclipse-iceoryx/iceoryx/issues/2209) **Refactoring:** @@ -1471,5 +1475,3 @@ class to enable or disable systemd support when running iceoryx [#2330](https:// ``` 64. The non-functional `iox::popo::Node` was removed - -65. 32-bit support is disabled by default. For development purposes iceoryx can be build with the `-DIOX_IGNORE_32_BIT_CHECK=ON` diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/client.h b/iceoryx_binding_c/include/iceoryx_binding_c/client.h index 986414f09f..116badbb28 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/client.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/client.h @@ -1,4 +1,5 @@ // Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -23,7 +24,7 @@ #include "iceoryx_binding_c/types.h" /// @brief client handle -typedef CLASS UntypedClient* iox_client_t; +typedef IOX_C_CLASS UntypedClient* iox_client_t; /// @brief options to be set for a client typedef struct @@ -38,10 +39,10 @@ typedef struct bool connectOnCreate; /// @brief Sets whether the server blocks when the client response queue is full - ENUM iox_QueueFullPolicy responseQueueFullPolicy; + enum iox_QueueFullPolicy responseQueueFullPolicy; /// @brief Sets whether the client blocks when the server request queue is full - ENUM iox_ConsumerTooSlowPolicy serverTooSlowPolicy; + enum iox_ConsumerTooSlowPolicy serverTooSlowPolicy; /// @brief this value will be set exclusively by 'iox_client_options_init' and is not supposed to be modified /// otherwise @@ -87,9 +88,8 @@ void iox_client_deinit(iox_client_t const self); /// describes the error /// @note for the user-payload alignment 'IOX_C_CHUNK_DEFAULT_USER_PAYLOAD_ALIGNMENT' is used /// for a custom user-payload alignment please use 'iox_client_loan_aligned_request' -ENUM iox_AllocationResult iox_client_loan_request(iox_client_t const self, - void** const payload, - const uint64_t payloadSize); +enum iox_AllocationResult +iox_client_loan_request(iox_client_t const self, void** const payload, const uint64_t payloadSize); /// @brief allocates a request in the shared memory with a custom alignment for the user-payload /// @param[in] self handle of the client @@ -98,7 +98,7 @@ ENUM iox_AllocationResult iox_client_loan_request(iox_client_t const self, /// @param[in] payloadAlignment user-payload alignment of the allocated request /// @return on success it returns AllocationResult_SUCCESS otherwise a value which /// describes the error -ENUM iox_AllocationResult iox_client_loan_aligned_request(iox_client_t const self, +enum iox_AllocationResult iox_client_loan_aligned_request(iox_client_t const self, void** const payload, const uint64_t payloadSize, const uint32_t payloadAlignment); @@ -114,7 +114,7 @@ void iox_client_release_request(iox_client_t const self, void* const payload); /// @param[in] payload pointer to the user-payload of the request which should be send /// @return on success it returns ClientSendResult_SUCCESS otherwise a value which /// describes the error -ENUM iox_ClientSendResult iox_client_send(iox_client_t const self, void* const payload); +enum iox_ClientSendResult iox_client_send(iox_client_t const self, void* const payload); /// @brief connects to the service /// @param[in] self handle to the client @@ -128,14 +128,14 @@ void iox_client_disconnect(iox_client_t const self); /// @param[in] self handle to the client /// @return ConnectionState_CONNECTED when successfully connected otherwise an enum which /// describes the current state -ENUM iox_ConnectionState iox_client_get_connection_state(iox_client_t const self); +enum iox_ConnectionState iox_client_get_connection_state(iox_client_t const self); /// @brief retrieve a received respone /// @param[in] self handle to the client /// @param[in] payload pointer in which the pointer to the user-payload of the response is stored /// @return if a chunk could be received it returns ChunkReceiveResult_SUCCESS otherwise /// an enum which describes the error -ENUM iox_ChunkReceiveResult iox_client_take_response(iox_client_t const self, const void** const payload); +enum iox_ChunkReceiveResult iox_client_take_response(iox_client_t const self, const void** const payload); /// @brief release a previously acquired response (via iox_client_take_response) /// @param[in] self handle to the client diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/internal/c2cpp_binding.h b/iceoryx_binding_c/include/iceoryx_binding_c/internal/c2cpp_binding.h index 02787ed9ae..f4a1933560 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/internal/c2cpp_binding.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/internal/c2cpp_binding.h @@ -1,4 +1,5 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -21,16 +22,14 @@ #include -#define CLASS class -#define ENUM +#define IOX_C_CLASS class #else #include #include -#define CLASS struct -#define ENUM enum +#define IOX_C_CLASS struct #endif diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/internal/c2cpp_enum_translation.hpp b/iceoryx_binding_c/include/iceoryx_binding_c/internal/c2cpp_enum_translation.hpp index 84ef057f0f..d5efd761b9 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/internal/c2cpp_enum_translation.hpp +++ b/iceoryx_binding_c/include/iceoryx_binding_c/internal/c2cpp_enum_translation.hpp @@ -1,4 +1,5 @@ // Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -24,8 +25,8 @@ namespace c2cpp { -iox::popo::ConsumerTooSlowPolicy consumerTooSlowPolicy(const ENUM iox_ConsumerTooSlowPolicy policy) noexcept; -iox::popo::QueueFullPolicy queueFullPolicy(const ENUM iox_QueueFullPolicy policy) noexcept; +iox::popo::ConsumerTooSlowPolicy consumerTooSlowPolicy(const enum iox_ConsumerTooSlowPolicy policy) noexcept; +iox::popo::QueueFullPolicy queueFullPolicy(const enum iox_QueueFullPolicy policy) noexcept; iox::popo::SubscriberEvent subscriberEvent(const iox_SubscriberEvent value) noexcept; iox::popo::SubscriberState subscriberState(const iox_SubscriberState value) noexcept; diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/listener.h b/iceoryx_binding_c/include/iceoryx_binding_c/listener.h index 6aca47663d..79003640a9 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/listener.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/listener.h @@ -1,4 +1,5 @@ // Copyright (c) 2021 - 2022 Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -26,7 +27,7 @@ #include "iceoryx_binding_c/types.h" #include "iceoryx_binding_c/user_trigger.h" -typedef CLASS Listener* iox_listener_t; +typedef IOX_C_CLASS Listener* iox_listener_t; /// @brief initializes a listener struct from a storage struct pointer @@ -44,9 +45,9 @@ void iox_listener_deinit(iox_listener_t const self); /// @param[in] subscriberEvent the event which should trigger the listener /// @param[in] callback the callback which is called when an event triggers the listener /// @return when successful iox_ListenerResult::ListenerResult_SUCCESS otherwise an enum which describes the error -ENUM iox_ListenerResult iox_listener_attach_subscriber_event(iox_listener_t const self, +enum iox_ListenerResult iox_listener_attach_subscriber_event(iox_listener_t const self, iox_sub_t const subscriber, - const ENUM iox_SubscriberEvent subscriberEvent, + const enum iox_SubscriberEvent subscriberEvent, void (*callback)(iox_sub_t)); /// @brief Attaches a subscriber event to the listener. The callback has an additional contextData argument to provide @@ -57,10 +58,10 @@ ENUM iox_ListenerResult iox_listener_attach_subscriber_event(iox_listener_t cons /// @param[in] callback the callback which is called when an event triggers the listener /// @param[in] contextData a void pointer which is provided as second argument to the callback /// @return when successful iox_ListenerResult::ListenerResult_SUCCESS otherwise an enum which describes the error -ENUM iox_ListenerResult +enum iox_ListenerResult iox_listener_attach_subscriber_event_with_context_data(iox_listener_t const self, iox_sub_t const subscriber, - const ENUM iox_SubscriberEvent subscriberEvent, + const enum iox_SubscriberEvent subscriberEvent, void (*callback)(iox_sub_t, void*), void* const contextData); @@ -69,7 +70,7 @@ iox_listener_attach_subscriber_event_with_context_data(iox_listener_t const self /// @param[in] userTrigger user trigger which emits the event /// @param[in] callback the callback which is called when the user trigger triggers the listener /// @return when successful iox_ListenerResult::ListenerResult_SUCCESS otherwise an enum which describes the error -ENUM iox_ListenerResult iox_listener_attach_user_trigger_event(iox_listener_t const self, +enum iox_ListenerResult iox_listener_attach_user_trigger_event(iox_listener_t const self, iox_user_trigger_t const userTrigger, void (*callback)(iox_user_trigger_t)); @@ -80,7 +81,7 @@ ENUM iox_ListenerResult iox_listener_attach_user_trigger_event(iox_listener_t co /// @param[in] callback the callback which is called when the user trigger triggers the listener /// @param[in] contextData a void pointer which is provided as second argument to the callback /// @return when successful iox_ListenerResult::ListenerResult_SUCCESS otherwise an enum which describes the error -ENUM iox_ListenerResult iox_listener_attach_user_trigger_event_with_context_data(iox_listener_t const self, +enum iox_ListenerResult iox_listener_attach_user_trigger_event_with_context_data(iox_listener_t const self, iox_user_trigger_t const userTrigger, void (*callback)(iox_user_trigger_t, void*), @@ -92,7 +93,7 @@ ENUM iox_ListenerResult iox_listener_attach_user_trigger_event_with_context_data /// @param[in] subscriberEvent the subscriber event which is registered at the listener void iox_listener_detach_subscriber_event(iox_listener_t const self, iox_sub_t const subscriber, - const ENUM iox_SubscriberEvent subscriberEvent); + const enum iox_SubscriberEvent subscriberEvent); /// @brief Detaches a user trigger from the listener /// @param[in] self listener from which the event should be detached @@ -116,9 +117,9 @@ uint64_t iox_listener_capacity(iox_listener_t const self); /// @param[in] clientEvent the event which should trigger the listener /// @param[in] callback the callback which is called when an event triggers the listener /// @return when successful iox_ListenerResult::ListenerResult_SUCCESS otherwise an enum which describes the error -ENUM iox_ListenerResult iox_listener_attach_client_event(iox_listener_t const self, +enum iox_ListenerResult iox_listener_attach_client_event(iox_listener_t const self, iox_client_t const client, - const ENUM iox_ClientEvent clientEvent, + const enum iox_ClientEvent clientEvent, void (*callback)(iox_client_t)); /// @brief Attaches a client event to the listener. The callback has an additional contextData argument to provide @@ -129,9 +130,9 @@ ENUM iox_ListenerResult iox_listener_attach_client_event(iox_listener_t const se /// @param[in] callback the callback which is called when an event triggers the listener /// @param[in] contextData a void pointer which is provided as second argument to the callback /// @return when successful iox_ListenerResult::ListenerResult_SUCCESS otherwise an enum which describes the error -ENUM iox_ListenerResult iox_listener_attach_client_event_with_context_data(iox_listener_t const self, +enum iox_ListenerResult iox_listener_attach_client_event_with_context_data(iox_listener_t const self, iox_client_t const client, - const ENUM iox_ClientEvent clientEvent, + const enum iox_ClientEvent clientEvent, void (*callback)(iox_client_t, void*), void* const contextData); @@ -141,7 +142,7 @@ ENUM iox_ListenerResult iox_listener_attach_client_event_with_context_data(iox_l /// @param[in] clientEvent the event which should be removed from the listener void iox_listener_detach_client_event(iox_listener_t const self, iox_client_t const client, - const ENUM iox_ClientEvent clientEvent); + const enum iox_ClientEvent clientEvent); /// @brief Attaches a server event to the listener /// @param[in] self listener to which the event should be attached to @@ -149,9 +150,9 @@ void iox_listener_detach_client_event(iox_listener_t const self, /// @param[in] serverEvent the event which should trigger the listener /// @param[in] callback the callback which is called when an event triggers the listener /// @return when successful iox_ListenerResult::ListenerResult_SUCCESS otherwise an enum which describes the error -ENUM iox_ListenerResult iox_listener_attach_server_event(iox_listener_t const self, +enum iox_ListenerResult iox_listener_attach_server_event(iox_listener_t const self, iox_server_t const server, - const ENUM iox_ServerEvent serverEvent, + const enum iox_ServerEvent serverEvent, void (*callback)(iox_server_t)); /// @brief Attaches a server event to the listener. The callback has an additional contextData argument to provide @@ -162,9 +163,9 @@ ENUM iox_ListenerResult iox_listener_attach_server_event(iox_listener_t const se /// @param[in] callback the callback which is called when an event triggers the listener /// @param[in] contextData a void pointer which is provided as second argument to the callback /// @return when successful iox_ListenerResult::ListenerResult_SUCCESS otherwise an enum which describes the error -ENUM iox_ListenerResult iox_listener_attach_server_event_with_context_data(iox_listener_t const self, +enum iox_ListenerResult iox_listener_attach_server_event_with_context_data(iox_listener_t const self, iox_server_t const server, - const ENUM iox_ServerEvent serverEvent, + const enum iox_ServerEvent serverEvent, void (*callback)(iox_server_t, void*), void* const contextData); @@ -174,7 +175,7 @@ ENUM iox_ListenerResult iox_listener_attach_server_event_with_context_data(iox_l /// @param[in] serverEvent the event which should be removed from the listener void iox_listener_detach_server_event(iox_listener_t const self, iox_server_t const server, - const ENUM iox_ServerEvent serverEvent); + const enum iox_ServerEvent serverEvent); /// @brief Attaches a service discovery event to the listener /// @param[in] self listener to which the event should be attached to @@ -182,10 +183,10 @@ void iox_listener_detach_server_event(iox_listener_t const self, /// @param[in] serviceDiscoveryEvent the event which should trigger the listener /// @param[in] callback the callback which is called when an event triggers the listener /// @return when successful iox_ListenerResult::ListenerResult_SUCCESS otherwise an enum which describes the error -ENUM iox_ListenerResult +enum iox_ListenerResult iox_listener_attach_service_discovery_event(iox_listener_t const self, iox_service_discovery_t const serviceDiscovery, - const ENUM iox_ServiceDiscoveryEvent serviceDiscoveryEvent, + const enum iox_ServiceDiscoveryEvent serviceDiscoveryEvent, void (*callback)(iox_service_discovery_t)); /// @brief Attaches a service discovery event to the listener. The callback has an additional contextData argument to @@ -196,10 +197,10 @@ iox_listener_attach_service_discovery_event(iox_listener_t const self, /// @param[in] callback the callback which is called when an event triggers the listener /// @param[in] contextData a void pointer which is provided as second argument to the callback /// @return when successful iox_ListenerResult::ListenerResult_SUCCESS otherwise an enum which describes the error -ENUM iox_ListenerResult iox_listener_attach_service_discovery_event_with_context_data( +enum iox_ListenerResult iox_listener_attach_service_discovery_event_with_context_data( iox_listener_t const self, iox_service_discovery_t const serviceDiscovery, - const ENUM iox_ServiceDiscoveryEvent serviceDiscoveryEvent, + const enum iox_ServiceDiscoveryEvent serviceDiscoveryEvent, void (*callback)(iox_service_discovery_t, void*), void* const contextData); @@ -209,6 +210,6 @@ ENUM iox_ListenerResult iox_listener_attach_service_discovery_event_with_context /// @param[in] serviceDiscoveryEvent the service discovery event which should be removed from the listener void iox_listener_detach_service_discovery_event(iox_listener_t const self, iox_service_discovery_t const serviceDiscovery, - const ENUM iox_ServiceDiscoveryEvent serviceDiscoveryEvent); + const enum iox_ServiceDiscoveryEvent serviceDiscoveryEvent); #endif diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/notification_info.h b/iceoryx_binding_c/include/iceoryx_binding_c/notification_info.h index 9ad8a80735..ed7ab1bba9 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/notification_info.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/notification_info.h @@ -1,4 +1,5 @@ // Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -25,7 +26,7 @@ #include "iceoryx_binding_c/user_trigger.h" /// @brief notification info handle -typedef const CLASS NotificationInfo* iox_notification_info_t; +typedef const IOX_C_CLASS NotificationInfo* iox_notification_info_t; /// @brief returns the id of the notification /// @param[in] self handle to notification info diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/publisher.h b/iceoryx_binding_c/include/iceoryx_binding_c/publisher.h index 3fed75af8f..b6507b8a35 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/publisher.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/publisher.h @@ -1,5 +1,6 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2020 - 2021 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -40,7 +41,7 @@ typedef struct bool offerOnCreate; /// @brief describes whether a publisher blocks when subscriber queue is full - ENUM iox_ConsumerTooSlowPolicy subscriberTooSlowPolicy; + enum iox_ConsumerTooSlowPolicy subscriberTooSlowPolicy; /// @brief this value will be set exclusively by 'iox_pub_options_init' and is not supposed to be modified otherwise uint64_t initCheck; @@ -85,9 +86,8 @@ void iox_pub_deinit(iox_pub_t const self); /// describes the error /// @note for the user-payload alignment 'IOX_C_CHUNK_DEFAULT_USER_PAYLOAD_ALIGNMENT' is used /// for a custom user-payload alignment please use 'iox_pub_loan_aligned_chunk' -ENUM iox_AllocationResult iox_pub_loan_chunk(iox_pub_t const self, - void** const userPayload, - const uint64_t userPayloadSize); +enum iox_AllocationResult +iox_pub_loan_chunk(iox_pub_t const self, void** const userPayload, const uint64_t userPayloadSize); /// @brief allocates a chunk in the shared memory with a custom alignment for the user-payload /// @param[in] self handle of the publisher @@ -96,7 +96,7 @@ ENUM iox_AllocationResult iox_pub_loan_chunk(iox_pub_t const self, /// @param[in] userPayloadAlignment user-payload alignment of the allocated chunk /// @return on success it returns AllocationResult_SUCCESS otherwise a value which /// describes the error -ENUM iox_AllocationResult iox_pub_loan_aligned_chunk(iox_pub_t const self, +enum iox_AllocationResult iox_pub_loan_aligned_chunk(iox_pub_t const self, void** const userPayload, const uint64_t userPayloadSize, const uint32_t userPayloadAlignment); @@ -111,7 +111,7 @@ ENUM iox_AllocationResult iox_pub_loan_aligned_chunk(iox_pub_t const self, /// @param[in] userHeaderAlignment user-header alignment of the allocated chunk /// @return on success it returns AllocationResult_SUCCESS otherwise a value which /// describes the error -ENUM iox_AllocationResult iox_pub_loan_aligned_chunk_with_user_header(iox_pub_t const self, +enum iox_AllocationResult iox_pub_loan_aligned_chunk_with_user_header(iox_pub_t const self, void** const userPayload, const uint64_t userPayloadSize, const uint32_t userPayloadAlignment, diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/request_header.h b/iceoryx_binding_c/include/iceoryx_binding_c/request_header.h index 41b0753338..8f78ff9bfe 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/request_header.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/request_header.h @@ -1,4 +1,5 @@ // Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -21,10 +22,10 @@ #include "iceoryx_binding_c/internal/c2cpp_binding.h" /// @brief request header handle -typedef CLASS RequestHeader* iox_request_header_t; +typedef IOX_C_CLASS RequestHeader* iox_request_header_t; /// @brief const request header handle -typedef const CLASS RequestHeader* iox_const_request_header_t; +typedef const IOX_C_CLASS RequestHeader* iox_const_request_header_t; /// @brief extract the request header from a given payload /// @param[in] payload the pointer to the payload diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/response_header.h b/iceoryx_binding_c/include/iceoryx_binding_c/response_header.h index f6dae9c6fb..e3ce25dd5e 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/response_header.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/response_header.h @@ -1,4 +1,5 @@ // Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -21,10 +22,10 @@ #include "iceoryx_binding_c/internal/c2cpp_binding.h" /// @brief response header handle -typedef CLASS ResponseHeader* iox_response_header_t; +typedef IOX_C_CLASS ResponseHeader* iox_response_header_t; /// @brief const response header handle -typedef const CLASS ResponseHeader* iox_const_response_header_t; +typedef const IOX_C_CLASS ResponseHeader* iox_const_response_header_t; /// @brief extract the response header from a given payload /// @param[in] payload the pointer to the payload diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/server.h b/iceoryx_binding_c/include/iceoryx_binding_c/server.h index d53bf4aa95..a526a2fe5f 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/server.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/server.h @@ -1,4 +1,5 @@ // Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -23,7 +24,7 @@ #include "iceoryx_binding_c/types.h" /// @brief server handle -typedef CLASS UntypedServer* iox_server_t; +typedef IOX_C_CLASS UntypedServer* iox_server_t; /// @brief options to be set for a server typedef struct @@ -38,10 +39,10 @@ typedef struct bool offerOnCreate; /// @brief Sets whether the client blocks when the server request queue is full - ENUM iox_QueueFullPolicy requestQueueFullPolicy; + enum iox_QueueFullPolicy requestQueueFullPolicy; /// @brief Sets whether the server blocks when the client response queue is full - ENUM iox_ConsumerTooSlowPolicy clientTooSlowPolicy; + enum iox_ConsumerTooSlowPolicy clientTooSlowPolicy; /// @brief this value will be set exclusively by 'iox_server_options_init' and is not supposed to be modified /// otherwise @@ -84,7 +85,7 @@ void iox_server_deinit(iox_server_t const self); /// @param[in] payload pointer in which the pointer to the user-payload of the request is stored /// @return if a chunk could be received it returns ChunkReceiveResult_SUCCESS otherwise /// an enum which describes the error -ENUM iox_ServerRequestResult iox_server_take_request(iox_server_t const self, const void** const payload); +enum iox_ServerRequestResult iox_server_take_request(iox_server_t const self, const void** const payload); /// @brief release a previously acquired request (via iox_server_take_request) /// @param[in] self handle to the server @@ -100,7 +101,7 @@ void iox_server_release_request(iox_server_t const self, const void* const paylo /// describes the error /// @note for the user-payload alignment 'IOX_C_CHUNK_DEFAULT_USER_PAYLOAD_ALIGNMENT' is used /// for a custom user-payload alignment please use 'iox_server_loan_aligned_response' -ENUM iox_AllocationResult iox_server_loan_response(iox_server_t const self, +enum iox_AllocationResult iox_server_loan_response(iox_server_t const self, const void* const requestPayload, void** const payload, const uint64_t payloadSize); @@ -113,7 +114,7 @@ ENUM iox_AllocationResult iox_server_loan_response(iox_server_t const self, /// @param[in] payloadAlignment user-payload alignment of the allocated request /// @return on success it returns AllocationResult_SUCCESS otherwise a value which /// describes the error -ENUM iox_AllocationResult iox_server_loan_aligned_response(iox_server_t const self, +enum iox_AllocationResult iox_server_loan_aligned_response(iox_server_t const self, const void* const requestPayload, void** const payload, const uint64_t payloadSize, @@ -124,7 +125,7 @@ ENUM iox_AllocationResult iox_server_loan_aligned_response(iox_server_t const se /// @param[in] payload pointer to the user-payload of the response which should be send /// @return on success it returns ServerSendResult_SUCCESS otherwise a value which /// describes the error -ENUM iox_ServerSendResult iox_server_send(iox_server_t const self, void* const payload); +enum iox_ServerSendResult iox_server_send(iox_server_t const self, void* const payload); /// @brief releases ownership of a previously allocated loaned response without sending it /// @param[in] self handle of the server diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/service_discovery.h b/iceoryx_binding_c/include/iceoryx_binding_c/service_discovery.h index b48d821143..33573573cb 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/service_discovery.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/service_discovery.h @@ -1,4 +1,5 @@ // Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -23,7 +24,7 @@ #include "service_description.h" /// @brief service discovery handle -typedef CLASS ServiceDiscovery* iox_service_discovery_t; +typedef IOX_C_CLASS ServiceDiscovery* iox_service_discovery_t; /// @brief initializes a service discovery from a storage struct pointer /// @param[in] self pointer to raw memory which can hold a service discovery @@ -53,7 +54,7 @@ uint64_t iox_service_discovery_find_service(iox_service_discovery_t const self, iox_service_description_t* const serviceContainer, const uint64_t serviceContainerCapacity, uint64_t* missedServices, - const ENUM iox_MessagingPattern pattern); + const enum iox_MessagingPattern pattern); /// @brief Searches all services with the given messaging pattern that match the provided service description and /// applies a function to each of them @@ -68,7 +69,7 @@ void iox_service_discovery_find_service_apply_callable(iox_service_discovery_t c const char* const instance, const char* const event, void (*callable)(const iox_service_description_t), - const ENUM iox_MessagingPattern pattern); + const enum iox_MessagingPattern pattern); /// @brief Searches all services with the given messaging pattern that match the provided service description and /// applies a function to each of them. A second parameter for the function can be provided as contextData. @@ -86,6 +87,6 @@ void iox_service_discovery_find_service_apply_callable_with_context_data( const char* const event, void (*callable)(const iox_service_description_t, void*), void* const contextData, - const ENUM iox_MessagingPattern pattern); + const enum iox_MessagingPattern pattern); #endif diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/subscriber.h b/iceoryx_binding_c/include/iceoryx_binding_c/subscriber.h index 416f5dc910..da7beb0575 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/subscriber.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/subscriber.h @@ -1,5 +1,6 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -43,7 +44,7 @@ typedef struct bool subscribeOnCreate; /// @brief describes whether a publisher blocks when subscriber queue is full - ENUM iox_QueueFullPolicy queueFullPolicy; + enum iox_QueueFullPolicy queueFullPolicy; /// @brief Indicates whether we require the publisher to have historyCapacity > 0. /// If true and the condition is not met (i.e. historyCapacity = 0), the subscriber will @@ -97,14 +98,14 @@ void iox_sub_unsubscribe(iox_sub_t const self); /// @param[in] self handle to the subscriber /// @return SubscribeState_SUBSCRIBED when successfully subscribed otherwise an enum which /// describes the current state -ENUM iox_SubscribeState iox_sub_get_subscription_state(iox_sub_t const self); +enum iox_SubscribeState iox_sub_get_subscription_state(iox_sub_t const self); /// @brief retrieve a received chunk /// @param[in] self handle to the subscriber /// @param[in] userPayload pointer in which the pointer to the user-payload of the chunk is stored /// @return if a chunk could be received it returns ChunkReceiveResult_SUCCESS otherwise /// an enum which describes the error -ENUM iox_ChunkReceiveResult iox_sub_take_chunk(iox_sub_t const self, const void** const userPayload); +enum iox_ChunkReceiveResult iox_sub_take_chunk(iox_sub_t const self, const void** const userPayload); /// @brief release a previously acquired chunk (via iox_sub_take_chunk) /// @param[in] self handle to the subscriber diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/user_trigger.h b/iceoryx_binding_c/include/iceoryx_binding_c/user_trigger.h index f09bebd5f2..8fdb845bdd 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/user_trigger.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/user_trigger.h @@ -1,5 +1,6 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2020 - 2021 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -22,7 +23,7 @@ #include "iceoryx_binding_c/types.h" /// @brief user trigger handle -typedef CLASS UserTrigger* iox_user_trigger_t; +typedef IOX_C_CLASS UserTrigger* iox_user_trigger_t; /// @brief initialize user trigger handle /// @param[in] self pointer to preallocated memory of size = sizeof(iox_user_trigger_storage_t) diff --git a/iceoryx_binding_c/include/iceoryx_binding_c/wait_set.h b/iceoryx_binding_c/include/iceoryx_binding_c/wait_set.h index 3624235d40..a439897a39 100644 --- a/iceoryx_binding_c/include/iceoryx_binding_c/wait_set.h +++ b/iceoryx_binding_c/include/iceoryx_binding_c/wait_set.h @@ -1,5 +1,6 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2020 - 2022 Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -30,7 +31,7 @@ #include /// @brief wait set handle -typedef CLASS cpp2c_WaitSet* iox_ws_t; +typedef IOX_C_CLASS cpp2c_WaitSet* iox_ws_t; /// @brief initialize wait set handle /// @param[in] self pointer to preallocated memory of size = sizeof(iox_ws_storage_t) @@ -89,9 +90,9 @@ void iox_ws_mark_for_destruction(iox_ws_t const self); /// @param[in] callback a callback which is attached to the state /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult iox_ws_attach_subscriber_state(iox_ws_t const self, +enum iox_WaitSetResult iox_ws_attach_subscriber_state(iox_ws_t const self, iox_sub_t const subscriber, - const ENUM iox_SubscriberState subscriberState, + const enum iox_SubscriberState subscriberState, const uint64_t id, void (*callback)(iox_sub_t)); @@ -105,9 +106,9 @@ ENUM iox_WaitSetResult iox_ws_attach_subscriber_state(iox_ws_t const self, /// @param[in] contextData a void pointer which is provided as second argument to the callback /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult iox_ws_attach_subscriber_state_with_context_data(iox_ws_t const self, +enum iox_WaitSetResult iox_ws_attach_subscriber_state_with_context_data(iox_ws_t const self, iox_sub_t const subscriber, - const ENUM iox_SubscriberState subscriberState, + const enum iox_SubscriberState subscriberState, const uint64_t id, void (*callback)(iox_sub_t, void*), void* const contextData); @@ -120,9 +121,9 @@ ENUM iox_WaitSetResult iox_ws_attach_subscriber_state_with_context_data(iox_ws_t /// @param[in] callback a callback which is attached to the event /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult iox_ws_attach_subscriber_event(iox_ws_t const self, +enum iox_WaitSetResult iox_ws_attach_subscriber_event(iox_ws_t const self, iox_sub_t const subscriber, - const ENUM iox_SubscriberEvent subscriberEvent, + const enum iox_SubscriberEvent subscriberEvent, const uint64_t eventId, void (*callback)(iox_sub_t)); @@ -136,9 +137,9 @@ ENUM iox_WaitSetResult iox_ws_attach_subscriber_event(iox_ws_t const self, /// @param[in] contextData a void pointer which is provided as second argument to the callback /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult iox_ws_attach_subscriber_event_with_context_data(iox_ws_t const self, +enum iox_WaitSetResult iox_ws_attach_subscriber_event_with_context_data(iox_ws_t const self, iox_sub_t const subscriber, - const ENUM iox_SubscriberEvent subscriberEvent, + const enum iox_SubscriberEvent subscriberEvent, const uint64_t eventId, void (*callback)(iox_sub_t, void*), void* const contextData); @@ -150,7 +151,7 @@ ENUM iox_WaitSetResult iox_ws_attach_subscriber_event_with_context_data(iox_ws_t /// @param[in] callback a callback which is attached to the event /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult iox_ws_attach_user_trigger_event(iox_ws_t const self, +enum iox_WaitSetResult iox_ws_attach_user_trigger_event(iox_ws_t const self, iox_user_trigger_t const userTrigger, const uint64_t eventId, void (*callback)(iox_user_trigger_t)); @@ -164,7 +165,7 @@ ENUM iox_WaitSetResult iox_ws_attach_user_trigger_event(iox_ws_t const self, /// @param[in] contextData a void pointer which is provided as second argument to the callback /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult iox_ws_attach_user_trigger_event_with_context_data(iox_ws_t const self, +enum iox_WaitSetResult iox_ws_attach_user_trigger_event_with_context_data(iox_ws_t const self, iox_user_trigger_t const userTrigger, const uint64_t eventId, void (*callback)(iox_user_trigger_t, void*), @@ -176,7 +177,7 @@ ENUM iox_WaitSetResult iox_ws_attach_user_trigger_event_with_context_data(iox_ws /// @param[in] subscriberEvent the event which should be detached from the subscriber void iox_ws_detach_subscriber_event(iox_ws_t const self, iox_sub_t const subscriber, - const ENUM iox_SubscriberEvent subscriberEvent); + const enum iox_SubscriberEvent subscriberEvent); /// @brief detaches a subscriber state from a waitset /// @param[in] self handle to the waitset @@ -184,7 +185,7 @@ void iox_ws_detach_subscriber_event(iox_ws_t const self, /// @param[in] subscriberState the state which should be detached from the subscriber void iox_ws_detach_subscriber_state(iox_ws_t const self, iox_sub_t const subscriber, - const ENUM iox_SubscriberState subscriberState); + const enum iox_SubscriberState subscriberState); /// @brief detaches a user trigger event from a waitset /// @param[in] self handle to the waitset @@ -199,9 +200,9 @@ void iox_ws_detach_user_trigger_event(iox_ws_t const self, iox_user_trigger_t co /// @param[in] callback a callback which is attached to the event /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult iox_ws_attach_client_event(const iox_ws_t self, +enum iox_WaitSetResult iox_ws_attach_client_event(const iox_ws_t self, const iox_client_t client, - const ENUM iox_ClientEvent clientEvent, + const enum iox_ClientEvent clientEvent, const uint64_t eventId, void (*callback)(iox_client_t)); @@ -214,9 +215,9 @@ ENUM iox_WaitSetResult iox_ws_attach_client_event(const iox_ws_t self, /// @param[in] contextData a void pointer which is provided as second argument to the callback /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult iox_ws_attach_client_event_with_context_data(iox_ws_t const self, +enum iox_WaitSetResult iox_ws_attach_client_event_with_context_data(iox_ws_t const self, iox_client_t const client, - const ENUM iox_ClientEvent clientEvent, + const enum iox_ClientEvent clientEvent, const uint64_t eventId, void (*callback)(iox_client_t, void*), void* const contextData); @@ -229,9 +230,9 @@ ENUM iox_WaitSetResult iox_ws_attach_client_event_with_context_data(iox_ws_t con /// @param[in] callback a callback which is attached to the state /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult iox_ws_attach_client_state(const iox_ws_t self, +enum iox_WaitSetResult iox_ws_attach_client_state(const iox_ws_t self, const iox_client_t client, - const ENUM iox_ClientState clientState, + const enum iox_ClientState clientState, const uint64_t eventId, void (*callback)(iox_client_t)); @@ -244,9 +245,9 @@ ENUM iox_WaitSetResult iox_ws_attach_client_state(const iox_ws_t self, /// @param[in] contextData a void pointer which is provided as second argument to the callback /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult iox_ws_attach_client_state_with_context_data(iox_ws_t const self, +enum iox_WaitSetResult iox_ws_attach_client_state_with_context_data(iox_ws_t const self, iox_client_t const client, - const ENUM iox_ClientState clientState, + const enum iox_ClientState clientState, const uint64_t eventId, void (*callback)(iox_client_t, void*), void* const contextData); @@ -255,13 +256,13 @@ ENUM iox_WaitSetResult iox_ws_attach_client_state_with_context_data(iox_ws_t con /// @param[in] self handle to the waitset /// @param[in] client the client which should be detached /// @param[in] clientEvent the event which should be detached from the client -void iox_ws_detach_client_event(iox_ws_t const self, iox_client_t const client, const ENUM iox_ClientEvent clientEvent); +void iox_ws_detach_client_event(iox_ws_t const self, iox_client_t const client, const enum iox_ClientEvent clientEvent); /// @brief detaches a client state from a waitset /// @param[in] self handle to the waitset /// @param[in] client the client which should be detached /// @param[in] clientState the state which should be detached from the client -void iox_ws_detach_client_state(iox_ws_t const self, iox_client_t const client, const ENUM iox_ClientState clientState); +void iox_ws_detach_client_state(iox_ws_t const self, iox_client_t const client, const enum iox_ClientState clientState); /// @brief attaches a server event to a waitset /// @param[in] self handle to the waitset @@ -271,9 +272,9 @@ void iox_ws_detach_client_state(iox_ws_t const self, iox_client_t const client, /// @param[in] callback a callback which is attached to the event /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult iox_ws_attach_server_event(const iox_ws_t self, +enum iox_WaitSetResult iox_ws_attach_server_event(const iox_ws_t self, const iox_server_t server, - const ENUM iox_ServerEvent serverEvent, + const enum iox_ServerEvent serverEvent, const uint64_t eventId, void (*callback)(iox_server_t)); @@ -286,9 +287,9 @@ ENUM iox_WaitSetResult iox_ws_attach_server_event(const iox_ws_t self, /// @param[in] contextData a void pointer which is provided as second argument to the callback /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult iox_ws_attach_server_event_with_context_data(iox_ws_t const self, +enum iox_WaitSetResult iox_ws_attach_server_event_with_context_data(iox_ws_t const self, iox_server_t const server, - const ENUM iox_ServerEvent serverEvent, + const enum iox_ServerEvent serverEvent, const uint64_t eventId, void (*callback)(iox_server_t, void*), void* const contextData); @@ -301,9 +302,9 @@ ENUM iox_WaitSetResult iox_ws_attach_server_event_with_context_data(iox_ws_t con /// @param[in] callback a callback which is attached to the state /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult iox_ws_attach_server_state(const iox_ws_t self, +enum iox_WaitSetResult iox_ws_attach_server_state(const iox_ws_t self, const iox_server_t server, - const ENUM iox_ServerState serverState, + const enum iox_ServerState serverState, const uint64_t eventId, void (*callback)(iox_server_t)); @@ -316,9 +317,9 @@ ENUM iox_WaitSetResult iox_ws_attach_server_state(const iox_ws_t self, /// @param[in] contextData a void pointer which is provided as second argument to the callback /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult iox_ws_attach_server_state_with_context_data(iox_ws_t const self, +enum iox_WaitSetResult iox_ws_attach_server_state_with_context_data(iox_ws_t const self, iox_server_t const server, - const ENUM iox_ServerState serverState, + const enum iox_ServerState serverState, const uint64_t eventId, void (*callback)(iox_server_t, void*), void* const contextData); @@ -327,13 +328,13 @@ ENUM iox_WaitSetResult iox_ws_attach_server_state_with_context_data(iox_ws_t con /// @param[in] self handle to the waitset /// @param[in] server the server which should be detached /// @param[in] serverEvent the event which should be detached from the server -void iox_ws_detach_server_event(iox_ws_t const self, iox_server_t const server, const ENUM iox_ServerEvent serverEvent); +void iox_ws_detach_server_event(iox_ws_t const self, iox_server_t const server, const enum iox_ServerEvent serverEvent); /// @brief detaches a server state from a waitset /// @param[in] self handle to the waitset /// @param[in] server the server which should be detached /// @param[in] serverState the state which should be detached from the server -void iox_ws_detach_server_state(iox_ws_t const self, iox_server_t const server, const ENUM iox_ServerState serverState); +void iox_ws_detach_server_state(iox_ws_t const self, iox_server_t const server, const enum iox_ServerState serverState); /// @brief attaches a service discovery event to a waitset /// @param[in] self handle to the waitset @@ -343,9 +344,9 @@ void iox_ws_detach_server_state(iox_ws_t const self, iox_server_t const server, /// @param[in] callback a callback which is attached to the event /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult iox_ws_attach_service_discovery_event(const iox_ws_t self, +enum iox_WaitSetResult iox_ws_attach_service_discovery_event(const iox_ws_t self, const iox_service_discovery_t serviceDiscovery, - const ENUM iox_ServiceDiscoveryEvent serviceDiscoveryEvent, + const enum iox_ServiceDiscoveryEvent serviceDiscoveryEvent, const uint64_t eventId, void (*callback)(iox_service_discovery_t)); @@ -358,10 +359,10 @@ ENUM iox_WaitSetResult iox_ws_attach_service_discovery_event(const iox_ws_t self /// @param[in] contextData a void pointer which is provided as second argument to the callback /// @return if the attaching was successfull it returns WaitSetResult_SUCCESS, otherwise /// an enum which describes the error -ENUM iox_WaitSetResult +enum iox_WaitSetResult iox_ws_attach_service_discovery_event_with_context_data(iox_ws_t const self, iox_service_discovery_t const serviceDiscovery, - const ENUM iox_ServiceDiscoveryEvent serviceDiscoveryEvent, + const enum iox_ServiceDiscoveryEvent serviceDiscoveryEvent, const uint64_t eventId, void (*callback)(iox_service_discovery_t, void*), void* const contextData); @@ -372,6 +373,6 @@ iox_ws_attach_service_discovery_event_with_context_data(iox_ws_t const self, /// @param[in] serviceDiscoveryEvent the event which should be detached from the service discovery void iox_ws_detach_service_discovery_event(iox_ws_t const self, iox_service_discovery_t const serviceDiscovery, - const ENUM iox_ServiceDiscoveryEvent serviceDiscoveryEvent); + const enum iox_ServiceDiscoveryEvent serviceDiscoveryEvent); #endif diff --git a/iceoryx_binding_c/source/c2cpp_enum_translation.cpp b/iceoryx_binding_c/source/c2cpp_enum_translation.cpp index 2f36ed4c9e..d38e6e9a32 100644 --- a/iceoryx_binding_c/source/c2cpp_enum_translation.cpp +++ b/iceoryx_binding_c/source/c2cpp_enum_translation.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -21,7 +22,7 @@ namespace c2cpp { -iox::popo::ConsumerTooSlowPolicy consumerTooSlowPolicy(const ENUM iox_ConsumerTooSlowPolicy policy) noexcept +iox::popo::ConsumerTooSlowPolicy consumerTooSlowPolicy(const enum iox_ConsumerTooSlowPolicy policy) noexcept { switch (policy) { @@ -35,7 +36,7 @@ iox::popo::ConsumerTooSlowPolicy consumerTooSlowPolicy(const ENUM iox_ConsumerTo return iox::popo::ConsumerTooSlowPolicy::DISCARD_OLDEST_DATA; } -iox::popo::QueueFullPolicy queueFullPolicy(const ENUM iox_QueueFullPolicy policy) noexcept +iox::popo::QueueFullPolicy queueFullPolicy(const enum iox_QueueFullPolicy policy) noexcept { switch (policy) { diff --git a/iceoryx_binding_c/source/c_listener.cpp b/iceoryx_binding_c/source/c_listener.cpp index e369a30c9c..9e888b09fa 100644 --- a/iceoryx_binding_c/source/c_listener.cpp +++ b/iceoryx_binding_c/source/c_listener.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2021 - 2022 Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -49,9 +50,9 @@ void iox_listener_deinit(iox_listener_t const self) delete self; } -ENUM iox_ListenerResult iox_listener_attach_subscriber_event(iox_listener_t const self, +enum iox_ListenerResult iox_listener_attach_subscriber_event(iox_listener_t const self, iox_sub_t const subscriber, - const ENUM iox_SubscriberEvent subscriberEvent, + const enum iox_SubscriberEvent subscriberEvent, void (*callback)(iox_sub_t)) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); @@ -69,10 +70,10 @@ ENUM iox_ListenerResult iox_listener_attach_subscriber_event(iox_listener_t cons return ListenerResult_SUCCESS; } -ENUM iox_ListenerResult +enum iox_ListenerResult iox_listener_attach_subscriber_event_with_context_data(iox_listener_t const self, iox_sub_t const subscriber, - const ENUM iox_SubscriberEvent subscriberEvent, + const enum iox_SubscriberEvent subscriberEvent, void (*callback)(iox_sub_t, void*), void* const contextData) { @@ -91,7 +92,7 @@ iox_listener_attach_subscriber_event_with_context_data(iox_listener_t const self return ListenerResult_SUCCESS; } -ENUM iox_ListenerResult iox_listener_attach_user_trigger_event(iox_listener_t const self, +enum iox_ListenerResult iox_listener_attach_user_trigger_event(iox_listener_t const self, iox_user_trigger_t const userTrigger, void (*callback)(iox_user_trigger_t)) { @@ -108,7 +109,7 @@ ENUM iox_ListenerResult iox_listener_attach_user_trigger_event(iox_listener_t co return ListenerResult_SUCCESS; } -ENUM iox_ListenerResult iox_listener_attach_user_trigger_event_with_context_data(iox_listener_t const self, +enum iox_ListenerResult iox_listener_attach_user_trigger_event_with_context_data(iox_listener_t const self, iox_user_trigger_t const userTrigger, void (*callback)(iox_user_trigger_t, void*), @@ -133,7 +134,7 @@ ENUM iox_ListenerResult iox_listener_attach_user_trigger_event_with_context_data void iox_listener_detach_subscriber_event(iox_listener_t const self, iox_sub_t const subscriber, - const ENUM iox_SubscriberEvent subscriberEvent) + const enum iox_SubscriberEvent subscriberEvent) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); IOX_ENFORCE(subscriber != nullptr, "'subscriver' must not be a 'nullptr'"); @@ -165,7 +166,7 @@ uint64_t iox_listener_capacity(iox_listener_t const self) iox_ListenerResult iox_listener_attach_client_event(iox_listener_t const self, iox_client_t const client, - const ENUM iox_ClientEvent clientEvent, + const enum iox_ClientEvent clientEvent, void (*callback)(iox_client_t)) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); @@ -181,7 +182,7 @@ iox_ListenerResult iox_listener_attach_client_event(iox_listener_t const self, iox_ListenerResult iox_listener_attach_client_event_with_context_data(iox_listener_t const self, iox_client_t const client, - const ENUM iox_ClientEvent clientEvent, + const enum iox_ClientEvent clientEvent, void (*callback)(iox_client_t, void*), void* const contextData) { @@ -199,7 +200,7 @@ iox_ListenerResult iox_listener_attach_client_event_with_context_data(iox_listen void iox_listener_detach_client_event(iox_listener_t const self, iox_client_t const client, - const ENUM iox_ClientEvent clientEvent) + const enum iox_ClientEvent clientEvent) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); IOX_ENFORCE(client != nullptr, "'client' must not be a 'nullptr'"); @@ -210,7 +211,7 @@ void iox_listener_detach_client_event(iox_listener_t const self, iox_ListenerResult iox_listener_attach_server_event(iox_listener_t const self, iox_server_t const server, - const ENUM iox_ServerEvent serverEvent, + const enum iox_ServerEvent serverEvent, void (*callback)(iox_server_t)) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); @@ -226,7 +227,7 @@ iox_ListenerResult iox_listener_attach_server_event(iox_listener_t const self, iox_ListenerResult iox_listener_attach_server_event_with_context_data(iox_listener_t const self, iox_server_t const server, - const ENUM iox_ServerEvent serverEvent, + const enum iox_ServerEvent serverEvent, void (*callback)(iox_server_t, void*), void* const contextData) { @@ -244,7 +245,7 @@ iox_ListenerResult iox_listener_attach_server_event_with_context_data(iox_listen void iox_listener_detach_server_event(iox_listener_t const self, iox_server_t const server, - const ENUM iox_ServerEvent serverEvent) + const enum iox_ServerEvent serverEvent) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); IOX_ENFORCE(server != nullptr, "'server' must not be a 'nullptr'"); @@ -255,7 +256,7 @@ void iox_listener_detach_server_event(iox_listener_t const self, iox_ListenerResult iox_listener_attach_service_discovery_event(iox_listener_t const self, iox_service_discovery_t const serviceDiscovery, - const ENUM iox_ServiceDiscoveryEvent serviceDiscoveryEvent, + const enum iox_ServiceDiscoveryEvent serviceDiscoveryEvent, void (*callback)(iox_service_discovery_t)) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); @@ -273,7 +274,7 @@ iox_listener_attach_service_discovery_event(iox_listener_t const self, iox_ListenerResult iox_listener_attach_service_discovery_event_with_context_data( iox_listener_t const self, iox_service_discovery_t const serviceDiscovery, - const ENUM iox_ServiceDiscoveryEvent serviceDiscoveryEvent, + const enum iox_ServiceDiscoveryEvent serviceDiscoveryEvent, void (*callback)(iox_service_discovery_t, void*), void* const contextData) { @@ -291,7 +292,7 @@ iox_ListenerResult iox_listener_attach_service_discovery_event_with_context_data void iox_listener_detach_service_discovery_event(iox_listener_t const self, iox_service_discovery_t const serviceDiscovery, - const ENUM iox_ServiceDiscoveryEvent serviceDiscoveryEvent) + const enum iox_ServiceDiscoveryEvent serviceDiscoveryEvent) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); IOX_ENFORCE(serviceDiscovery != nullptr, "'serviceDiscovery' must not be a 'nullptr'"); diff --git a/iceoryx_binding_c/source/c_runtime.cpp b/iceoryx_binding_c/source/c_runtime.cpp index e343156f4b..a532046d00 100644 --- a/iceoryx_binding_c/source/c_runtime.cpp +++ b/iceoryx_binding_c/source/c_runtime.cpp @@ -42,7 +42,7 @@ uint64_t iox_runtime_get_instance_name(char* const name, const uint64_t nameLeng } auto instanceName = PoshRuntime::getInstance().getInstanceName(); - std::strncpy(name, instanceName.c_str(), nameLength); + std::strncpy(name, instanceName.c_str(), static_cast(nameLength)); name[nameLength - 1U] = '\0'; // strncpy doesn't add a null-termination if destination is smaller than source return instanceName.size(); diff --git a/iceoryx_binding_c/source/c_service_discovery.cpp b/iceoryx_binding_c/source/c_service_discovery.cpp index 517bff51d6..77650766ef 100644 --- a/iceoryx_binding_c/source/c_service_discovery.cpp +++ b/iceoryx_binding_c/source/c_service_discovery.cpp @@ -1,4 +1,5 @@ // Copyright (c) 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -50,7 +51,7 @@ uint64_t iox_service_discovery_find_service(iox_service_discovery_t const self, iox_service_description_t* const serviceContainer, const uint64_t serviceContainerCapacity, uint64_t* missedServices, - const ENUM iox_MessagingPattern pattern) + const enum iox_MessagingPattern pattern) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); IOX_ENFORCE(serviceContainer != nullptr, "'serviceContainer' must not be a 'nullptr'"); @@ -94,7 +95,7 @@ void iox_service_discovery_find_service_apply_callable(iox_service_discovery_t c const char* const instance, const char* const event, void (*callable)(const iox_service_description_t), - const ENUM iox_MessagingPattern pattern) + const enum iox_MessagingPattern pattern) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); IOX_ENFORCE(callable != nullptr, "'callable' must not be a 'nullptr'"); @@ -126,7 +127,7 @@ void iox_service_discovery_find_service_apply_callable_with_context_data( const char* const event, void (*callable)(const iox_service_description_t, void*), void* const contextData, - const ENUM iox_MessagingPattern pattern) + const enum iox_MessagingPattern pattern) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); IOX_ENFORCE(callable != nullptr, "'callable' must not be a 'nullptr'"); diff --git a/iceoryx_binding_c/source/c_subscriber.cpp b/iceoryx_binding_c/source/c_subscriber.cpp index 9886ebce3b..0cb263c68e 100644 --- a/iceoryx_binding_c/source/c_subscriber.cpp +++ b/iceoryx_binding_c/source/c_subscriber.cpp @@ -110,8 +110,9 @@ iox_sub_t iox_sub_init(iox_sub_storage_t* self, auto meWithStoragePointer = new SubscriberWithStoragePointer(); meWithStoragePointer->subscriberStorage = self; auto me = &meWithStoragePointer->subscriber; - assert(reinterpret_cast(me) - reinterpret_cast(meWithStoragePointer) == sizeof(void*) - && "Size mismatch for SubscriberWithStoragePointer!"); + auto ptrDiff = reinterpret_cast(me) - reinterpret_cast(meWithStoragePointer); + IOX_ENFORCE(ptrDiff >= sizeof(void*), "Size mismatch for SubscriberWithStoragePointer!"); + IOX_ENFORCE(ptrDiff <= 2 * sizeof(void*), "Size mismatch for SubscriberWithStoragePointer!"); me->m_portData = PoshRuntime::getInstance().getMiddlewareSubscriber(ServiceDescription{IdString_t(TruncateToCapacity, service), diff --git a/iceoryx_binding_c/source/c_wait_set.cpp b/iceoryx_binding_c/source/c_wait_set.cpp index 9a599251cd..f4cf1ed5cb 100644 --- a/iceoryx_binding_c/source/c_wait_set.cpp +++ b/iceoryx_binding_c/source/c_wait_set.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved. // Copyright (c) 2020 - 2022 by Apex.AI Inc. All rights reserved. +// Copyright (c) 2024 by Michael Bentley . 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. @@ -259,7 +260,7 @@ iox_WaitSetResult iox_ws_attach_client_event(const iox_ws_t self, iox_WaitSetResult iox_ws_attach_client_event_with_context_data(iox_ws_t const self, iox_client_t const client, - const ENUM iox_ClientEvent clientEvent, + const enum iox_ClientEvent clientEvent, const uint64_t eventId, void (*callback)(iox_client_t, void*), void* const contextData) @@ -290,7 +291,7 @@ iox_WaitSetResult iox_ws_attach_client_state(const iox_ws_t self, iox_WaitSetResult iox_ws_attach_client_state_with_context_data(iox_ws_t const self, iox_client_t const client, - const ENUM iox_ClientState clientState, + const enum iox_ClientState clientState, const uint64_t eventId, void (*callback)(iox_client_t, void*), void* const contextData) @@ -306,7 +307,7 @@ iox_WaitSetResult iox_ws_attach_client_state_with_context_data(iox_ws_t const se return (result.has_error()) ? cpp2c::waitSetResult(result.error()) : iox_WaitSetResult::WaitSetResult_SUCCESS; } -void iox_ws_detach_client_event(iox_ws_t const self, iox_client_t const client, const ENUM iox_ClientEvent clientEvent) +void iox_ws_detach_client_event(iox_ws_t const self, iox_client_t const client, const enum iox_ClientEvent clientEvent) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); IOX_ENFORCE(client != nullptr, "'client' must not be a 'nullptr'"); @@ -314,7 +315,7 @@ void iox_ws_detach_client_event(iox_ws_t const self, iox_client_t const client, self->detachEvent(*client, c2cpp::clientEvent(clientEvent)); } -void iox_ws_detach_client_state(iox_ws_t const self, iox_client_t const client, const ENUM iox_ClientState clientState) +void iox_ws_detach_client_state(iox_ws_t const self, iox_client_t const client, const enum iox_ClientState clientState) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); IOX_ENFORCE(client != nullptr, "'client' must not be a 'nullptr'"); @@ -324,7 +325,7 @@ void iox_ws_detach_client_state(iox_ws_t const self, iox_client_t const client, iox_WaitSetResult iox_ws_attach_server_event(const iox_ws_t self, const iox_server_t server, - const ENUM iox_ServerEvent serverEvent, + const enum iox_ServerEvent serverEvent, const uint64_t eventId, void (*callback)(iox_server_t)) { @@ -337,7 +338,7 @@ iox_WaitSetResult iox_ws_attach_server_event(const iox_ws_t self, iox_WaitSetResult iox_ws_attach_server_event_with_context_data(iox_ws_t const self, iox_server_t const server, - const ENUM iox_ServerEvent serverEvent, + const enum iox_ServerEvent serverEvent, const uint64_t eventId, void (*callback)(iox_server_t, void*), void* const contextData) @@ -355,7 +356,7 @@ iox_WaitSetResult iox_ws_attach_server_event_with_context_data(iox_ws_t const se iox_WaitSetResult iox_ws_attach_server_state(const iox_ws_t self, const iox_server_t server, - const ENUM iox_ServerState serverState, + const enum iox_ServerState serverState, const uint64_t eventId, void (*callback)(iox_server_t)) { @@ -368,7 +369,7 @@ iox_WaitSetResult iox_ws_attach_server_state(const iox_ws_t self, iox_WaitSetResult iox_ws_attach_server_state_with_context_data(iox_ws_t const self, iox_server_t const server, - const ENUM iox_ServerState serverState, + const enum iox_ServerState serverState, const uint64_t eventId, void (*callback)(iox_server_t, void*), void* const contextData) @@ -384,7 +385,7 @@ iox_WaitSetResult iox_ws_attach_server_state_with_context_data(iox_ws_t const se return (result.has_error()) ? cpp2c::waitSetResult(result.error()) : iox_WaitSetResult::WaitSetResult_SUCCESS; } -void iox_ws_detach_server_event(iox_ws_t const self, iox_server_t const server, const ENUM iox_ServerEvent serverEvent) +void iox_ws_detach_server_event(iox_ws_t const self, iox_server_t const server, const enum iox_ServerEvent serverEvent) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); IOX_ENFORCE(server != nullptr, "'server' must not be a 'nullptr'"); @@ -392,7 +393,7 @@ void iox_ws_detach_server_event(iox_ws_t const self, iox_server_t const server, self->detachEvent(*server, c2cpp::serverEvent(serverEvent)); } -void iox_ws_detach_server_state(iox_ws_t const self, iox_server_t const server, const ENUM iox_ServerState serverState) +void iox_ws_detach_server_state(iox_ws_t const self, iox_server_t const server, const enum iox_ServerState serverState) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); IOX_ENFORCE(server != nullptr, "'server' must not be a 'nullptr'"); @@ -402,7 +403,7 @@ void iox_ws_detach_server_state(iox_ws_t const self, iox_server_t const server, iox_WaitSetResult iox_ws_attach_service_discovery_event(const iox_ws_t self, const iox_service_discovery_t serviceDiscovery, - const ENUM iox_ServiceDiscoveryEvent serviceDiscoveryEvent, + const enum iox_ServiceDiscoveryEvent serviceDiscoveryEvent, const uint64_t eventId, void (*callback)(iox_service_discovery_t)) { @@ -417,7 +418,7 @@ iox_WaitSetResult iox_ws_attach_service_discovery_event(const iox_ws_t self, iox_WaitSetResult iox_ws_attach_service_discovery_event_with_context_data(iox_ws_t const self, iox_service_discovery_t const serviceDiscovery, - const ENUM iox_ServiceDiscoveryEvent serviceDiscoveryEvent, + const enum iox_ServiceDiscoveryEvent serviceDiscoveryEvent, const uint64_t eventId, void (*callback)(iox_service_discovery_t, void*), void* const contextData) @@ -436,7 +437,7 @@ iox_ws_attach_service_discovery_event_with_context_data(iox_ws_t const self, void iox_ws_detach_service_discovery_event(iox_ws_t const self, iox_service_discovery_t const serviceDiscovery, - const ENUM iox_ServiceDiscoveryEvent serviceDiscoveryEvent) + const enum iox_ServiceDiscoveryEvent serviceDiscoveryEvent) { IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'"); IOX_ENFORCE(serviceDiscovery != nullptr, "'serviceDiscovery' must not be a 'nullptr'"); diff --git a/iceoryx_binding_c/test/moduletests/test_client.cpp b/iceoryx_binding_c/test/moduletests/test_client.cpp index 02861d195f..3f74e6a615 100644 --- a/iceoryx_binding_c/test/moduletests/test_client.cpp +++ b/iceoryx_binding_c/test/moduletests/test_client.cpp @@ -109,7 +109,7 @@ class iox_client_test : public Test char managementMemory[MANAGEMENT_MEMORY_SIZE]; iox::BumpAllocator mgmtAllocator{managementMemory, MANAGEMENT_MEMORY_SIZE}; static constexpr uint64_t DATA_MEMORY_SIZE = 1024 * 1024; - char dataMemory[DATA_MEMORY_SIZE]; + alignas(8) char dataMemory[DATA_MEMORY_SIZE]; iox::BumpAllocator dataAllocator{dataMemory, DATA_MEMORY_SIZE}; iox::mepoo::MemoryManager memoryManager; iox::mepoo::MePooConfig memoryConfig; 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_publisher.cpp b/iceoryx_binding_c/test/moduletests/test_publisher.cpp index 484cf185dd..ee9f37e126 100644 --- a/iceoryx_binding_c/test/moduletests/test_publisher.cpp +++ b/iceoryx_binding_c/test/moduletests/test_publisher.cpp @@ -97,7 +97,7 @@ class iox_pub_test : public Test } static constexpr size_t MEMORY_SIZE = 1024 * 1024; - uint8_t m_memory[MEMORY_SIZE]; + alignas(8) uint8_t m_memory[MEMORY_SIZE]; static constexpr uint32_t NUM_CHUNKS_IN_POOL = 20; static constexpr uint64_t CHUNK_SIZE = 256; diff --git a/iceoryx_binding_c/test/moduletests/test_server.cpp b/iceoryx_binding_c/test/moduletests/test_server.cpp index 7b6f9ca793..642847c076 100644 --- a/iceoryx_binding_c/test/moduletests/test_server.cpp +++ b/iceoryx_binding_c/test/moduletests/test_server.cpp @@ -104,7 +104,7 @@ class iox_server_test : public Test char managementMemory[MANAGEMENT_MEMORY_SIZE]; iox::BumpAllocator mgmtAllocator{managementMemory, MANAGEMENT_MEMORY_SIZE}; static constexpr uint64_t DATA_MEMORY_SIZE = 1024 * 1024; - char dataMemory[DATA_MEMORY_SIZE]; + alignas(8) char dataMemory[DATA_MEMORY_SIZE]; iox::BumpAllocator dataAllocator{dataMemory, DATA_MEMORY_SIZE}; iox::mepoo::MemoryManager memoryManager; iox::mepoo::MePooConfig memoryConfig; diff --git a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp index b75647ed91..9e7823b708 100644 --- a/iceoryx_binding_c/test/moduletests/test_subscriber.cpp +++ b/iceoryx_binding_c/test/moduletests/test_subscriber.cpp @@ -25,6 +25,7 @@ #include "iceoryx_posh/internal/popo/ports/subscriber_port_user.hpp" #include "iceoryx_posh/mepoo/mepoo_config.hpp" #include "iox/detail/hoofs_error_reporting.hpp" +#include "iox/detail/system_configuration.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "iceoryx_posh/roudi_env/minimal_iceoryx_config.hpp" @@ -98,8 +99,8 @@ class iox_sub_test : public Test } static iox_sub_t m_triggerCallbackLatestArgument; - static constexpr size_t MEMORY_SIZE = 1024 * 1024 * 100; - uint8_t m_memory[MEMORY_SIZE]; + static constexpr size_t MEMORY_SIZE = 1024 * 1024; + alignas(8) uint8_t m_memory[MEMORY_SIZE]; static constexpr uint32_t NUM_CHUNKS_IN_POOL = MAX_CHUNKS_HELD_PER_SUBSCRIBER_SIMULTANEOUSLY + 2U; static constexpr uint64_t CHUNK_SIZE = 128U; @@ -145,6 +146,12 @@ TEST_F(iox_sub_test, initSubscriberWithNotInitializedSubscriberOptionsTerminates TEST_F(iox_sub_test, initSubscriberWithDefaultOptionsWorks) { ::testing::Test::RecordProperty("TEST_ID", "40eaa006-4781-46cd-bde3-40fa7d572f29"); + + if (iox::detail::isCompiledOn32BitSystem()) + { + GTEST_SKIP() << "@todo iox-#2301 This test does not work on 32 bit builds due to the usage of RouDiEnv"; + } + RouDiEnv roudiEnv; iox_runtime_init("hypnotoad"); @@ -402,6 +409,12 @@ TEST_F(iox_sub_test, hasDataTriggersWaitSetWithCorrectCallback) TEST_F(iox_sub_test, deinitSubscriberDetachesTriggerFromWaitSet) { ::testing::Test::RecordProperty("TEST_ID", "93e350fb-5430-43ff-982b-b43c6ae9b890"); + + if (iox::detail::isCompiledOn32BitSystem()) + { + GTEST_SKIP() << "@todo iox-#2301 This test does not work on 32 bit builds due to the usage of RouDiEnv"; + } + RouDiEnv roudiEnv; iox_runtime_init("hypnotoad"); 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/BUILD.bazel b/iceoryx_hoofs/BUILD.bazel index 0d5f4bc5fd..aaa397e4ff 100644 --- a/iceoryx_hoofs/BUILD.bazel +++ b/iceoryx_hoofs/BUILD.bazel @@ -22,7 +22,6 @@ configure_file( src = "cmake/iceoryx_hoofs_deployment.hpp.in", out = "generated/include/iox/iceoryx_hoofs_deployment.hpp", config = { - "IOX_IGNORE_32_BIT_CHECK_FLAG": "false", "IOX_MAX_NAMED_PIPE_MESSAGE_SIZE": "4096", "IOX_MAX_NAMED_PIPE_NUMBER_OF_MESSAGES": "10", # FIXME: for values see "iceoryx_hoofs/cmake/IceoryxHoofsDeployment.cmake" ... for now some nice defaults diff --git a/iceoryx_hoofs/cli/source/command_line_parser.cpp b/iceoryx_hoofs/cli/source/command_line_parser.cpp index 5d2b83beb9..278f18fe4a 100644 --- a/iceoryx_hoofs/cli/source/command_line_parser.cpp +++ b/iceoryx_hoofs/cli/source/command_line_parser.cpp @@ -106,7 +106,7 @@ bool CommandLineParser::doesNotExceedLongOptionDash(const char* option) const no bool CommandLineParser::doesFitIntoString(const char* value, const uint64_t maxLength) noexcept { - return (strnlen(value, maxLength + 1) <= maxLength); + return (strnlen(value, static_cast(maxLength) + 1) <= maxLength); } bool CommandLineParser::doesOptionNameFitIntoString(const char* option) const noexcept diff --git a/iceoryx_hoofs/cmake/IceoryxHoofsDeployment.cmake b/iceoryx_hoofs/cmake/IceoryxHoofsDeployment.cmake index 67bea9cfc8..a3404300e9 100644 --- a/iceoryx_hoofs/cmake/IceoryxHoofsDeployment.cmake +++ b/iceoryx_hoofs/cmake/IceoryxHoofsDeployment.cmake @@ -31,11 +31,6 @@ configure_option( DEFAULT_VALUE 10 ) -if(IOX_IGNORE_32_BIT_CHECK) - set(IOX_IGNORE_32_BIT_CHECK_FLAG true) -else() - set(IOX_IGNORE_32_BIT_CHECK_FLAG false) -endif() message(STATUS "[i] IOX_EXPERIMENTAL_POSH_FLAG: ${IOX_EXPERIMENTAL_POSH_FLAG}") message(STATUS "[i] <<<<<<<<<<<<<< End iceoryx_hoofs configuration: >>>>>>>>>>>>>>") diff --git a/iceoryx_hoofs/cmake/iceoryx_hoofs_deployment.hpp.in b/iceoryx_hoofs/cmake/iceoryx_hoofs_deployment.hpp.in index e9e2bf5fca..218db9b65a 100644 --- a/iceoryx_hoofs/cmake/iceoryx_hoofs_deployment.hpp.in +++ b/iceoryx_hoofs/cmake/iceoryx_hoofs_deployment.hpp.in @@ -35,8 +35,6 @@ constexpr iox::log::LogLevel IOX_MINIMAL_LOG_LEVEL = iox::log::LogLevel::@IOX_MI constexpr uint64_t IOX_MAX_NAMED_PIPE_MESSAGE_SIZE = static_cast(@IOX_MAX_NAMED_PIPE_MESSAGE_SIZE@); constexpr uint32_t IOX_MAX_NAMED_PIPE_NUMBER_OF_MESSAGES = static_cast(@IOX_MAX_NAMED_PIPE_NUMBER_OF_MESSAGES@); -constexpr bool IOX_IGNORE_32_BIT_CHECK_FLAG = @IOX_IGNORE_32_BIT_CHECK_FLAG@; - } // namespace build } // namespace iox 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..e104c44046 100644 --- a/iceoryx_hoofs/concurrent/buffer/include/iox/detail/spsc_sofi.hpp +++ b/iceoryx_hoofs/concurrent/buffer/include/iox/detail/spsc_sofi.hpp @@ -19,123 +19,124 @@ #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 +#include namespace iox { namespace concurrent { -/// @brief -/// Thread safe producer and consumer queue with a safe overflowing behavior. -/// SpscSofi is designed in a FIFO Manner but prevents data loss when pushing into -/// a full SpscSofi. When SpscSofi is full and a Sender tries to push, the data at the -/// current read position will be returned. SpscSofi is threadsafe without using -/// locks. When the buffer is filled, new data is written starting at the -/// beginning of the buffer and overwriting the old.The SpscSofi is especially -/// designed to provide fixed capacity storage. When its capacity is exhausted, -/// newly inserted elements will cause elements either at the beginning -/// to be overwritten.The SpscSofi only allocates memory when -/// created , capacity can be is adjusted explicitly. -/// +/// @brief Thread safe lock-free single producer and single consumer queue with a safe +/// overflowing behavior +/// @note When SpscSoFi is full and a sender tries to push, the data at the current read pos will be +/// returned. This behavior mimics a FiFo queue but prevents resource leaks when pushing into +/// a full SpscSoFi. +/// SpscSoFi is especially designed to provide fixed capacity storage. +/// It's an expected behavior that when push/pop are called concurrently and SpscSoFi is full, as +/// many elements as specified with 'CapacityValue' can be removed /// @param[in] ValueType DataType to be stored, must be trivially copyable /// @param[in] CapacityValue Capacity of the SpscSofi template class SpscSofi { static_assert(std::is_trivially_copyable::value, - "SpscSofi can handle only trivially copyable data types"); + "SpscSofi can only handle trivially copyable data types since 'memcpy' is used internally"); /// @brief Check if Atomic integer is lockfree on platform /// ATOMIC_INT_LOCK_FREE = 2 - is always lockfree /// ATOMIC_INT_LOCK_FREE = 1 - is sometimes lockfree /// ATOMIC_INT_LOCK_FREE = 0 - is never lockfree static_assert(2 <= ATOMIC_INT_LOCK_FREE, "SpscSofi is not able to run lock free on this data type"); - /// @brief Internal size needs to be bigger than the size desirred by the user - /// This is because of buffer empty detection and overflow handling - static constexpr uint32_t INTERNAL_SIZE_ADD_ON = 1; - - /// @brief This is the resulting internal size on creation - static constexpr uint32_t INTERNAL_SPSC_SOFI_SIZE = CapacityValue + INTERNAL_SIZE_ADD_ON; + // To ensure a consumer gets at least the amount of capacity of data when a queue is full, an additional free + // slot (add-on) is required. + // ======================================================================== + // Consider the following scenario when there is no "capacity add-on": + // 1. CapacityValue = 2 + // |--A--|--B--| + // ^ + // w=2, r=0 + // 2. The producer thread pushes a new element + // 3. Increment the read position (this effectively reduces the capacity and is the reason the internal capacity + // needs to be larger; + // |--A--|--B--| + // ^ ^ + // w=2 r=1 + // 4. The producer thread is suspended, the consumer thread pops a value + // |--A--|-----| + // ^ + // w=2, r=2 + // 5. The consumer tries to pop another value but the queue looks empty as + // write position == read position: the consumer cannot pop + // out CAPACITY amount of samples even though the queue was full + // ======================================================================== + // With "capacity add-on" + // 1. CapacityValue = 2, InternalCapacity = 3 + // |--A--|--B--|----| + // ^ ^ + // r=0 w=2 + // 2. The producer threads pushes a new element + // 3. First write the element at index 2 % capacity and increment the write index + // |--A--|--B--|--C--| + // ^ + // w=3, r=0, + // 4. Then increment the read position and return the overflowing 'A' + // |-----|--B--|--C--| + // ^ ^ + // w=3 r=1 + // 5. The producer thread is suspended, the consumer thread pops a value + // |--A--|-----|--C--| + // ^ ^ + // w=3 r=2 + // 6. The consumer thread pops another value + // |--A--|-----|-----| + // ^ + // w=3, r=3 + // 7. Now, write position == read position so we cannot pop another element: the queue looks empty. We managed to + // pop CapacityValue elements + // ======================================================================== + static constexpr uint32_t INTERNAL_CAPACITY_ADDON = 1; + + /// @brief Internal capacity of the queue at creation + static constexpr uint32_t INTERNAL_SPSC_SOFI_CAPACITY = CapacityValue + INTERNAL_CAPACITY_ADDON; public: - /// @brief default constructor which constructs an empty sofi + /// @brief default constructor which constructs an empty SpscSofi SpscSofi() noexcept = default; - /// @brief pushs an element into SpscSofi. if SpscSofi is full the oldest data will be + /// @brief push an element into SpscSofi. if SpscSofi is full the oldest data will be /// returned and the pushed element is stored in its place instead. - /// @param[in] valueIn value which should be stored - /// @param[out] valueOut if SpscSofi is overflowing the value of the overridden value + /// @param[in] value_in value which should be stored + /// @param[out] value_out if SpscSofi is overflowing the value of the overridden value /// is stored here - /// @concurrent restricted thread safe: single pop, single push no - /// push calls from multiple contexts - /// @return return true if push was sucessfull else false. - /// @code - /// (initial situation, SpscSofi is FULL) - /// Start|-----A-------| - /// |-----B-------| - /// |-----C-------| - /// |-----D-------| - /// - /// - /// (calling push with data ’E’) - /// Start|-----E-------| - /// |-----A-------| - /// |-----B-------| - /// |-----C-------| - /// (’D’ is returned as valueOut) - /// - /// ################################################################### - /// - /// (if SpscSofi is not FULL , calling push() add new data) - /// Start|-------------| - /// |-------------| ( Initial SpscSofi ) - /// (push() Called two times) - /// - /// |-------------| - /// (New Data) - /// |-------------| - /// (New Data) - /// @endcode + /// @note restricted thread safe: can only be called from one thread. The authorization to push into the + /// SpscSofi can be transferred to another thread if appropriate synchronization mechanisms are used. + /// @return return true if push was successful else false. + /// @remarks + /// 1. SpscSofi is empty |-----|-----| + /// 2. push an element |--A--|-----| + /// 3. push an element |--A--|--B--| + /// 5. SpscSofi is full + /// 6. push an element |--C--|--B--| -> value_out is set to 'A' bool push(const ValueType& valueIn, ValueType& valueOut) noexcept; /// @brief pop the oldest element /// @param[out] valueOut storage of the pop'ed value - /// @concurrent restricted thread safe: single pop, single push no - /// pop or popIf calls from multiple contexts + /// @concurrent restricted thread safe: can only be called from one thread. The authorization to pop from the + /// SpscSofi can be transferred to another thread if appropriate synchronization mechanisms are used. /// @return false if SpscSofi is empty, otherwise true bool pop(ValueType& valueOut) noexcept; - /// @brief conditional pop call to provide an alternative for a peek - /// and pop approach. If the verificator returns true the - /// peeked element is returned. - /// @param[out] valueOut storage of the pop'ed value - /// @param[in] verificator callable of type bool(const ValueType& peekValue) - /// which takes the value which would be pop'ed as argument and returns - /// true if it should be pop'ed, otherwise false - /// @code - /// int limit = 7128; - /// mysofi.popIf(value, [=](const ValueType & peek) - /// { - /// return peek < limit; // pop only when peek is smaller than limit - /// } - /// ); // pop's a value only if it is smaller than 9012 - /// @endcode - /// @concurrent restricted thread safe: single pop, single push no - /// pop or popIf calls from multiple contexts - /// @return false if SpscSofi is empty or when verificator returns false, otherwise true - template - bool popIf(ValueType& valueOut, const Verificator_T& verificator) noexcept; - /// @brief returns true if SpscSofi is empty, otherwise false /// @note the use of this function is limited in the concurrency case. if you /// call this and in another thread pop is called the result can be out /// of date as soon as you require it - /// @concurrent unrestricted thread safe + /// @concurrent unrestricted thread safe (the result might already be outdated when used). Expected to be called + /// from either the producer or the consumer thread but not from a third thread bool empty() const noexcept; /// @brief resizes SpscSofi @@ -150,17 +151,18 @@ class SpscSofi uint64_t capacity() const noexcept; /// @brief returns the current size of SpscSofi - /// @concurrent unrestricted thread safe + /// @concurrent unrestricted thread safe (the result might already be outdated when used). Expected to be called + /// from either the producer or the consumer thread but not from a third thread uint64_t size() const noexcept; private: - UninitializedArray m_data; - uint64_t m_size = INTERNAL_SPSC_SOFI_SIZE; + std::pair getReadWritePositions() const noexcept; - /// @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}; + private: + UninitializedArray m_data; + uint64_t m_size = INTERNAL_SPSC_SOFI_CAPACITY; + Atomic m_readPosition{0}; + Atomic m_writePosition{0}; }; } // namespace concurrent diff --git a/iceoryx_hoofs/concurrent/buffer/include/iox/detail/spsc_sofi.inl b/iceoryx_hoofs/concurrent/buffer/include/iox/detail/spsc_sofi.inl index 146ac726dd..3d935d2362 100644 --- a/iceoryx_hoofs/concurrent/buffer/include/iox/detail/spsc_sofi.inl +++ b/iceoryx_hoofs/concurrent/buffer/include/iox/detail/spsc_sofi.inl @@ -27,11 +27,11 @@ namespace concurrent template inline uint64_t SpscSofi::capacity() const noexcept { - return m_size - INTERNAL_SIZE_ADD_ON; + return m_size - INTERNAL_CAPACITY_ADDON; } template -inline uint64_t SpscSofi::size() const noexcept +inline std::pair SpscSofi::getReadWritePositions() const noexcept { uint64_t readPosition{0}; uint64_t writePosition{0}; @@ -39,17 +39,44 @@ inline uint64_t SpscSofi::size() const noexcept { readPosition = m_readPosition.load(std::memory_order_relaxed); writePosition = m_writePosition.load(std::memory_order_relaxed); + + // The while loop is needed to avoid the following scenarios: + // 1. Implementation to get the size: size = m_writePosition - m_readPosition; + // - consumer reads m_writePosition + // - consumer thread gets suspended + // - producer pushes 100 times + // - consumer reads m_readPosition + // => m_readPosition will be past m_writePosition and one would get a negative size (or the positive unsigned + // equivalent) + // 2. Implementation to get the size: readPosition = m_readPosition; size = m_writePosition - readPosition; + // - consumer stores m_readPosition in readPosition + // - consumer thread gets suspended + // - producer pushes 100 times + // - consumer reads m_writePosition + // => m_writePosition will be past readPosition + Capacity and one would get a size which is much larger than + // the capacity + // =========================================== + // Note: it is still possible to return a size that is not up-to-date anymore but at least + // the returned size is logically valid } while (m_writePosition.load(std::memory_order_relaxed) != writePosition || m_readPosition.load(std::memory_order_relaxed) != readPosition); + return {readPosition, writePosition}; +} + + +template +inline uint64_t SpscSofi::size() const noexcept +{ + auto [readPosition, writePosition] = getReadWritePositions(); return writePosition - readPosition; } template inline bool SpscSofi::setCapacity(const uint64_t newSize) noexcept { - uint64_t newInternalSize = newSize + INTERNAL_SIZE_ADD_ON; - if (empty() && (newInternalSize <= INTERNAL_SPSC_SOFI_SIZE)) + uint64_t newInternalSize = newSize + INTERNAL_CAPACITY_ADDON; + if (empty() && (newInternalSize <= INTERNAL_SPSC_SOFI_CAPACITY)) { m_size = newInternalSize; @@ -65,74 +92,62 @@ inline bool SpscSofi::setCapacity(const uint64_t newSi template inline bool SpscSofi::empty() const noexcept { - uint64_t currentReadPosition{0}; - bool isEmpty{false}; - - do - { - /// @todo iox-#1695 read before write since the writer increments the aba counter!!! - /// @todo iox-#1695 write doc with example!!! - currentReadPosition = m_readPosition.load(std::memory_order_acquire); - uint64_t currentWritePosition = m_writePosition.load(std::memory_order_acquire); - - isEmpty = (currentWritePosition == currentReadPosition); - // we need compare without exchange - } while (!(currentReadPosition == m_readPosition.load(std::memory_order_acquire))); - - return isEmpty; + auto [readPosition, writePosition] = getReadWritePositions(); + return readPosition == writePosition; } template inline bool SpscSofi::pop(ValueType& valueOut) noexcept { - return popIf(valueOut, [](ValueType) { return true; }); -} - -template -template -inline bool SpscSofi::popIf(ValueType& valueOut, const Verificator_T& verificator) noexcept -{ - uint64_t currentReadPosition = m_readPosition.load(std::memory_order_acquire); uint64_t nextReadPosition{0}; - bool popWasSuccessful{true}; + // Memory order relaxed is enough since: + // - no synchronization needed for m_readPosition + // - if m_writePosition is loaded before m_readPosition and m_readPosition changed, it will be detected by the + // compare_exchange loop + uint64_t currentReadPosition = m_readPosition.load(std::memory_order_relaxed); + do { + // SYNC POINT READ: m_data + // See explanation of the corresponding synchronization point in push() if (currentReadPosition == m_writePosition.load(std::memory_order_acquire)) { nextReadPosition = currentReadPosition; popWasSuccessful = false; + // We cannot just return false (i.e. we need to continue the loop) to avoid the following situation: + // 0. Initial situation (the queue is full) + // |----|--B--|--C--| + // ^ ^ + // w=3 r=1 + // 1. The consumer thread loads m_writePosition => 3 + // |----|--B--|--C--| + // ^ ^ + // w=3 r=1 + // 2. The producer thread pushes two times + // |--D--|--E--|-----| + // ^ ^ + // r=3 w=5 + // 3. The consumer thread loads m_readPosition => 3 The pop method returns false + // => Whereas the queue was full, pop returned false giving the impression that the queue if empty } else { - // we use memcpy here, since the copy assignment is not thread safe in general (we might have an overflow in - // the push thread and invalidates the object while the copy is running and therefore works on an - // invalid object); memcpy is also not thread safe, but we discard the object anyway and read it - // again if its overwritten in between; this is only relevant for types larger than pointer size - // assign the user data + // we use memcpy here, to ensure that there is no logic in copying the data std::memcpy(&valueOut, &m_data[currentReadPosition % m_size], sizeof(ValueType)); + nextReadPosition = currentReadPosition + 1U; + popWasSuccessful = true; - /// @brief first we need to peak valueOut if it is fitting the condition and then we have to verify - /// if valueOut is not am invalid object, this could be the case if the read position has - /// changed - if (m_readPosition.load(std::memory_order_relaxed) == currentReadPosition && !verificator(valueOut)) - { - popWasSuccessful = false; - nextReadPosition = currentReadPosition; - } - else - { - nextReadPosition = currentReadPosition + 1U; - popWasSuccessful = true; - } + // We need to check if m_readPosition hasn't changed otherwise valueOut might be corrupted + // ============================================= + // While memory synchronization is not needed for m_readPosition, we need to ensure that the + // 'memcpy' happens before updating m_readPosition. + // Corresponding m_readPosition load/acquire is in the CAS loop of push method + // ============================================= + // ABA problem: m_readPosition is an uint64_t. Assuming a thread is pushing at a rate of 1 GHz + // while this thread is blocked, we would still need more than 500 years to overflow + // m_readPosition and encounter the ABA problem } - - // compare and swap - // if(m_readPosition == currentReadPosition) - // m_readPosition = l_next_aba_read_pos - // else - // currentReadPosition = m_readPosition - // Assign m_aba_read_p to next readable location } while (!m_readPosition.compare_exchange_weak( currentReadPosition, nextReadPosition, std::memory_order_acq_rel, std::memory_order_acquire)); @@ -144,42 +159,94 @@ inline bool SpscSofi::push(const ValueType& valueIn, V { constexpr bool SOFI_OVERFLOW{false}; + // Memory order relaxed is enough since: + // - no synchronization needed as we are loading a value only modified in this method and this method cannot be + // accessed concurrently + // - the operation cannot move below without observable changes uint64_t currentWritePosition = m_writePosition.load(std::memory_order_relaxed); uint64_t nextWritePosition = currentWritePosition + 1U; m_data[currentWritePosition % m_size] = valueIn; + // SYNC POINT WRITE: m_data + // We need to make sure that writing the value happens before incrementing the + // m_writePosition otherwise the following scenario can happen: + // 1. m_writePosition is increased (but the value has not been written yet) + // 2. The consumer thread calls pop(): we check if the queue is empty => no + // 3. In pop(), when we read a value a data race can occur + // With memory_order_release, this cannot happen as it is guaranteed that writing the data + // happens before incrementing m_writePosition + // ======================================= + // Note that the following situation can still happen (but, although it is an inherent race with + // concurrent algorithms, it is not a data race and therefore not a problem): + // 1. There is an empty queue + // 2. A push operation is in progress, the value has been written but 'm_writePosition' was not + // yet advanced + // 3. The consumer thread performs a pop operation and the check for an empty queue is true + // resulting in a failed pop + // 4. The push operation is finished by advancing m_writePos and synchronizing the memory + // 5. The consumer thread missed the chance to pop the element in the blink of an eye m_writePosition.store(nextWritePosition, std::memory_order_release); - uint64_t currentReadPosition = m_readPosition.load(std::memory_order_acquire); + // Memory order relaxed is enough since: + // - no synchronization needed when loading + // - the operation cannot move below without observable changes + uint64_t currentReadPosition = m_readPosition.load(std::memory_order_relaxed); - // check if there is a free position for the next push + // Check if queue is full: since we have an extra element (INTERNAL_CAPACITY_ADD_ON), we need to + // check if there is a free position for the *next* write position if (nextWritePosition < currentReadPosition + m_size) { return !SOFI_OVERFLOW; } - // this is an overflow situation, which means that the next push has no free position, therefore the oldest value - // needs to be passed back to the caller - - uint64_t nextReadPosition = currentReadPosition + 1U; - - // we need to update the read position - // a) it works, then we need to pass the overflow value back - // b) it doesn't work, which means that the pop thread already took the value in the meantime an no further action - // is required - // memory order success is memory_order_acq_rel - // - this is to prevent the reordering of m_writePosition.store(...) after the increment of the m_readPosition - // - in case of an overflow, this might result in the pop thread getting one element less than the capacity of - // the SoFi if the push thread is suspended in between this two statements - // - it's still possible to get more elements than the capacity, but this is an inherent issue with concurrent - // queues and cannot be prevented since there can always be a push during a pop operation - // - another issue might be that two consecutive pushes (not concurrent) happen on different CPU cores without - // synchronization, then the memory also needs to be synchronized for the overflow case - // memory order failure is memory_order_relaxed since there is no further synchronization needed if there is no - // overflow + // This is an overflow situation so we will need to read the overwritten value + // however, it could be that pop() was called in the meantime, i.e. m_readPosition was increased. + // Memory order success needs to be memory_order_acq_rel to prevent the reordering of + // m_writePosition.store(...) after the increment of the m_readPosition. Otherwise, in case of + // an overflow, this might result in the pop thread getting one element less than the capacity + // of the SoFi if the push thread is suspended in between this two statements. + // It's still possible to get more elements than the capacity, but this is an inherent issue + // with concurrent queues and cannot be prevented since there can always be a push during a pop + // operation. + // Another issue might be that two consecutive pushes (not concurrent) happen on different CPU + // cores without synchronization, then the memory also needs to be synchronized for the overflow + // case. + // Memory order failure needs to be memory_order_acquire to match the corresponding m_readPosition store/release in + // the CAS loop of the pop method + // ====================================== + // ABA problem: m_readPosition is an uint64_t. Assuming a thread is popping at a rate of 1 GHz while + // this thread is blocked, we would still need more than 500 years to overflow m_readPosition and + // encounter the ABA problem if (m_readPosition.compare_exchange_strong( - currentReadPosition, nextReadPosition, std::memory_order_acq_rel, std::memory_order_relaxed)) + currentReadPosition, currentReadPosition + 1U, std::memory_order_acq_rel, std::memory_order_acquire)) { + // Since INTERNAL_SOFI_CAPACITY = CapacityValue + 1, it can happen that we return more + // elements than the CapacityValue by calling push and pop concurrently (in case of an + // overflow). This is an inherent behavior with concurrent queues. Scenario example + // (CapacityValue = 2): + // 0. Initial situation (before the call to push) + // |--A--|--B--|----| + // ^ ^ + // r=0 w=2 + // 1. Thread 1, pushes a new value and increases m_readPosition (overflow situation) + // |--A--|--B--|--C--| + // ^ ^ + // w=3, r=1 + // 2. Now, thread 1 is interrupted and another thread pops as many elements as possible + // 3. pop() -> returns B (First value returned by pop) + // |--A--|-(B)-|--C--| + // ^ ^ + // w=3 r=2 + // 4. pop() -> returns C (Second value returned by pop) + // |--A--|-(B)-|-(C)-| + // ^ + // w=3, r=3 + // 5. pop() -> nothing to return + // 6. Finally, thread 1 resumes and returns A (Third value [additional value] returned by + // push) + // |-(A)-|-(B)-|-(C)-| + // ^ + // w=3, r=3 std::memcpy(&valueOut, &m_data[currentReadPosition % m_size], sizeof(ValueType)); return SOFI_OVERFLOW; } 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/container/include/iox/detail/vector.inl b/iceoryx_hoofs/container/include/iox/detail/vector.inl index ae822c2787..6c20aaff20 100644 --- a/iceoryx_hoofs/container/include/iox/detail/vector.inl +++ b/iceoryx_hoofs/container/include/iox/detail/vector.inl @@ -90,7 +90,7 @@ inline vector& vector::operator=(const vector& rhs) no if constexpr (std::is_trivially_copyable::value) { - std::memcpy(data(), rhs.data(), rhsSize * sizeof(T)); + std::memcpy(data(), rhs.data(), static_cast(rhsSize) * sizeof(T)); i = rhsSize; } else @@ -129,7 +129,7 @@ inline vector& vector::operator=(vector&& rhs) noexcep if constexpr (std::is_trivially_copyable::value) { - std::memcpy(data(), rhs.data(), rhsSize * sizeof(T)); + std::memcpy(data(), rhs.data(), static_cast(rhsSize) * sizeof(T)); i = rhsSize; } else @@ -220,7 +220,7 @@ inline bool vector::emplace(const uint64_t position, Targs&&... arg if constexpr (std::is_trivial::value) { resize(size() + 1U); - const uint64_t dataLen{sizeBeforeEmplace - position}; + const size_t dataLen{static_cast(sizeBeforeEmplace) - static_cast(position)}; std::memmove(data() + position + 1U, data() + position, dataLen * sizeof(T)); at_unchecked(position) = T{std::forward(args)...}; } @@ -414,7 +414,7 @@ inline bool vector::erase(iterator position) noexcept at_unchecked(n).~T(); } uint64_t dataLen{size() - n - 1U}; - std::memmove(data() + n, data() + n + 1U, dataLen * sizeof(T)); + std::memmove(data() + n, data() + n + 1U, static_cast(dataLen) * sizeof(T)); } else { 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/memory/include/iox/detail/relative_pointer.inl b/iceoryx_hoofs/memory/include/iox/detail/relative_pointer.inl index c2f55c0e72..0724e9b6b8 100644 --- a/iceoryx_hoofs/memory/include/iox/detail/relative_pointer.inl +++ b/iceoryx_hoofs/memory/include/iox/detail/relative_pointer.inl @@ -189,7 +189,7 @@ inline typename RelativePointer::offset_t RelativePointer::getOffset(const const auto* const basePtr = getBasePtr(id); // AXIVION Next Construct AutosarC++19_03-A5.2.4, AutosarC++19_03-M5.2.9 : Cast needed for pointer arithmetic // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - return reinterpret_cast(ptr) - reinterpret_cast(basePtr); + return reinterpret_cast(ptr) - reinterpret_cast(basePtr); } template @@ -206,7 +206,7 @@ inline T* RelativePointer::getPtr(const segment_id_t id, const offset_t offse // AXIVION DISABLE STYLE AutosarC++19_03-M5.2.8 : Cast needed for pointer arithmetic // AXIVION DISABLE STYLE AutosarC++19_03-M5.2.9 : Cast needed for pointer arithmetic // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast, performance-no-int-to-ptr) - return reinterpret_cast(offset + reinterpret_cast(basePtr)); + return reinterpret_cast(offset + reinterpret_cast(basePtr)); // AXIVION ENABLE STYLE AutosarC++19_03-M5.2.9 // AXIVION ENABLE STYLE AutosarC++19_03-M5.2.8 // AXIVION ENABLE STYLE AutosarC++19_03-A5.2.4 diff --git a/iceoryx_hoofs/memory/include/iox/detail/static_storage.inl b/iceoryx_hoofs/memory/include/iox/detail/static_storage.inl index d1b2693d04..2fadf98eea 100644 --- a/iceoryx_hoofs/memory/include/iox/detail/static_storage.inl +++ b/iceoryx_hoofs/memory/include/iox/detail/static_storage.inl @@ -67,7 +67,7 @@ constexpr void* static_storage::allocate(const uint64_t align, size_t space{Capacity}; m_ptr = m_bytes; - if (std::align(align, size, m_ptr, space) != nullptr) + if (std::align(static_cast(align), static_cast(size), m_ptr, space) != nullptr) { // fits, ptr was potentially modified to reflect alignment return m_ptr; diff --git a/iceoryx_hoofs/memory/include/iox/memory.hpp b/iceoryx_hoofs/memory/include/iox/memory.hpp index 6e4638b5ab..5fa2cae9bf 100644 --- a/iceoryx_hoofs/memory/include/iox/memory.hpp +++ b/iceoryx_hoofs/memory/include/iox/memory.hpp @@ -37,7 +37,7 @@ T align(const T value, const T alignment) noexcept /// @param[in] alignment, alignment of the memory /// @param[in] size, memory size /// @return void pointer to the aligned memory -void* alignedAlloc(const uint64_t alignment, const uint64_t size) noexcept; +void* alignedAlloc(const size_t alignment, const size_t size) noexcept; /// @brief frees aligned memory allocated with alignedAlloc /// @param[in] memory, pointer to the aligned memory diff --git a/iceoryx_hoofs/memory/include/iox/relative_pointer.hpp b/iceoryx_hoofs/memory/include/iox/relative_pointer.hpp index 60ed5abb90..3551ee1fa0 100644 --- a/iceoryx_hoofs/memory/include/iox/relative_pointer.hpp +++ b/iceoryx_hoofs/memory/include/iox/relative_pointer.hpp @@ -67,7 +67,7 @@ class RelativePointer final { public: using ptr_t = T*; - using offset_t = std::uintptr_t; + using offset_t = std::uint64_t; /// @brief Default constructs a RelativePointer as a logical nullptr RelativePointer() noexcept = default; diff --git a/iceoryx_hoofs/memory/source/memory.cpp b/iceoryx_hoofs/memory/source/memory.cpp index 5d602d87a0..403c255690 100644 --- a/iceoryx_hoofs/memory/source/memory.cpp +++ b/iceoryx_hoofs/memory/source/memory.cpp @@ -21,18 +21,18 @@ namespace iox { -void* alignedAlloc(const uint64_t alignment, const uint64_t size) noexcept +void* alignedAlloc(const size_t alignment, const size_t size) noexcept { // -1 == since the max alignment addition is alignment - 1 otherwise the // memory is already aligned and we have to do nothing // low-level memory management, no other approach then to use malloc to acquire heap memory // NOLINTNEXTLINE(cppcoreguidelines-owning-memory,cppcoreguidelines-pro-type-reinterpret-cast,hicpp-no-malloc,cppcoreguidelines-no-malloc) - auto memory = reinterpret_cast(std::malloc(size + alignment + sizeof(void*) - 1)); + auto memory = reinterpret_cast(std::malloc(size + alignment + sizeof(void*) - 1)); if (memory == 0) { return nullptr; } - uint64_t alignedMemory = align(memory + sizeof(void*), alignment); + size_t alignedMemory = align(memory + sizeof(void*), alignment); assert(alignedMemory >= memory + 1); // low-level memory management, we have to store the actual start of the memory a position before the // returned aligned address to be able to release the actual memory address again with free when we diff --git a/iceoryx_hoofs/posix/filesystem/source/file.cpp b/iceoryx_hoofs/posix/filesystem/source/file.cpp index 2219e2da70..7d5821c60e 100644 --- a/iceoryx_hoofs/posix/filesystem/source/file.cpp +++ b/iceoryx_hoofs/posix/filesystem/source/file.cpp @@ -340,7 +340,9 @@ File::read_at(const uint64_t offset, uint8_t* const buffer, const uint64_t buffe return err(FileReadError::OffsetFailure); } - auto result = IOX_POSIX_CALL(iox_read)(m_file_descriptor, buffer, buffer_len).failureReturnValue(-1).evaluate(); + auto result = IOX_POSIX_CALL(iox_read)(m_file_descriptor, buffer, static_cast(buffer_len)) + .failureReturnValue(-1) + .evaluate(); if (!result.has_error()) { @@ -394,7 +396,9 @@ File::write_at(const uint64_t offset, const uint8_t* const buffer, const uint64_ return err(FileWriteError::OffsetFailure); } - auto result = IOX_POSIX_CALL(iox_write)(m_file_descriptor, buffer, buffer_len).failureReturnValue(-1).evaluate(); + auto result = IOX_POSIX_CALL(iox_write)(m_file_descriptor, buffer, static_cast(buffer_len)) + .failureReturnValue(-1) + .evaluate(); if (!result.has_error()) { diff --git a/iceoryx_hoofs/posix/ipc/include/iox/detail/message_queue.inl b/iceoryx_hoofs/posix/ipc/include/iox/detail/message_queue.inl index d626049228..2a7818452c 100644 --- a/iceoryx_hoofs/posix/ipc/include/iox/detail/message_queue.inl +++ b/iceoryx_hoofs/posix/ipc/include/iox/detail/message_queue.inl @@ -40,7 +40,7 @@ MessageQueue::timedSendImpl(not_null msg, uint64_t msgSize, const u } timespec timeOut = timeout.timespec(units::TimeSpecReference::Epoch); - auto mqCall = IOX_POSIX_CALL(mq_timedsend)(m_mqDescriptor, msg, msgSizeToSend, 1U, &timeOut) + auto mqCall = IOX_POSIX_CALL(mq_timedsend)(m_mqDescriptor, msg, static_cast(msgSizeToSend), 1U, &timeOut) .failureReturnValue(ERROR_CODE) // don't use the suppressErrorMessagesForErrnos method since QNX used EINTR instead of ETIMEDOUT .ignoreErrnos(TIMEOUT_ERRNO) @@ -74,8 +74,9 @@ expected MessageQueue::sendImpl(not_null(msgSizeToSend), 1U) + .failureReturnValue(ERROR_CODE) + .evaluate(); if (mqCall.has_error()) { @@ -95,11 +96,12 @@ expected MessageQueue::timedReceiveImpl(not_null msg, uint64_t maxMsgSize, const units::Duration& timeout) const noexcept { timespec timeOut = timeout.timespec(units::TimeSpecReference::Epoch); - auto mqCall = IOX_POSIX_CALL(mq_timedreceive)(m_mqDescriptor, msg, maxMsgSize, nullptr, &timeOut) - .failureReturnValue(ERROR_CODE) - // don't use the suppressErrorMessagesForErrnos method since QNX used EINTR instead of ETIMEDOUT - .ignoreErrnos(TIMEOUT_ERRNO) - .evaluate(); + auto mqCall = + IOX_POSIX_CALL(mq_timedreceive)(m_mqDescriptor, msg, static_cast(maxMsgSize), nullptr, &timeOut) + .failureReturnValue(ERROR_CODE) + // don't use the suppressErrorMessagesForErrnos method since QNX used EINTR instead of ETIMEDOUT + .ignoreErrnos(TIMEOUT_ERRNO) + .evaluate(); if (mqCall.has_error()) { @@ -118,8 +120,9 @@ template expected MessageQueue::receiveImpl(not_null msg, uint64_t maxMsgSize) const noexcept { - auto mqCall = - IOX_POSIX_CALL(mq_receive)(m_mqDescriptor, msg, maxMsgSize, nullptr).failureReturnValue(ERROR_CODE).evaluate(); + auto mqCall = IOX_POSIX_CALL(mq_receive)(m_mqDescriptor, msg, static_cast(maxMsgSize), nullptr) + .failureReturnValue(ERROR_CODE) + .evaluate(); if (mqCall.has_error()) { @@ -210,4 +213,4 @@ expected MessageQueue::receiveVerification(not_n } } // namespace iox -#endif \ No newline at end of file +#endif diff --git a/iceoryx_hoofs/posix/ipc/include/iox/detail/unix_domain_socket.inl b/iceoryx_hoofs/posix/ipc/include/iox/detail/unix_domain_socket.inl index 21dc4636b7..eed222f3d9 100644 --- a/iceoryx_hoofs/posix/ipc/include/iox/detail/unix_domain_socket.inl +++ b/iceoryx_hoofs/posix/ipc/include/iox/detail/unix_domain_socket.inl @@ -53,7 +53,7 @@ expected UnixDomainSocket::timedSendImpl(not_null(msgSizeToSend), 0, nullptr, 0) .failureReturnValue(ERROR_CODE) .evaluate(); @@ -85,7 +85,7 @@ expected UnixDomainSocket::timedReceiveImpl( return err(errnoToEnum(setsockoptCall.error().errnum)); } - auto recvCall = IOX_POSIX_CALL(iox_recvfrom)(m_sockfd, msg, maxMsgSize, 0, nullptr, nullptr) + auto recvCall = IOX_POSIX_CALL(iox_recvfrom)(m_sockfd, msg, static_cast(maxMsgSize), 0, nullptr, nullptr) .failureReturnValue(ERROR_CODE) .suppressErrorMessagesForErrnos(EAGAIN, EWOULDBLOCK) .evaluate(); diff --git a/iceoryx_hoofs/posix/ipc/include/iox/named_pipe.hpp b/iceoryx_hoofs/posix/ipc/include/iox/named_pipe.hpp index 8c20ecfcc0..123b35e799 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; }; @@ -212,7 +213,7 @@ class NamedPipeBuilder IOX_BUILDER_PARAMETER(PosixIpcChannelSide, channelSide, PosixIpcChannelSide::CLIENT) /// @brief Defines the max message size of the named pipe - IOX_BUILDER_PARAMETER(size_t, maxMsgSize, NamedPipe::MAX_MESSAGE_SIZE) + IOX_BUILDER_PARAMETER(uint64_t, maxMsgSize, NamedPipe::MAX_MESSAGE_SIZE) /// @brief Defines the max number of messages for the named pipe. IOX_BUILDER_PARAMETER(uint64_t, maxMsgNumber, NamedPipe::MAX_NUMBER_OF_MESSAGES) diff --git a/iceoryx_hoofs/posix/ipc/source/posix_memory_map.cpp b/iceoryx_hoofs/posix/ipc/source/posix_memory_map.cpp index c1e05e23dd..27c6500848 100644 --- a/iceoryx_hoofs/posix/ipc/source/posix_memory_map.cpp +++ b/iceoryx_hoofs/posix/ipc/source/posix_memory_map.cpp @@ -31,7 +31,7 @@ expected PosixMemoryMapBuilder::create() no // AXIVION Next Construct AutosarC++19_03-A5.2.3, CertC++-EXP55 : Incompatibility with POSIX definition of mmap // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) low-level memory management auto result = IOX_POSIX_CALL(mmap)(const_cast(m_baseAddressHint), - m_length, + static_cast(m_length), convertToProtFlags(m_accessMode), static_cast(m_flags), m_fileDescriptor, @@ -176,7 +176,8 @@ bool PosixMemoryMap::destroy() noexcept { if (m_baseAddress != nullptr) { - auto unmapResult = IOX_POSIX_CALL(munmap)(m_baseAddress, m_length).failureReturnValue(-1).evaluate(); + auto unmapResult = + IOX_POSIX_CALL(munmap)(m_baseAddress, static_cast(m_length)).failureReturnValue(-1).evaluate(); m_baseAddress = nullptr; m_length = 0U; diff --git a/iceoryx_hoofs/posix/ipc/source/posix_shared_memory.cpp b/iceoryx_hoofs/posix/ipc/source/posix_shared_memory.cpp index 0d4c0022b6..84a25e3c6d 100644 --- a/iceoryx_hoofs/posix/ipc/source/posix_shared_memory.cpp +++ b/iceoryx_hoofs/posix/ipc/source/posix_shared_memory.cpp @@ -129,7 +129,7 @@ expected PosixSharedMemoryBuilder::cr if (hasOwnership) { - auto result = IOX_POSIX_CALL(iox_ftruncate)(sharedMemoryFileHandle, static_cast(m_size)) + auto result = IOX_POSIX_CALL(iox_ftruncate)(sharedMemoryFileHandle, static_cast(m_size)) .failureReturnValue(PosixSharedMemory::INVALID_HANDLE) .evaluate(); if (result.has_error()) diff --git a/iceoryx_hoofs/posix/ipc/source/posix_shared_memory_object.cpp b/iceoryx_hoofs/posix/ipc/source/posix_shared_memory_object.cpp index 836c33a036..1cf72e2c60 100644 --- a/iceoryx_hoofs/posix/ipc/source/posix_shared_memory_object.cpp +++ b/iceoryx_hoofs/posix/ipc/source/posix_shared_memory_object.cpp @@ -163,7 +163,7 @@ expected PosixSharedMemor (m_baseAddressHint) ? *m_baseAddressHint : nullptr, m_permissions.value())); - memset(memoryMap->getBaseAddress(), 0, m_memorySizeInBytes); + memset(memoryMap->getBaseAddress(), 0, static_cast(m_memorySizeInBytes)); } IOX_LOG(DEBUG, "Acquired " << m_memorySizeInBytes << " bytes successfully in the shared memory [" << m_name << "]"); diff --git a/iceoryx_hoofs/posix/ipc/source/unix_domain_socket.cpp b/iceoryx_hoofs/posix/ipc/source/unix_domain_socket.cpp index 3090a3b5d0..74320da023 100644 --- a/iceoryx_hoofs/posix/ipc/source/unix_domain_socket.cpp +++ b/iceoryx_hoofs/posix/ipc/source/unix_domain_socket.cpp @@ -75,7 +75,8 @@ expected UnixDomainSocketBuilderNoPathPr { return err(PosixIpcChannelError::INVALID_CHANNEL_NAME); } - strncpy(&(sockAddr.sun_path[0]), m_name.c_str(), m_name.size()); + auto nameSize = m_name.size(); + strncpy(&(sockAddr.sun_path[0]), m_name.c_str(), static_cast(nameSize)); // the mask will be applied to the permissions, we only allow users and group members to have read and write access // the system call always succeeds, no need to check for errors 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/posix/utility/include/iox/detail/system_configuration.hpp b/iceoryx_hoofs/posix/utility/include/iox/detail/system_configuration.hpp index 8ff8c99a62..6ed96be76e 100644 --- a/iceoryx_hoofs/posix/utility/include/iox/detail/system_configuration.hpp +++ b/iceoryx_hoofs/posix/utility/include/iox/detail/system_configuration.hpp @@ -32,10 +32,6 @@ uint64_t pageSize() noexcept; /// @return True if called on 32-bit, false if not 32-bit system constexpr bool isCompiledOn32BitSystem() noexcept { - static_assert(build::IOX_IGNORE_32_BIT_CHECK_FLAG || INTPTR_MAX > INT32_MAX, - "iceoryx is only supported on 64-bit systems. Using it on 32-bit will result in race conditions in " - "the lock-free constructs!"); - return INTPTR_MAX == INT32_MAX; } } // namespace detail 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_cli_command_line_common.hpp b/iceoryx_hoofs/test/moduletests/test_cli_command_line_common.hpp index 9c78b4512a..2262de0611 100644 --- a/iceoryx_hoofs/test/moduletests/test_cli_command_line_common.hpp +++ b/iceoryx_hoofs/test/moduletests/test_cli_command_line_common.hpp @@ -30,10 +30,10 @@ struct CmdArgs explicit CmdArgs(const std::vector& arguments) : argc{static_cast(arguments.size())} - , argv{new char*[static_cast(argc)]} + , argv{new char*[static_cast(argc)]} { contents = std::make_unique>(arguments); - for (uint64_t i = 0; i < static_cast(argc); ++i) + for (size_t i = 0; i < static_cast(argc); ++i) { // NOLINTJUSTIFICATION required for test // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) 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_concurrent_spsc_sofi.cpp b/iceoryx_hoofs/test/moduletests/test_concurrent_spsc_sofi.cpp index dd48bf5a6c..2d724fb00c 100644 --- a/iceoryx_hoofs/test/moduletests/test_concurrent_spsc_sofi.cpp +++ b/iceoryx_hoofs/test/moduletests/test_concurrent_spsc_sofi.cpp @@ -388,7 +388,7 @@ TEST_F(SpscSofiTest, ResizeAndSizeFillUp) } } -TEST_F(SpscSofiTest, PopIfWithValidCondition) +TEST_F(SpscSofiTest, Pop) { ::testing::Test::RecordProperty("TEST_ID", "f149035c-21cc-4f7d-ba4d-564a645e933b"); sofi.push(10, returnVal); @@ -396,33 +396,22 @@ TEST_F(SpscSofiTest, PopIfWithValidCondition) sofi.push(12, returnVal); int output{-1}; - bool result = sofi.popIf(output, [](const int& peek) { return peek < 20; }); + bool result = sofi.pop(output); EXPECT_EQ(result, true); EXPECT_EQ(output, 10); } -TEST_F(SpscSofiTest, PopIfWithInvalidCondition) -{ - ::testing::Test::RecordProperty("TEST_ID", "1a494c28-928f-48f4-8b01-e68dfbd7563e"); - sofi.push(15, returnVal); - sofi.push(16, returnVal); - sofi.push(17, returnVal); - - bool result = sofi.popIf(returnVal, [](const int& peek) { return peek < 5; }); - - EXPECT_EQ(result, false); -} -TEST_F(SpscSofiTest, PopIfOnEmpty) +TEST_F(SpscSofiTest, PopOnEmpty) { ::testing::Test::RecordProperty("TEST_ID", "960ad78f-cb9b-4c34-a077-6adb343a841c"); - bool result = sofi.popIf(returnVal, [](const int& peek) { return peek < 7; }); + bool result = sofi.pop(returnVal); EXPECT_EQ(result, false); } -TEST_F(SpscSofiTest, PopIfFullWithValidCondition) +TEST_F(SpscSofiTest, PopFull) { ::testing::Test::RecordProperty("TEST_ID", "167f2f01-f926-4442-bc4f-ff5e7cfe9fe0"); constexpr int INITIAL_VALUE = 100; @@ -432,42 +421,21 @@ TEST_F(SpscSofiTest, PopIfFullWithValidCondition) sofi.push(i + INITIAL_VALUE, returnVal); } - bool result = sofi.popIf(returnVal, [](const int& peek) { return peek < 150; }); + bool result = sofi.pop(returnVal); EXPECT_EQ(result, true); EXPECT_EQ(returnVal, INITIAL_VALUE + OFFSET); } -TEST_F(SpscSofiTest, PopIfFullWithInvalidCondition) -{ - ::testing::Test::RecordProperty("TEST_ID", "672881b9-eebd-471d-9d62-e792a8b8013f"); - for (int i = 0; i < static_cast(sofi.capacity()) + 2; i++) - { - sofi.push(i + 100, returnVal); - } - - bool result = sofi.popIf(returnVal, [](const int& peek) { return peek < 50; }); - - EXPECT_EQ(result, false); -} - -TEST_F(SpscSofiTest, PopIfValidEmptyAfter) +TEST_F(SpscSofiTest, PopEmptyAfter) { ::testing::Test::RecordProperty("TEST_ID", "19444dcd-7746-4e6b-a3b3-398c9d62317d"); + sofi.push(2, returnVal); - sofi.popIf(returnVal, [](const int& peek) { return peek < 50; }); + sofi.pop(returnVal); EXPECT_EQ(sofi.empty(), true); } -TEST_F(SpscSofiTest, PopIfInvalidNotEmptyAfter) -{ - ::testing::Test::RecordProperty("TEST_ID", "cadd7f02-6fe5-49a5-bd5d-837f5fcb2a71"); - sofi.push(200, returnVal); - - sofi.popIf(returnVal, [](const int& peek) { return peek < 50; }); - - EXPECT_EQ(sofi.empty(), false); -} } // namespace diff --git a/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp b/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp index bba82bb50d..9de51449ee 100644 --- a/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp +++ b/iceoryx_hoofs/test/moduletests/test_container_fixed_position_container.cpp @@ -2455,7 +2455,7 @@ TEST_F(FixedPositionContainer_test, PartiallyFilledUpContainerCallsDestructorOnE } } - uint64_t i = 0; + size_t i = 0; for (const auto value : stats.dTorOrder) { EXPECT_THAT(value, Eq(expected_values[i])); @@ -2586,7 +2586,7 @@ TEST_F(FixedPositionContainer_test, ClearAfterPartiallyFillingContainerUpCallsDe } } - uint64_t i = 0; + size_t i = 0; for (const auto value : stats.dTorOrder) { EXPECT_THAT(value, Eq(expected_values[i])); diff --git a/iceoryx_hoofs/test/moduletests/test_container_vector.cpp b/iceoryx_hoofs/test/moduletests/test_container_vector.cpp index ab4a6c342c..d694e1cc41 100644 --- a/iceoryx_hoofs/test/moduletests/test_container_vector.cpp +++ b/iceoryx_hoofs/test/moduletests/test_container_vector.cpp @@ -498,7 +498,7 @@ TEST_F(vector_test, ReverseDestructionOrderInCopyAssignment) EXPECT_THAT(stats.dTor, Eq(VECTOR_CAPACITY)); ASSERT_THAT(stats.dTorOrder.size(), Eq(VECTOR_CAPACITY)); - for (uint64_t i{0}; i < VECTOR_CAPACITY; ++i) + for (size_t i{0}; i < VECTOR_CAPACITY; ++i) { EXPECT_THAT(stats.dTorOrder[i], Eq(VECTOR_CAPACITY - 1 - i)); } @@ -518,7 +518,7 @@ TEST_F(vector_test, ReverseDestructionOrderInMoveAssignment) EXPECT_THAT(stats.dTor, Eq(VECTOR_CAPACITY)); ASSERT_THAT(stats.dTorOrder.size(), Eq(VECTOR_CAPACITY)); - for (uint64_t i{0}; i < VECTOR_CAPACITY; ++i) + for (size_t i{0}; i < VECTOR_CAPACITY; ++i) { EXPECT_THAT(stats.dTorOrder[i], Eq(VECTOR_CAPACITY - i)); } @@ -1262,7 +1262,7 @@ TEST_F(vector_test, FullVectorDestroysElementsInReverseOrder) } ASSERT_THAT(stats.dTorOrder.size(), Eq(VECTOR_CAPACITY)); - for (uint64_t i = 0U; i < VECTOR_CAPACITY; ++i) + for (size_t i = 0U; i < VECTOR_CAPACITY; ++i) { EXPECT_THAT(stats.dTorOrder[i], Eq(INDEX_END - i + SOME_OFFSET)); } @@ -1286,7 +1286,7 @@ TEST_F(vector_test, PartiallyFullVectorDestroysElementsInReverseOrder) } ASSERT_THAT(stats.dTorOrder.size(), Eq(VECTOR_SIZE)); - for (uint64_t i = 0U; i < VECTOR_SIZE; ++i) + for (size_t i = 0U; i < VECTOR_SIZE; ++i) { EXPECT_THAT(stats.dTorOrder[i], Eq(INDEX_END - i + SOME_OFFSET)); } 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..45d661362f 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 @@ -87,7 +87,8 @@ class UnixDomainSocket_test : public Test memset(&sockAddr, 0, sizeof(sockAddr)); sockAddr.sun_family = AF_LOCAL; - strncpy(&(sockAddr.sun_path[0]), name.c_str(), name.size()); + auto nameSize = name.size(); + strncpy(&(sockAddr.sun_path[0]), name.c_str(), static_cast(nameSize)); IOX_POSIX_CALL(iox_socket) (AF_LOCAL, SOCK_DGRAM, 0) @@ -128,7 +129,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 +809,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/moduletests/test_time_unit_duration.cpp b/iceoryx_hoofs/test/moduletests/test_time_unit_duration.cpp index 5cf61a5026..8c5f842d2b 100644 --- a/iceoryx_hoofs/test/moduletests/test_time_unit_duration.cpp +++ b/iceoryx_hoofs/test/moduletests/test_time_unit_duration.cpp @@ -1050,7 +1050,7 @@ TEST(Duration_test, ConvertTimespecWithNoneReferenceFromDurationMoreThanOneSecon TEST(Duration_test, ConvertTimespecWithNoneReferenceFromDurationResultsNotYetInSaturation) { ::testing::Test::RecordProperty("TEST_ID", "70f11b99-78ec-442a-aefe-4dd9152b7903"); - constexpr int64_t SECONDS{std::numeric_limits::max()}; + constexpr int64_t SECONDS{std::numeric_limits::max()}; constexpr int64_t NANOSECONDS{NANOSECS_PER_SECOND - 1U}; auto duration = createDuration(SECONDS, NANOSECONDS); @@ -1064,7 +1064,7 @@ TEST(Duration_test, ConvertTimespecWithNoneReferenceFromDurationResultsNotYetInS TEST(Duration_test, ConvertTimespecWithNoneReferenceFromMaxDurationResultsInSaturation) { ::testing::Test::RecordProperty("TEST_ID", "3bf4bb34-46f3-4889-84f5-9220b32fff73"); - constexpr int64_t SECONDS{std::numeric_limits::max()}; + constexpr int64_t SECONDS{std::numeric_limits::max()}; constexpr int64_t NANOSECONDS{NANOSECS_PER_SECOND - 1U}; const timespec sut = DurationAccessor::max().timespec(iox::units::TimeSpecReference::None); @@ -1101,7 +1101,7 @@ TEST(Duration_test, ConvertTimespecWithMonotonicReference) TEST(Duration_test, ConvertTimespecWithMonotonicReferenceFromMaxDurationResultsInSaturation) { ::testing::Test::RecordProperty("TEST_ID", "ff5a1fe2-65c8-490a-b31d-4d8ea615c91a"); - constexpr int64_t SECONDS{std::numeric_limits::max()}; + constexpr int64_t SECONDS{std::numeric_limits::max()}; constexpr int64_t NANOSECONDS{NANOSECS_PER_SECOND - 1U}; const timespec sut = DurationAccessor::max().timespec(iox::units::TimeSpecReference::Monotonic); @@ -1129,7 +1129,7 @@ TEST(Duration_test, ConvertTimespecWithEpochReference) TEST(Duration_test, ConvertTimespecWithEpochReferenceFromMaxDurationResultsInSaturation) { ::testing::Test::RecordProperty("TEST_ID", "97ff4204-a7f7-43ef-b81e-0e359d1dce93"); - constexpr int64_t SECONDS{std::numeric_limits::max()}; + constexpr int64_t SECONDS{std::numeric_limits::max()}; constexpr int64_t NANOSECONDS{NANOSECS_PER_SECOND - 1U}; const timespec sut = DurationAccessor::max().timespec(iox::units::TimeSpecReference::Epoch); diff --git a/iceoryx_hoofs/test/moduletests/test_utility_std_string_support.cpp b/iceoryx_hoofs/test/moduletests/test_utility_std_string_support.cpp index ae111a541b..e88ee2ba35 100644 --- a/iceoryx_hoofs/test/moduletests/test_utility_std_string_support.cpp +++ b/iceoryx_hoofs/test/moduletests/test_utility_std_string_support.cpp @@ -543,7 +543,7 @@ TYPED_TEST(StdString_test, AppendStdStringContainingNullWorks) sut.append(TruncateToCapacity, testStdString); EXPECT_THAT(sut.capacity(), Eq(RESULT_CAPACITY)); EXPECT_THAT(sut.size(), Eq(7U)); - EXPECT_THAT(std::memcmp(sut.c_str(), expectedString.c_str(), sut.size()), Eq(0)); + EXPECT_THAT(std::memcmp(sut.c_str(), expectedString.c_str(), static_cast(sut.size())), Eq(0)); } TYPED_TEST(StdString_test, FindStdStringInEmptyStringFails) diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp index 4309422fed..76e4e0bad0 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_semantic_string.cpp @@ -500,7 +500,7 @@ TYPED_TEST(SemanticString_test, InsertValidContentToValidStringWorks) { for (auto& add_value : TestValues::VALID_VALUES) { - for (uint64_t insert_position = 0; insert_position < value.size(); ++insert_position) + for (size_t insert_position = 0; insert_position < value.size(); ++insert_position) { auto sut = SutType::create(string(TruncateToCapacity, value.c_str())); ASSERT_THAT(sut.has_error(), Eq(false)); diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_string_concatenate_append_and_insert.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_string_concatenate_append_and_insert.cpp index 26e78672ed..43ad950a6b 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_string_concatenate_append_and_insert.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_string_concatenate_append_and_insert.cpp @@ -95,9 +95,9 @@ TYPED_TEST(stringTyped_test, ConcatenateThreeStringsWorks) string testString2("YOD"); auto testString3 = concatenate(testString2, this->testSubject, testString1); - std::string cmpString = std::string(testString2.c_str(), testString2.size()) - + std::string(this->testSubject.c_str(), this->testSubject.size()) - + std::string(testString1.c_str(), testString1.size()); + std::string cmpString = std::string(testString2.c_str(), static_cast(testString2.size())) + + std::string(this->testSubject.c_str(), static_cast(this->testSubject.size())) + + std::string(testString1.c_str(), static_cast(testString1.size())); EXPECT_THAT(testString3.capacity(), Eq(3U * STRINGCAP + 2U)); EXPECT_THAT(testString3.size(), Eq(cmpString.size())); EXPECT_THAT(testString3.c_str(), StrEq(cmpString)); @@ -566,7 +566,7 @@ TYPED_TEST(stringTyped_test, AppendStringContainingNullWorks) sut.append(TruncateToCapacity, testCxxString); EXPECT_THAT(sut.capacity(), Eq(RESULT_CAPACITY)); EXPECT_THAT(sut.size(), Eq(7U)); - EXPECT_THAT(std::memcmp(sut.c_str(), expectedString.c_str(), sut.size()), Eq(0)); + EXPECT_THAT(std::memcmp(sut.c_str(), expectedString.c_str(), static_cast(sut.size())), Eq(0)); } /// @note string& append(TruncateToCapacity_t, char c) noexcept diff --git a/iceoryx_hoofs/test/moduletests/test_vocabulary_string_ctor_and_assign.cpp b/iceoryx_hoofs/test/moduletests/test_vocabulary_string_ctor_and_assign.cpp index 4ce0d48f64..e5bd6dc8d2 100644 --- a/iceoryx_hoofs/test/moduletests/test_vocabulary_string_ctor_and_assign.cpp +++ b/iceoryx_hoofs/test/moduletests/test_vocabulary_string_ctor_and_assign.cpp @@ -171,12 +171,12 @@ TYPED_TEST(stringTyped_test, SelfMoveAssignmentExcluded) { ::testing::Test::RecordProperty("TEST_ID", "0ad45975-b68b-465a-b8c5-83dd8d8290d5"); this->testSubject = "M"; -#if (defined(__GNUC__) && __GNUC__ == 13 && !defined(__clang__)) +#if (defined(__GNUC__) && (__GNUC__ >= 13 && __GNUC__ <= 14) && !defined(__clang__)) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wself-move" #endif this->testSubject = std::move(this->testSubject); -#if (defined(__GNUC__) && __GNUC__ == 13 && !defined(__clang__)) +#if (defined(__GNUC__) && (__GNUC__ >= 13 && __GNUC__ <= 14) == 13 && !defined(__clang__)) #pragma GCC diagnostic pop #endif EXPECT_THAT(this->testSubject.size(), Eq(1U)); 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..d21f6f1c26 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,14 +71,16 @@ 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(); bool error = false; - std::vector lastCount(maxId + 1, 0); + std::vector lastCount(static_cast(maxId) + 1U, 0); while (run || !queue.empty()) { @@ -86,16 +88,16 @@ void consume(Queue& queue, std::atomic& run, uint64_t expectedFinalCount, if (popped.has_value()) { auto& value = popped.value(); - if (lastCount[value.id] + 1 != value.count) + if (lastCount[static_cast(value.id)] + 1 != value.count) { error = true; } - lastCount[value.id] = value.count; + lastCount[static_cast(value.id)] = value.count; } } - for (uint64_t i = 1; i <= maxId; ++i) + for (size_t i = 1; i <= maxId; ++i) { if (lastCount[i] != expectedFinalCount) { @@ -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(); @@ -148,7 +150,7 @@ bool isStrictlyMonotonic(std::list& list) return true; } - size_t prev = iter->count; + auto prev = iter->count; iter++; while (iter != list.end()) @@ -169,12 +171,12 @@ bool isComplete(std::list& list1, std::list& list2, size_t finalCoun std::vector count(finalCount + 1); for (auto& data : list1) { - count[data.count]++; + count[static_cast(data.count)]++; } for (auto& data : list2) { - count[data.count]++; + count[static_cast(data.count)]++; } for (size_t i = 1; i <= finalCount; ++i) @@ -194,7 +196,7 @@ bool checkTwoConsumerResult(std::list& consumed1, uint64_t expectedFinalCount, uint64_t maxId) { - std::vector> consumed(maxId + 1U); + std::vector> consumed(static_cast(maxId) + 1U); for (uint64_t id = 1; id <= maxId; ++id) { @@ -207,7 +209,7 @@ bool checkTwoConsumerResult(std::list& consumed1, return false; } - if (!isComplete(filtered1, filtered2, expectedFinalCount)) + if (!isComplete(filtered1, filtered2, static_cast(expectedFinalCount))) { IOX_LOG(INFO, "id " << id << " incomplete"); return false; @@ -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; @@ -515,11 +517,11 @@ TYPED_TEST(MpmcLockFreeQueueStressTest, TimedMultiProducerMultiConsumer) } // check whether all elements are there, but there is no specific ordering we can expect - std::vector count(capacity, 0); + std::vector count(static_cast(capacity), 0); auto popped = q.pop(); while (popped.has_value()) { - count[popped.value().count]++; + count[static_cast(popped.value().count)]++; popped = q.pop(); } @@ -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); @@ -583,8 +585,8 @@ TYPED_TEST(MpmcLockFreeQueueStressTest, TimedMultiProducerMultiConsumer0verflow) std::ref(q), id, std::ref(run), - std::ref(overflowCount[id - 1]), - std::ref(itemVec[id - 1]), + std::ref(overflowCount[static_cast(id) - 1]), + std::ref(itemVec[static_cast(id) - 1]), popProbability); } @@ -601,11 +603,11 @@ TYPED_TEST(MpmcLockFreeQueueStressTest, TimedMultiProducerMultiConsumer0verflow) // check whether all elements are there, but there is no specific ordering we can expect // items are either in the local lists or the queue, in total we expect each count numThreads times - std::vector count(capacity, 0U); + std::vector count(static_cast(capacity), 0U); auto popped = q.pop(); while (popped.has_value()) { - count[popped.value().count]++; + count[static_cast(popped.value().count)]++; popped = q.pop(); } @@ -614,14 +616,14 @@ TYPED_TEST(MpmcLockFreeQueueStressTest, TimedMultiProducerMultiConsumer0verflow) { for (auto& item : items) { - count[item.count]++; + count[static_cast(item.count)]++; } } // we expect at least one overflow in the test (since the queue is full in the beginning) // we cannot expect one overflow in each thread due to thread scheduling auto numOverflows = std::accumulate(overflowCount.begin(), overflowCount.end(), 0ULL); - EXPECT_GT(numOverflows, 0LL); + EXPECT_GT(numOverflows, 0ULL); bool testResult = true; for (size_t i = 0; i < capacity; ++i) 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..8af8784a4a 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(); @@ -66,14 +65,14 @@ void producePeriodic(Queue& queue, const uint32_t id, CountArray& producedCount, { if (queue.tryPush(d)) { - producedCount[d.count].fetch_add(1U, std::memory_order_relaxed); + producedCount[static_cast(d.count)].fetch_add(1U, std::memory_order_relaxed); d.count = (d.count + 1U) % n; } } } template -void consume(Queue& queue, CountArray& consumedCount, std::atomic_bool& run) +void consume(Queue& queue, CountArray& consumedCount, iox::concurrent::Atomic& run) { g_barrier.notify(); @@ -84,13 +83,13 @@ void consume(Queue& queue, CountArray& consumedCount, std::atomic_bool& run) if (popped.has_value()) { const auto& value = popped.value(); - consumedCount[value.count].fetch_add(1U, std::memory_order_relaxed); + consumedCount[static_cast(value.count)].fetch_add(1U, std::memory_order_relaxed); } } } 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) @@ -302,7 +305,7 @@ void changeCapacity(Queue& queue, incrementK = false; } - if (queue.setCapacity(capacities[static_cast(k)], removeHandler)) + if (queue.setCapacity(capacities[static_cast(k)], removeHandler)) { ++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}; @@ -424,7 +427,7 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, MultiProducerMultiConsumerComp CountArray consumedCount(cycleLength); // cannot be done with the vector ctor for atomics - for (uint64_t i = 0; i < cycleLength; ++i) + for (size_t i = 0; i < cycleLength; ++i) { producedCount[i].store(0U, std::memory_order_relaxed); consumedCount[i].store(0U, std::memory_order_relaxed); @@ -462,11 +465,11 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, MultiProducerMultiConsumerComp while (const auto popped = queue.pop()) { const auto& value = popped.value(); - consumedCount[value.count].fetch_add(1U, std::memory_order_relaxed); + consumedCount[static_cast(value.count)].fetch_add(1U, std::memory_order_relaxed); } // verify counts - for (uint64_t i = 0; i < cycleLength; ++i) + for (size_t i = 0; i < cycleLength; ++i) { EXPECT_EQ(producedCount[i].load(), consumedCount[i].load()); } @@ -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; @@ -572,11 +575,11 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, HybridMultiProducerMultiConsum } // check whether all elements are there, but there is no specific ordering we can expect - std::vector count(capacity, 0); + std::vector count(static_cast(capacity), 0); auto popped = q.pop(); while (popped.has_value()) { - count[popped.value().count]++; + count[static_cast(popped.value().count)]++; popped = q.pop(); } @@ -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); @@ -664,12 +667,12 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, HybridMultiProducerMultiConsum // items are either in the local lists or the queue, in total we expect each count numThreads times // and for each count each id exactly once - std::vector> count(capacity, std::vector(numThreads + 1, 0)); + std::vector> count(static_cast(capacity), std::vector(numThreads + 1, 0)); auto popped = q.pop(); while (popped.has_value()) { const auto& value = popped.value(); - count[value.count][value.id]++; + count[static_cast(value.count)][value.id]++; popped = q.pop(); } @@ -678,7 +681,7 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, HybridMultiProducerMultiConsum { for (auto& item : items) { - count[item.count][item.id]++; + count[static_cast(item.count)][item.id]++; } } @@ -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); @@ -784,12 +787,12 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, HybridMultiProducerMultiConsum // items are either in the local lists or the queue, in total we expect each count numThreads times // and for each count each id exactly once - std::vector> count(capacity, std::vector(numThreads + 1, 0)); + std::vector> count(static_cast(capacity), std::vector(numThreads + 1, 0)); auto popped = q.pop(); while (popped.has_value()) { const auto& value = popped.value(); - count[value.count][value.id]++; + count[static_cast(value.count)][value.id]++; popped = q.pop(); } @@ -798,17 +801,17 @@ TYPED_TEST(MpmcResizeableLockFreeQueueStressTest, HybridMultiProducerMultiConsum { for (auto& item : items) { - count[item.count][item.id]++; + count[static_cast(item.count)][item.id]++; } } bool testResult = true; - for (uint64_t i = 0; i < capacity; ++i) + for (size_t i = 0; i < capacity; ++i) { // we expect each data item exactly numThreads + 1 times, // the extra one is for the initially full queue // and each count appears for all ids exactly ones - for (uint32_t j = 0; j <= numThreads; ++j) + for (size_t j = 0; j <= numThreads; ++j) { if (count[i][j] != 1) { diff --git a/iceoryx_hoofs/testing/CMakeLists.txt b/iceoryx_hoofs/testing/CMakeLists.txt index fffa71d365..202ec59977 100644 --- a/iceoryx_hoofs/testing/CMakeLists.txt +++ b/iceoryx_hoofs/testing/CMakeLists.txt @@ -38,6 +38,9 @@ iox_add_library( error_reporting/testing_support.cpp ) +# deactivate _FORTIFY_SOURCE since it causes issues with longjmp in the testing logger and error handler +target_compile_options(iceoryx_hoofs_testing PRIVATE -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0) + if(TEST_WITH_ADDITIONAL_USER) target_compile_definitions(iceoryx_hoofs_testing PUBLIC -DTEST_WITH_ADDITIONAL_USER) endif(TEST_WITH_ADDITIONAL_USER) 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/testing_logger.cpp b/iceoryx_hoofs/testing/testing_logger.cpp index 9803e1a74d..73f1589193 100644 --- a/iceoryx_hoofs/testing/testing_logger.cpp +++ b/iceoryx_hoofs/testing/testing_logger.cpp @@ -83,6 +83,7 @@ void TestingLogger::printLogBuffer() noexcept puts(log.c_str()); } puts("#### Log end ####"); + loggerData->buffer.clear(); } uint64_t TestingLogger::getNumberOfLogMessages() noexcept 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/serialization.inl b/iceoryx_hoofs/utility/include/iox/detail/serialization.inl index 7c8ee96c55..46f0f2213b 100644 --- a/iceoryx_hoofs/utility/include/iox/detail/serialization.inl +++ b/iceoryx_hoofs/utility/include/iox/detail/serialization.inl @@ -107,13 +107,13 @@ inline bool Serialization::deserialize(const std::string& serializedString, T& t inline bool Serialization::removeFirstEntry(std::string& firstEntry, std::string& remainder) noexcept { - uint64_t pos = remainder.find_first_of(SEPARATOR); + auto pos = remainder.find_first_of(SEPARATOR); if (pos == std::string::npos) { return false; } - auto result = convert::from_string(remainder.substr(0, pos).c_str()); + auto result = convert::from_string(remainder.substr(0U, pos).c_str()); if (!result.has_value()) { diff --git a/iceoryx_hoofs/utility/include/iox/detail/std_string_support.inl b/iceoryx_hoofs/utility/include/iox/detail/std_string_support.inl index ea5c5aba5d..95106d03b7 100644 --- a/iceoryx_hoofs/utility/include/iox/detail/std_string_support.inl +++ b/iceoryx_hoofs/utility/include/iox/detail/std_string_support.inl @@ -24,7 +24,7 @@ namespace iox template inline std::string FromImpl, std::string>::fromImpl(const string& value) noexcept { - return std::string(value.c_str(), value.size()); + return std::string(value.c_str(), static_cast(value.size())); } template 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_hoofs/vocabulary/include/iox/detail/string.inl b/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl index 4ed91aa090..4c96ca7b08 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl +++ b/iceoryx_hoofs/vocabulary/include/iox/detail/string.inl @@ -147,7 +147,7 @@ inline string::string(TruncateToCapacity_t, const char* const other, c } else { - std::memcpy(m_rawstring, other, count); + std::memcpy(m_rawstring, other, static_cast(count)); m_rawstring[count] = '\0'; m_rawstringSize = count; } @@ -187,7 +187,7 @@ inline string& string::operator=(const char (&rhs)[N]) noexc #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Warray-bounds" #endif - std::memcpy(m_rawstring, rhs, m_rawstringSize); + std::memcpy(m_rawstring, rhs, static_cast(m_rawstringSize)); #if (defined(__GNUC__) && (__GNUC__ == 8)) && (__GNUC_MINOR__ >= 3) #pragma GCC diagnostic pop #endif @@ -234,7 +234,7 @@ inline bool string::unsafe_assign(const char* const str) noexcept << ") of the fixed string."); return false; } - std::memcpy(m_rawstring, str, strSize); + std::memcpy(m_rawstring, str, static_cast(strSize)); m_rawstring[strSize] = '\0'; m_rawstringSize = strSize; return true; @@ -264,7 +264,8 @@ template inline IsStringOrCharArray string::compare(const T& other) const noexcept { const uint64_t otherSize{internal::GetSize::call(other)}; - const auto result = memcmp(c_str(), internal::GetData::call(other), std::min(m_rawstringSize, otherSize)); + const auto result = + memcmp(c_str(), internal::GetData::call(other), static_cast(std::min(m_rawstringSize, otherSize))); if (result == 0) { if (m_rawstringSize < otherSize) @@ -330,7 +331,7 @@ inline string& string::copy(const string& rhs) noexcept static_assert(N <= Capacity, "Assignment failed. The capacity of the given fixed string is larger than the capacity of this."); const uint64_t strSize{rhs.size()}; - std::memcpy(m_rawstring, rhs.c_str(), strSize); + std::memcpy(m_rawstring, rhs.c_str(), static_cast(strSize)); m_rawstring[strSize] = '\0'; m_rawstringSize = strSize; return *this; @@ -344,7 +345,7 @@ inline string& string::move(string&& rhs) noexcept static_assert(N <= Capacity, "Assignment failed. The capacity of the given fixed string is larger than the capacity of this."); const uint64_t strSize{rhs.size()}; - std::memcpy(m_rawstring, rhs.c_str(), strSize); + std::memcpy(m_rawstring, rhs.c_str(), static_cast(strSize)); m_rawstring[strSize] = '\0'; m_rawstringSize = strSize; rhs.clear(); @@ -379,8 +380,8 @@ concatenate(const T1& str1, const T2& str2) noexcept uint64_t size2{internal::GetSize::call(str2)}; using NewStringType = string::value>; NewStringType newString; - std::memcpy(newString.m_rawstring, internal::GetData::call(str1), size1); - std::memcpy(&newString.m_rawstring[size1], internal::GetData::call(str2), size2); + std::memcpy(newString.m_rawstring, internal::GetData::call(str1), static_cast(size1)); + std::memcpy(&newString.m_rawstring[size1], internal::GetData::call(str2), static_cast(size2)); newString.m_rawstring[size1 + size2] = '\0'; newString.m_rawstringSize = size1 + size2; @@ -417,7 +418,7 @@ inline IsStringOrCharArrayOrChar string::unsafe_append(const return false; } - std::memcpy(&(m_rawstring[m_rawstringSize]), tData, clampedTSize); + std::memcpy(&(m_rawstring[m_rawstringSize]), tData, static_cast(clampedTSize)); m_rawstringSize += clampedTSize; m_rawstring[m_rawstringSize] = '\0'; return true; @@ -434,7 +435,7 @@ inline IsStringOrCharArrayOrChar&> string::append( const char* const tData{internal::GetData::call(str)}; uint64_t const clampedTSize{std::min(Capacity - m_rawstringSize, tSize)}; - std::memcpy(&(m_rawstring[m_rawstringSize]), tData, clampedTSize); + std::memcpy(&(m_rawstring[m_rawstringSize]), tData, static_cast(clampedTSize)); if (tSize > clampedTSize) { IOX_LOG(WARN, @@ -487,8 +488,9 @@ string::insert(const uint64_t pos, const T& str, const uint64_t count) { return false; } - std::memmove(&m_rawstring[pos + count], &m_rawstring[pos], m_rawstringSize - pos); - std::memcpy(&m_rawstring[pos], internal::GetData::call(str), count); + auto number_of_characters_to_move = static_cast(m_rawstringSize) - static_cast(pos); + std::memmove(&m_rawstring[pos + count], &m_rawstring[pos], number_of_characters_to_move); + std::memcpy(&m_rawstring[pos], internal::GetData::call(str), static_cast(count)); m_rawstring[new_size] = '\0'; m_rawstringSize = new_size; @@ -506,7 +508,7 @@ inline optional> string::substr(const uint64_t pos, c const uint64_t length{std::min(count, m_rawstringSize - pos)}; string subString; - std::memcpy(subString.m_rawstring, &m_rawstring[pos], length); + std::memcpy(subString.m_rawstring, &m_rawstring[pos], static_cast(length)); subString.m_rawstring[length] = '\0'; subString.m_rawstringSize = length; return subString; @@ -549,7 +551,7 @@ inline IsStringOrCharArray> string::find_first_o const uint64_t dataSize{internal::GetSize::call(str)}; for (auto p = pos; p < m_rawstringSize; ++p) { - const void* const found{memchr(data, m_rawstring[p], dataSize)}; + const void* const found{memchr(data, m_rawstring[p], static_cast(dataSize))}; if (found != nullptr) { return p; @@ -577,13 +579,13 @@ inline IsStringOrCharArray> string::find_last_of const uint64_t dataSize{internal::GetSize::call(str)}; for (; p > 0U; --p) { - const void* const found{memchr(data, m_rawstring[p], dataSize)}; + const void* const found{memchr(data, m_rawstring[p], static_cast(dataSize))}; if (found != nullptr) { return p; } } - const void* const found{memchr(data, m_rawstring[p], dataSize)}; + const void* const found{memchr(data, m_rawstring[p], static_cast(dataSize))}; if (found != nullptr) { return 0U; diff --git a/iceoryx_meta/CMakeLists.txt b/iceoryx_meta/CMakeLists.txt index 1a9a536d06..68cd4181ba 100644 --- a/iceoryx_meta/CMakeLists.txt +++ b/iceoryx_meta/CMakeLists.txt @@ -90,9 +90,11 @@ message(" platform..................: " ${ICEORYX_PLATFORM_STRING}) message(" project name..............: " ${CMAKE_PROJECT_NAME}) message(" c compiler................: " ${CMAKE_C_COMPILER}) message(" c++ compiler..............: " ${CMAKE_CXX_COMPILER}) -message(" c++ standard..............: " ${ICEORYX_CXX_STANDARD}) +message(" c flags...................: " ${CMAKE_C_FLAGS}) +message(" c++ flags.................: " ${CMAKE_CXX_FLAGS}) message(" cmake.....................: " ${CMAKE_VERSION}) -message(" Flags from iceoryx platform") +message(" Additional flags from iceoryx platform") +message(" c++ standard..............: " ${ICEORYX_CXX_STANDARD}) message(" c flags...................: " ${ICEORYX_C_FLAGS}) message(" c warning flags...........: " ${ICEORYX_C_WARNINGS}) message(" c++ flags.................: " ${ICEORYX_CXX_FLAGS}) diff --git a/iceoryx_meta/build_options.cmake b/iceoryx_meta/build_options.cmake index 83e0b2f644..51ce45adea 100644 --- a/iceoryx_meta/build_options.cmake +++ b/iceoryx_meta/build_options.cmake @@ -37,7 +37,6 @@ option(TEST_WITH_ADDITIONAL_USER "Build Test with additional user accounts for t option(TEST_WITH_HUGE_PAYLOAD "Build Tests which use payload bigger than 2GB" OFF) option(TOML_CONFIG "TOML support for RouDi with dynamic configuration" ON) option(IOX_EXPERIMENTAL_POSH "Export experimental posh features (no guarantees)" OFF) -option(IOX_IGNORE_32_BIT_CHECK "Ignores the check for 32 bit systems! It is not recommended to turn this on in production systems" OFF) option(IOX_REPRODUCIBLE_BUILD "Create reproducible builds by omit setting the build timestamp in the version header" ON) option(USE_SYSTEMD "Build with systemd support" OFF) @@ -98,7 +97,6 @@ function(show_config_options) message(" TEST_WITH_HUGE_PAYLOAD ..............: " ${TEST_WITH_HUGE_PAYLOAD}) message(" TOML_CONFIG..........................: " ${TOML_CONFIG}) message(" IOX_EXPERIMENTAL_POSH................: " ${IOX_EXPERIMENTAL_POSH}) - message(" IOX_IGNORE_32_BIT_CHECK..............: " ${IOX_IGNORE_32_BIT_CHECK}) message(" IOX_REPRODUCIBLE_BUILD...............: " ${IOX_REPRODUCIBLE_BUILD}) message(" USE_SYSTEMD..........................: " ${USE_SYSTEMD}) endfunction() 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/linux/cmake/IceoryxPlatformSettings.cmake b/iceoryx_platform/linux/cmake/IceoryxPlatformSettings.cmake index 61343796eb..084cb4df1f 100644 --- a/iceoryx_platform/linux/cmake/IceoryxPlatformSettings.cmake +++ b/iceoryx_platform/linux/cmake/IceoryxPlatformSettings.cmake @@ -23,9 +23,6 @@ set_global(VAR ICEORYX_TEST_CXX_FLAGS VALUE ) set_global(VAR ICEORYX_C_WARNINGS VALUE -W -Wall -Wextra -Wuninitialized -Wpedantic -Wstrict-aliasing -Wcast-align -Wconversion) set_global(VAR ICEORYX_CXX_WARNINGS VALUE ${ICEORYX_C_WARNINGS} -Wno-noexcept-type) -if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") - set_global(VAR ICEORYX_CXX_WARNINGS VALUE ${ICEORYX_CXX_WARNINGS} -Wuseless-cast) -endif() if(BUILD_STRICT) set_global(VAR ICEORYX_C_WARNINGS VALUE ${ICEORYX_C_WARNINGS} -Werror) 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/qnx/cmake/IceoryxPlatformSettings.cmake b/iceoryx_platform/qnx/cmake/IceoryxPlatformSettings.cmake index 6440019655..11d59ab562 100644 --- a/iceoryx_platform/qnx/cmake/IceoryxPlatformSettings.cmake +++ b/iceoryx_platform/qnx/cmake/IceoryxPlatformSettings.cmake @@ -22,7 +22,7 @@ set_global(VAR ICEORYX_CXX_FLAGS VALUE ) set_global(VAR ICEORYX_TEST_CXX_FLAGS VALUE ) set_global(VAR ICEORYX_C_WARNINGS VALUE -W -Wall -Wextra -Wuninitialized -Wpedantic -Wstrict-aliasing -Wcast-align -Wconversion) -set_global(VAR ICEORYX_CXX_WARNINGS VALUE ${ICEORYX_C_WARNINGS} -Wno-noexcept-type -Wno-useless-cast) +set_global(VAR ICEORYX_CXX_WARNINGS VALUE ${ICEORYX_C_WARNINGS} -Wno-noexcept-type) if(BUILD_STRICT) set_global(VAR ICEORYX_C_WARNINGS VALUE ${ICEORYX_C_WARNINGS} -Werror) 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"); 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/acl.hpp b/iceoryx_platform/win/include/iceoryx_platform/acl.hpp index 6c18ed8010..8d69c5e08a 100644 --- a/iceoryx_platform/win/include/iceoryx_platform/acl.hpp +++ b/iceoryx_platform/win/include/iceoryx_platform/acl.hpp @@ -83,7 +83,7 @@ inline int acl_add_perm(acl_permset_t permset_d, acl_perm_t perm) return 0; } -inline char* acl_to_text(acl_t acl, ssize_t* len_p) +inline char* acl_to_text(acl_t acl, iox_ssize_t* len_p) { return nullptr; } diff --git a/iceoryx_platform/win/include/iceoryx_platform/mqueue.hpp b/iceoryx_platform/win/include/iceoryx_platform/mqueue.hpp index 87818c6a87..fd0083748f 100644 --- a/iceoryx_platform/win/include/iceoryx_platform/mqueue.hpp +++ b/iceoryx_platform/win/include/iceoryx_platform/mqueue.hpp @@ -52,12 +52,12 @@ inline int mq_close(mqd_t mqdes) //{ //} -inline ssize_t mq_receive(mqd_t mqdes, char* msg_ptr, size_t msg_len, unsigned int* msg_prio) +inline iox_ssize_t mq_receive(mqd_t mqdes, char* msg_ptr, size_t msg_len, unsigned int* msg_prio) { return 0; } -inline ssize_t +inline iox_ssize_t mq_timedreceive(mqd_t mqdes, char* msg_ptr, size_t msg_len, unsigned int* msg_prio, const struct timespec* abs_timeout) { return 0; diff --git a/iceoryx_platform/win/include/iceoryx_platform/socket.hpp b/iceoryx_platform/win/include/iceoryx_platform/socket.hpp index e7a3591436..7352094197 100644 --- a/iceoryx_platform/win/include/iceoryx_platform/socket.hpp +++ b/iceoryx_platform/win/include/iceoryx_platform/socket.hpp @@ -30,9 +30,9 @@ using sa_family_t = int; int iox_bind(int sockfd, const struct sockaddr* addr, socklen_t addrlen); int iox_socket(int domain, int type, int protocol); int iox_setsockopt(int sockfd, int level, int optname, const void* optval, socklen_t optlen); -ssize_t +iox_ssize_t iox_sendto(int sockfd, const void* buf, size_t len, int flags, const struct sockaddr* dest_addr, socklen_t addrlen); -ssize_t iox_recvfrom(int sockfd, void* buf, size_t len, int flags, struct sockaddr* src_addr, socklen_t* addrlen); +iox_ssize_t iox_recvfrom(int sockfd, void* buf, size_t len, int flags, struct sockaddr* src_addr, socklen_t* addrlen); int iox_connect(int sockfd, const struct sockaddr* addr, socklen_t addrlen); int iox_closesocket(int sockfd); diff --git a/iceoryx_platform/win/include/iceoryx_platform/types.hpp b/iceoryx_platform/win/include/iceoryx_platform/types.hpp index 4cd6937c6a..968cb9d7d2 100644 --- a/iceoryx_platform/win/include/iceoryx_platform/types.hpp +++ b/iceoryx_platform/win/include/iceoryx_platform/types.hpp @@ -23,8 +23,10 @@ using iox_gid_t = int; using iox_uid_t = int; #if defined(_MSC_VER) using mode_t = int; -using ssize_t = size_t; +using iox_ssize_t = int; using pid_t = int; +#elif defined(__MINGW32__) || defined(__MINGW64__) +using iox_ssize_t = ssize_t; #endif using nlink_t = int; using blksize_t = int; 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/include/iceoryx_platform/unistd.hpp b/iceoryx_platform/win/include/iceoryx_platform/unistd.hpp index c4719fd4cf..9fbe0be81a 100644 --- a/iceoryx_platform/win/include/iceoryx_platform/unistd.hpp +++ b/iceoryx_platform/win/include/iceoryx_platform/unistd.hpp @@ -35,7 +35,6 @@ #endif using iox_off_t = long; -using iox_ssize_t = int; #define IOX_F_OK 0 #define IOX_X_OK 1 @@ -55,4 +54,5 @@ iox_ssize_t iox_write(int fd, const void* buf, size_t count); iox_gid_t iox_getgid(void); iox_uid_t iox_geteuid(void); + #endif // IOX_HOOFS_WIN_PLATFORM_UNISTD_HPP diff --git a/iceoryx_platform/win/source/socket.cpp b/iceoryx_platform/win/source/socket.cpp index c0e360d31e..1e07e3ec4e 100644 --- a/iceoryx_platform/win/source/socket.cpp +++ b/iceoryx_platform/win/source/socket.cpp @@ -16,6 +16,7 @@ #include "iceoryx_platform/socket.hpp" #include "iceoryx_platform/logging.hpp" +#include "iceoryx_platform/types.hpp" #include int iox_bind(int sockfd, const struct sockaddr* addr, socklen_t addrlen) @@ -36,14 +37,14 @@ int iox_setsockopt(int sockfd, int level, int optname, const void* optval, sockl return 0; } -ssize_t +iox_ssize_t iox_sendto(int sockfd, const void* buf, size_t len, int flags, const struct sockaddr* dest_addr, socklen_t addrlen) { IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "'iox_sendto' is not implemented in windows!"); return 0; } -ssize_t iox_recvfrom(int sockfd, void* buf, size_t len, int flags, struct sockaddr* src_addr, socklen_t* addrlen) +iox_ssize_t iox_recvfrom(int sockfd, void* buf, size_t len, int flags, struct sockaddr* src_addr, socklen_t* addrlen) { IOX_PLATFORM_LOG(IOX_PLATFORM_LOG_LEVEL_ERROR, "'iox_recvfrom' is not implemented in windows!"); return 0; 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_platform/win/source/unistd.cpp b/iceoryx_platform/win/source/unistd.cpp index 534801fe63..8ac61fdf65 100644 --- a/iceoryx_platform/win/source/unistd.cpp +++ b/iceoryx_platform/win/source/unistd.cpp @@ -20,6 +20,7 @@ #include "iceoryx_platform/mman.hpp" #include "iceoryx_platform/win32_errorHandling.hpp" + int iox_ftruncate(int fildes, off_t length) { internal_iox_shm_set_size(fildes, length); diff --git a/iceoryx_posh/cmake/cpptoml/CMakeLists.txt b/iceoryx_posh/cmake/cpptoml/CMakeLists.txt index 42e79d98fb..e770e4fdba 100644 --- a/iceoryx_posh/cmake/cpptoml/CMakeLists.txt +++ b/iceoryx_posh/cmake/cpptoml/CMakeLists.txt @@ -59,7 +59,9 @@ file(MAKE_DIRECTORY ${BUILD_DIR}) set(CMAKE_ADDITIONAL_OPTIONS "-DCMAKE_C_FLAGS_INIT=${CMAKE_C_FLAGS_INIT}" + "-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}" "-DCMAKE_CXX_FLAGS_INIT=${CMAKE_CXX_FLAGS_INIT}" + "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}" "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}" "-DCMAKE_C_COMPILER_TARGET=${CMAKE_C_COMPILER_TARGET}" "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" diff --git a/iceoryx_posh/experimental/source/node.cpp b/iceoryx_posh/experimental/source/node.cpp index 03d30fdc06..e9a9d56d2b 100644 --- a/iceoryx_posh/experimental/source/node.cpp +++ b/iceoryx_posh/experimental/source/node.cpp @@ -41,7 +41,8 @@ NodeBuilder&& NodeBuilder::domain_id_from_env() && noexcept iox::string<10> domain_id_string; domain_id_string.unsafe_raw_access([](auto* buffer, const auto info) { size_t actual_size_with_null{0}; - auto result = IOX_POSIX_CALL(iox_getenv_s)(&actual_size_with_null, buffer, info.total_size, "IOX_DOMAIN_ID") + auto result = IOX_POSIX_CALL(iox_getenv_s)( + &actual_size_with_null, buffer, static_cast(info.total_size), "IOX_DOMAIN_ID") .failureReturnValue(-1) .evaluate(); if (result.has_error() && result.error().errnum == ERANGE) 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/mempool_introspection.inl b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl index ce035ff5fd..b7a568b9f3 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/introspection/mempool_introspection.inl @@ -163,7 +163,7 @@ MemPoolIntrospection::copyMemPoolI dst.m_minFreeChunks = src.m_minFreeChunks; dst.m_numChunks = src.m_numChunks; dst.m_chunkSize = src.m_chunkSize; - dst.m_chunkPayloadSize = src.m_chunkSize - static_cast(sizeof(mepoo::ChunkHeader)); + dst.m_chunkPayloadSize = src.m_chunkSize - sizeof(mepoo::ChunkHeader); } } 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 1de775d888..e748d5d773 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp @@ -28,6 +28,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" @@ -268,8 +269,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/roudi/memory/default_roudi_memory.cpp b/iceoryx_posh/source/roudi/memory/default_roudi_memory.cpp index 386e47d077..6c87d3843c 100644 --- a/iceoryx_posh/source/roudi/memory/default_roudi_memory.cpp +++ b/iceoryx_posh/source/roudi/memory/default_roudi_memory.cpp @@ -48,19 +48,17 @@ DefaultRouDiMemory::DefaultRouDiMemory(const IceoryxConfig& config) noexcept mepoo::MePooConfig DefaultRouDiMemory::introspectionMemPoolConfig(const uint32_t chunkCount) const noexcept { - constexpr uint32_t ALIGNMENT{mepoo::MemPool::CHUNK_MEMORY_ALIGNMENT}; + constexpr size_t ALIGNMENT{mepoo::MemPool::CHUNK_MEMORY_ALIGNMENT}; mepoo::MePooConfig mempoolConfig; mempoolConfig.m_mempoolConfig.push_back( - {align(static_cast(sizeof(roudi::MemPoolIntrospectionInfoContainer)), ALIGNMENT), chunkCount}); + {align(sizeof(roudi::MemPoolIntrospectionInfoContainer), ALIGNMENT), chunkCount}); mempoolConfig.m_mempoolConfig.push_back( - {align(static_cast(sizeof(roudi::ProcessIntrospectionFieldTopic)), ALIGNMENT), chunkCount}); + {align(sizeof(roudi::ProcessIntrospectionFieldTopic), ALIGNMENT), chunkCount}); + mempoolConfig.m_mempoolConfig.push_back({align(sizeof(roudi::PortIntrospectionFieldTopic), ALIGNMENT), chunkCount}); mempoolConfig.m_mempoolConfig.push_back( - {align(static_cast(sizeof(roudi::PortIntrospectionFieldTopic)), ALIGNMENT), chunkCount}); + {align(sizeof(roudi::PortThroughputIntrospectionFieldTopic), ALIGNMENT), chunkCount}); mempoolConfig.m_mempoolConfig.push_back( - {align(static_cast(sizeof(roudi::PortThroughputIntrospectionFieldTopic)), ALIGNMENT), chunkCount}); - mempoolConfig.m_mempoolConfig.push_back( - {align(static_cast(sizeof(roudi::SubscriberPortChangingIntrospectionFieldTopic)), ALIGNMENT), - chunkCount}); + {align(sizeof(roudi::SubscriberPortChangingIntrospectionFieldTopic), ALIGNMENT), chunkCount}); mempoolConfig.optimize(); return mempoolConfig; @@ -68,10 +66,9 @@ mepoo::MePooConfig DefaultRouDiMemory::introspectionMemPoolConfig(const uint32_t mepoo::MePooConfig DefaultRouDiMemory::discoveryMemPoolConfig(const uint32_t chunkCount) const noexcept { - constexpr uint32_t ALIGNMENT{mepoo::MemPool::CHUNK_MEMORY_ALIGNMENT}; + constexpr size_t ALIGNMENT{mepoo::MemPool::CHUNK_MEMORY_ALIGNMENT}; mepoo::MePooConfig mempoolConfig; - mempoolConfig.m_mempoolConfig.push_back( - {align(static_cast(sizeof(roudi::ServiceRegistry)), ALIGNMENT), chunkCount}); + mempoolConfig.m_mempoolConfig.push_back({align(sizeof(roudi::ServiceRegistry), ALIGNMENT), chunkCount}); mempoolConfig.optimize(); return mempoolConfig; diff --git a/iceoryx_posh/source/roudi/roudi.cpp b/iceoryx_posh/source/roudi/roudi.cpp index 9a25c9da52..d0b9134737 100644 --- a/iceoryx_posh/source/roudi/roudi.cpp +++ b/iceoryx_posh/source/roudi/roudi.cpp @@ -52,7 +52,7 @@ RouDi::RouDi(RouDiMemoryInterface& roudiMemoryInterface, { if (detail::isCompiledOn32BitSystem()) { - IOX_LOG(WARN, "Runnning RouDi on 32-bit architectures is not supported! Use at your own risk!"); + IOX_LOG(WARN, "Runnning RouDi on 32-bit architectures is experimental! Use at your own risk!"); } m_processIntrospection.registerPublisherPort( PublisherPortUserType(m_prcMgr->addIntrospectionPublisherPort(IntrospectionProcessService))); diff --git a/iceoryx_posh/source/runtime/ipc_runtime_interface.cpp b/iceoryx_posh/source/runtime/ipc_runtime_interface.cpp index 27e69fe747..d7becf2673 100644 --- a/iceoryx_posh/source/runtime/ipc_runtime_interface.cpp +++ b/iceoryx_posh/source/runtime/ipc_runtime_interface.cpp @@ -261,13 +261,13 @@ IpcRuntimeInterface::waitForRegAck(int64_t transmissionTimestamp, auto topic_size_result = iox::convert::from_string(receiveBuffer.getElementAtIndex(1U).c_str()); auto segment_manager_offset_result = - iox::convert::from_string(receiveBuffer.getElementAtIndex(2U).c_str()); + iox::convert::from_string(receiveBuffer.getElementAtIndex(2U).c_str()); auto recv_timestamp_result = iox::convert::from_string(receiveBuffer.getElementAtIndex(3U).c_str()); auto segment_id_result = iox::convert::from_string(receiveBuffer.getElementAtIndex(4U).c_str()); auto heartbeat_offset_result = - iox::convert::from_string(receiveBuffer.getElementAtIndex(5U).c_str()); + iox::convert::from_string(receiveBuffer.getElementAtIndex(5U).c_str()); // validate conversion results if (!topic_size_result.has_value() || !segment_manager_offset_result.has_value() diff --git a/iceoryx_posh/source/runtime/posh_runtime.cpp b/iceoryx_posh/source/runtime/posh_runtime.cpp index 877b92bd0a..90970f7778 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; } @@ -123,7 +123,7 @@ PoshRuntime::PoshRuntime(optional name) noexcept { if (detail::isCompiledOn32BitSystem()) { - IOX_LOG(WARN, "Running applications on 32-bit architectures is not supported! Use at your own risk!"); + IOX_LOG(WARN, "Running applications on 32-bit architectures is experimental! Use at your own risk!"); } } 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_posh_experimental_node.cpp b/iceoryx_posh/test/integrationtests/test_posh_experimental_node.cpp index 3db5b4d0b2..df4fad3873 100644 --- a/iceoryx_posh/test/integrationtests/test_posh_experimental_node.cpp +++ b/iceoryx_posh/test/integrationtests/test_posh_experimental_node.cpp @@ -18,6 +18,7 @@ #include "iceoryx_platform/stdlib.hpp" #include "iox/deadline_timer.hpp" +#include "iox/detail/system_configuration.hpp" #include "iox/duration.hpp" #include "iox/vector.hpp" @@ -256,6 +257,12 @@ TEST(Node_test, ExhaustingNodesLeadsToError) "number of file descriptors is not increased with 'ulimit -n 2000'!"; } + if (iox::detail::isCompiledOn32BitSystem()) + { + GTEST_SKIP() << "@todo iox-#2301 This test fails on 32 bit builds on the CI after ~240 created Nodes. " + "Potentially some issues with the amount of file descriptors."; + } + RouDiEnv roudi; iox::vector nodes; diff --git a/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp b/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp index 4c528934bb..07428bfdf8 100644 --- a/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp +++ b/iceoryx_posh/test/integrationtests/test_posh_mepoo.cpp @@ -254,7 +254,7 @@ class Mepoo_IntegrationTest : public Test { if (info.m_chunkSize != 0) { - info.m_chunkSize = info.m_chunkSize - static_cast(sizeof(iox::mepoo::ChunkHeader)); + info.m_chunkSize = info.m_chunkSize - sizeof(iox::mepoo::ChunkHeader); } } }); 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/mocks/roudi_memory_provider_mock.hpp b/iceoryx_posh/test/mocks/roudi_memory_provider_mock.hpp index cc4caea58e..6a1d0db39b 100644 --- a/iceoryx_posh/test/mocks/roudi_memory_provider_mock.hpp +++ b/iceoryx_posh/test/mocks/roudi_memory_provider_mock.hpp @@ -46,7 +46,7 @@ class MemoryProviderTestImpl : public iox::roudi::MemoryProvider createMemoryMock(size, alignment); } - dummyMemory = iox::alignedAlloc(alignment, size); + dummyMemory = iox::alignedAlloc(static_cast(alignment), static_cast(size)); return iox::ok(dummyMemory); } MOCK_METHOD(void, createMemoryMock, (uint64_t, uint64_t), (noexcept)); diff --git a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp index 0152bd535b..d0422bf7e9 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_chunk_header.cpp @@ -456,7 +456,7 @@ void checkUserPayloadNotOverlappingWithUserHeader(const ChunkHeader& sut, const const uint64_t chunkStartAddress{reinterpret_cast(&sut)}; const uint64_t userPayloadStartAddress{reinterpret_cast(sut.userPayload())}; const uint64_t userHeaderSizeAndPadding{ - iox::algorithm::maxVal(userHeaderSize, static_cast(alignof(UserPayloadOffset_t)))}; + iox::algorithm::maxVal(static_cast(userHeaderSize), alignof(UserPayloadOffset_t))}; constexpr uint64_t BACK_OFFSET_SIZE{sizeof(UserPayloadOffset_t)}; const uint64_t expectedRequiredSpace{sizeof(ChunkHeader) + userHeaderSizeAndPadding + BACK_OFFSET_SIZE}; diff --git a/iceoryx_posh/test/moduletests/test_mepoo_chunk_settings.cpp b/iceoryx_posh/test/moduletests/test_mepoo_chunk_settings.cpp index 2a4ca2f4af..0d2cbb026e 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_chunk_settings.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_chunk_settings.cpp @@ -349,8 +349,8 @@ INSTANTIATE_TEST_SUITE_P(ChunkSettings_test, uint64_t expectedChunkSizeWithUserHeader(const PayloadParams& userPayload, uint32_t userHeaderSize) { - const uint32_t userHeaderSizeAndPaddingToBackOffset = - iox::algorithm::maxVal(userHeaderSize, static_cast(alignof(UserPayloadOffset_t))); + const auto userHeaderSizeAndPaddingToBackOffset = + iox::algorithm::maxVal(static_cast(userHeaderSize), alignof(UserPayloadOffset_t)); if (userPayload.alignment <= alignof(UserPayloadOffset_t)) { diff --git a/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp b/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp index 53749a4469..80b1cd207f 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_mempool.cpp @@ -20,6 +20,7 @@ #include "iceoryx_posh/internal/posh_error_reporting.hpp" #include "iox/bump_allocator.hpp" #include "iox/detail/hoofs_error_reporting.hpp" +#include "iox/detail/system_configuration.hpp" #include "iceoryx_hoofs/testing/fatal_failure.hpp" #include "test.hpp" @@ -46,9 +47,6 @@ class MemPool_test : public Test { } - void SetUp(){}; - void TearDown(){}; - alignas(MemPool::CHUNK_MEMORY_ALIGNMENT) uint8_t m_rawMemory[NUMBER_OF_CHUNKS * CHUNK_SIZE + LOFFLI_MEMORY_REQUIREMENT]; iox::BumpAllocator allocator; @@ -138,14 +136,23 @@ TEST_F(MemPool_test, MempoolPointeToIndexConversionForMemoryOffsetsLargerThan4GB constexpr uint64_t GB{1ULL << 30}; constexpr uint64_t CHUNK_SIZE{128 * MB}; constexpr uint64_t RAW_MEMORY_BASE{0x7f60d90c5000ULL}; - uint8_t* const RAW_MEMORY_PTR{reinterpret_cast(RAW_MEMORY_BASE)}; - constexpr uint32_t EXPECTED_INDEX{42}; - uint8_t* const CHUNK_PTR{RAW_MEMORY_PTR + static_cast(EXPECTED_INDEX) * CHUNK_SIZE}; - const auto index = MemPool::pointerToIndex(CHUNK_PTR, CHUNK_SIZE, RAW_MEMORY_PTR); + if constexpr (iox::detail::isCompiledOn32BitSystem()) + { + GTEST_SKIP() << "This test does not work on 32 bit builds since it requires pointer larger than the 32 bit " + "address space"; + } + else + { + uint8_t* const RAW_MEMORY_PTR{reinterpret_cast(RAW_MEMORY_BASE)}; + constexpr uint32_t EXPECTED_INDEX{42}; + uint8_t* const CHUNK_PTR{RAW_MEMORY_PTR + static_cast(EXPECTED_INDEX) * CHUNK_SIZE}; - EXPECT_THAT(index, Eq(EXPECTED_INDEX)); - EXPECT_THAT(reinterpret_cast(CHUNK_PTR) - RAW_MEMORY_BASE, Gt(5 * GB)); + const auto index = MemPool::pointerToIndex(CHUNK_PTR, CHUNK_SIZE, RAW_MEMORY_PTR); + + EXPECT_THAT(index, Eq(EXPECTED_INDEX)); + EXPECT_THAT(reinterpret_cast(CHUNK_PTR) - RAW_MEMORY_BASE, Gt(5 * GB)); + } } TEST_F(MemPool_test, MempoolCtorInitialisesTheObjectWithValuesPassedToTheCtor) diff --git a/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp b/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp index 12406772fb..03e87ff121 100644 --- a/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp +++ b/iceoryx_posh/test/moduletests/test_mepoo_segment.cpp @@ -90,7 +90,7 @@ class MePooSegment_test : public Test uint64_t m_memorySizeInBytes{0}; void* m_baseAddressHint{nullptr}; static constexpr int MEM_SIZE = 100000; - char memory[MEM_SIZE]; + alignas(8) char memory[MEM_SIZE]; shm_handle_t filehandle; static createFct createVerificator; }; diff --git a/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp b/iceoryx_posh/test/moduletests/test_popo_chunk_distributor.cpp index 1fea4c17b7..dd073ca655 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)); @@ -797,7 +798,7 @@ TYPED_TEST(ChunkDistributor_test, MultipleBlockingQueuesWillBeFilledWhenThereBec std::this_thread::sleep_for(this->BLOCKING_DURATION); EXPECT_THAT(wasChunkDelivered.load(), Eq(false)); - for (uint64_t i = 0U; i < NUMBER_OF_QUEUES; ++i) + for (size_t i = 0U; i < NUMBER_OF_QUEUES; ++i) { auto maybeSharedChunk = queues[i].tryPop(); ASSERT_THAT(maybeSharedChunk.has_value(), Eq(true)); 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..92c01b5016 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); - for (uint64_t i = 1U; i < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_source.load() == &events[0U]); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_count.load() == 2U); + for (size_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); - for (uint64_t i = 1U; i < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_source.load() == &events[0U]); + TIMING_TEST_EXPECT_TRUE(g_triggerCallbackArg[0].m_count.load() == 3U); + for (size_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), [&] { @@ -984,16 +984,16 @@ TIMING_TEST_F(Listener_test, AttachingMultipleWhileCallbackIsRunningWorks, Repea AttachEvent::doIt(*m_sut, events, SimpleEvent::StoepselBachelorParty); g_triggerCallbackRuntimeInMs = 0U; - for (uint64_t i = 0U; i + 1U < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) + for (size_t i = 0U; i + 1U < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) { events[i].triggerStoepsel(); } std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS / 2U)); - for (uint64_t i = 0U; i + 1U < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) + for (size_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), [&] { @@ -1089,9 +1089,9 @@ TIMING_TEST_F(Listener_test, DetachingMultipleWhileCallbackIsRunningWorks, Repea } std::this_thread::sleep_for(std::chrono::milliseconds(CALLBACK_WAIT_IN_MS)); - for (uint64_t i = 0U; i < iox::MAX_NUMBER_OF_EVENTS_PER_LISTENER; ++i) + for (size_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..28e787b2bb 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); @@ -136,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)); 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); diff --git a/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/chunk_mock.hpp b/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/chunk_mock.hpp index 3a8a58f4fc..4240e9d7c0 100644 --- a/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/chunk_mock.hpp +++ b/iceoryx_posh/testing/include/iceoryx_posh/testing/mocks/chunk_mock.hpp @@ -48,9 +48,10 @@ class ChunkMock auto& chunkSettings = chunkSettingsResult.value(); auto chunkSize = chunkSettings.requiredChunkSize(); - m_rawMemory = static_cast(iox::alignedAlloc(alignof(iox::mepoo::ChunkHeader), chunkSize)); + m_rawMemory = + static_cast(iox::alignedAlloc(alignof(iox::mepoo::ChunkHeader), static_cast(chunkSize))); assert(m_rawMemory != nullptr && "Could not get aligned memory"); - memset(m_rawMemory, 0xFF, chunkSize); + memset(m_rawMemory, 0xFF, static_cast(chunkSize)); m_chunkHeader = new (m_rawMemory) iox::mepoo::ChunkHeader(chunkSize, chunkSettings); diff --git a/tools/ci/build-test-ubuntu.sh b/tools/ci/build-test-ubuntu.sh index 443ce3dc4c..20a4ffd595 100755 --- a/tools/ci/build-test-ubuntu.sh +++ b/tools/ci/build-test-ubuntu.sh @@ -19,6 +19,19 @@ set -e +COMPILER=gcc +SANITIZER=asan +BUILD_32BIT="" + +while (( "$#" )); do + case "$1" in + "32-bit-x86") + BUILD_32BIT="32-bit-x86" + shift 1 + ;; + esac +done + msg() { printf "\033[1;32m%s: %s\033[0m\n" ${FUNCNAME[1]} "$1" } @@ -26,9 +39,6 @@ msg() { WORKSPACE=$(git rev-parse --show-toplevel) cd ${WORKSPACE} -msg "installing build dependencies" -sudo apt-get update && sudo apt-get install -y libacl1-dev libncurses5-dev - msg "creating local test users and groups for testing access control" sudo ./tools/scripts/add_test_users.sh @@ -37,10 +47,10 @@ $(gcc --version) $(clang --version)" msg "building sources" -./tools/iceoryx_build_test.sh build-strict build-all out-of-tree build-shared test-add-user +./tools/iceoryx_build_test.sh build-strict build-all out-of-tree build-shared test-add-user ${BUILD_32BIT} msg "building debian package" -./tools/iceoryx_build_test.sh package +./tools/iceoryx_build_test.sh package ${BUILD_32BIT} # there are tests which open quite a lot of file descriptors simultaneously to exhaust the creation of some resources # therefore the limits needs to be increased @@ -53,4 +63,4 @@ cd ./build cd - msg "building roudi examples without toml support" -./tools/iceoryx_build_test.sh relwithdebinfo out-of-tree examples toml-config-off clean +./tools/iceoryx_build_test.sh relwithdebinfo out-of-tree examples toml-config-off clean ${BUILD_32BIT} 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/iceoryx_build_test.sh b/tools/iceoryx_build_test.sh index 6ca6f8e260..b0e4ad278c 100755 --- a/tools/iceoryx_build_test.sh +++ b/tools/iceoryx_build_test.sh @@ -56,6 +56,7 @@ BUILD_SHARED="OFF" TOML_FLAG="ON" COMPONENTS="iceoryx_platform iceoryx_hoofs iceoryx_posh iceoryx_introspection iceoryx_binding_c iceoryx_component" TOOLCHAIN_FILE="" +CMAKE_C_FLAGS="" CMAKE_CXX_FLAGS="" while (( "$#" )); do @@ -206,7 +207,7 @@ while (( "$#" )); do ;; "libcxx") echo " [i] Build with libc++ library" - CMAKE_CXX_FLAGS="-stdlib=libc++" + CMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -stdlib=libc++" shift 1 ;; "doc") @@ -214,6 +215,19 @@ while (( "$#" )); do BUILD_DOC="ON" shift 1 ;; + "32-bit-x86") + echo " [i] Build as 32 bit x86 library" + CMAKE_C_FLAGS="${CMAKE_C_FLAGS} -m32 -malign-double" + CMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -m32 -malign-double" + shift 1 + ;; + "32-bit-arm") + echo " [i] Build as 32 bit ARM library" + # NOTE: there is no '-m32' flag on ARM; the architecture is selected via the externally defined toolchain + CMAKE_C_FLAGS="${CMAKE_C_FLAGS} -malign-double" + CMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -malign-double" + shift 1 + ;; "help") echo "Build script for iceoryx." echo "By default, iceoryx with C-Binding and TOML-config is built." @@ -250,6 +264,8 @@ while (( "$#" )); do echo " test-add-user Create additional useraccounts in system for testing access control (default off)" echo " toml-config-off Build without TOML File support" echo " roudi-env Build the roudi environment" + echo " 32-bit-x86 Build as 32 bit library for x64" + echo " 32-bit-arm Build as 32 bit library for arm" echo "" echo "e.g. iceoryx_build_test.sh -b ./build-scripted clean test" echo "for gcov report: iceoryx_build_test.sh clean -c unit" @@ -324,7 +340,8 @@ if [ "$NO_BUILD" == false ]; then -DTHREAD_SANITIZER=$THREAD_SANITIZER_FLAG \ -DTEST_WITH_ADDITIONAL_USER=$TEST_ADD_USER $TOOLCHAIN_FILE \ -DTEST_WITH_HUGE_PAYLOAD=$TEST_HUGE_PAYLOAD \ - -DCMAKE_CXX_FLAGS=$CMAKE_CXX_FLAGS \ + -DCMAKE_C_FLAGS="$CMAKE_C_FLAGS" \ + -DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS" \ "$WORKSPACE"/iceoryx_meta cmake --build . --target install -- -j$NUM_JOBS @@ -365,6 +382,8 @@ if [ "$OUT_OF_TREE_FLAG" == "ON" ]; then cmake -DCMAKE_INSTALL_PREFIX="$ICEORYX_INSTALL_PREFIX" \ -DTOML_CONFIG=$TOML_FLAG \ -DBINDING_C=$BINDING_C_FLAG \ + -DCMAKE_C_FLAGS="$CMAKE_C_FLAGS" \ + -DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS" \ "$WORKSPACE"/iceoryx_examples/"$ex" if ! cmake --build . --target install -- -j$NUM_JOBS; then echo "Out of tree build failed" diff --git a/tools/introspection/source/introspection_app.cpp b/tools/introspection/source/introspection_app.cpp index d938298005..9fe006599d 100644 --- a/tools/introspection/source/introspection_app.cpp +++ b/tools/introspection/source/introspection_app.cpp @@ -280,6 +280,22 @@ void IntrospectionApp::printProcessIntrospectionData(const ProcessIntrospectionF wprintw(pad, "\n"); } +template +constexpr const char* format_uint64_t() noexcept; +template <> +constexpr const char* format_uint64_t() noexcept +{ + return "%*lu%s"; +} +template <> +constexpr const char* format_uint64_t() noexcept +{ + return "%*llu%s"; +} + +template +static constexpr const char* FORMAT_UINT64_T{format_uint64_t()}; + void IntrospectionApp::printMemPoolInfo(const MemPoolIntrospectionInfo& introspectionInfo) { wprintw(pad, "Segment ID: %d\n", introspectionInfo.m_id); @@ -312,12 +328,12 @@ void IntrospectionApp::printMemPoolInfo(const MemPoolIntrospectionInfo& introspe auto& info = introspectionInfo.m_mempoolInfo[i]; if (info.m_numChunks > 0u) { - wprintw(pad, "%*zd |", memPoolWidth, i + 1u); - wprintw(pad, "%*d |", usedchunksWidth, info.m_usedChunks); - wprintw(pad, "%*d |", numchunksWidth, info.m_numChunks); - wprintw(pad, "%*d |", minFreechunksWidth, info.m_minFreeChunks); - wprintw(pad, "%*ld |", chunkSizeWidth, info.m_chunkSize); - wprintw(pad, "%*ld\n", chunkPayloadSizeWidth, info.m_chunkPayloadSize); + wprintw(pad, "%*zu |", memPoolWidth, i + 1u); + wprintw(pad, "%*u |", usedchunksWidth, info.m_usedChunks); + wprintw(pad, "%*u |", numchunksWidth, info.m_numChunks); + wprintw(pad, "%*u |", minFreechunksWidth, info.m_minFreeChunks); + wprintw(pad, FORMAT_UINT64_T, chunkSizeWidth, info.m_chunkSize, " |"); + wprintw(pad, FORMAT_UINT64_T, chunkPayloadSizeWidth, info.m_chunkPayloadSize, "\n"); } } wprintw(pad, "\n"); @@ -576,7 +592,8 @@ IntrospectionApp::composePublisherPortData(const PortIntrospectionFieldTopic* po const PortThroughputIntrospectionFieldTopic* throughputData) { std::vector publisherPortData; - publisherPortData.reserve(portData->m_publisherList.size()); + auto listSize = portData->m_publisherList.size(); + publisherPortData.reserve(static_cast(listSize)); const PortThroughputData dummyThroughputData; @@ -625,7 +642,8 @@ std::vector IntrospectionApp::composeSubscriberPortD const SubscriberPortChangingIntrospectionFieldTopic* subscriberPortChangingData) { std::vector subscriberPortData; - subscriberPortData.reserve(portData->m_subscriberList.size()); + auto listSize = portData->m_subscriberList.size(); + subscriberPortData.reserve(static_cast(listSize)); uint32_t i = 0U; if (portData->m_subscriberList.size() == subscriberPortChangingData->subscriberPortChangingDataList.size()) 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}" diff --git a/tools/scripts/ice_env.sh b/tools/scripts/ice_env.sh index a91cd98c82..62f8fa55d3 100755 --- a/tools/scripts/ice_env.sh +++ b/tools/scripts/ice_env.sh @@ -17,7 +17,7 @@ # SPDX-License-Identifier: Apache-2.0 CONTAINER_NAME_PREFIX="ice_env_" -CONTAINER_MEMORY_SIZE="6g" +CONTAINER_MEMORY_SIZE="8g" CONTAINER_SHM_MEMORY_SIZE="2g" DEFAULT_OS_VERSION="ubuntu:22.04" CMAKE_VERSION="cmake-3.23.1-linux-x86_64" @@ -48,8 +48,10 @@ setup_docker_image() { # ubuntu/debian and derivatives if command -v apt &>/dev/null; then + dpkg --add-architecture i386 apt update apt -y install g++ gcc sudo cmake git fish gdb lldb llvm clang clang-format wget libncurses5-dev libacl1-dev wget lsb-release software-properties-common vim + apt -y install libacl1-dev:i386 libc6-dev-i386 libc6-dev-i386-cross libstdc++6-i386-cross gcc-multilib g++-multilib install_cmake # install newest clang @@ -67,7 +69,10 @@ setup_docker_image() { # archlinux based ones elif command -v pacman &>/dev/null; then + echo "[multilib]" >> /etc/pacman.conf + echo "Include = /etc/pacman.d/mirrorlist" >> /etc/pacman.conf pacman -Syu --noconfirm base base-devel clang cmake git fish gdb lldb llvm wget ncurses vim + pacman -Syu --noconfirm lib32-acl lib32-gcc-libs lib32-ncurses install_cmake else echo Please install the following packages to have a working iceoryx environment: