Skip to content

Commit

Permalink
Merge pull request eclipse-iceoryx#2143 from elBoberido/iox-1391-move…
Browse files Browse the repository at this point in the history
…-hoofs-header-from-legacy-path-to-module-path-part-8

iox-eclipse-iceoryx#1391 Move remaining concurrent classes to new location
  • Loading branch information
elBoberido authored Jan 2, 2024
2 parents 26bd1f4 + e003168 commit 8c32765
Show file tree
Hide file tree
Showing 26 changed files with 143 additions and 96 deletions.
2 changes: 0 additions & 2 deletions .clang-tidy-diff-scans.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
./iceoryx_hoofs/memory/**/*
./iceoryx_hoofs/test/moduletests/test_memory_*

./iceoryx_hoofs/include/iceoryx_hoofs/internal/concurrent/*

./iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/mocks/logger_mock.hpp
./iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/fatal_failure*
./iceoryx_hoofs/testing/include/iceoryx_hoofs/testing/testing_logger.hpp
Expand Down
1 change: 1 addition & 0 deletions iceoryx_hoofs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ cc_library(
"buffer/include/",
"cli/include/",
"concurrent/buffer/include/",
"concurrent/sync/include/",
"container/include/",
"design/include",
"filesystem/include",
Expand Down
2 changes: 2 additions & 0 deletions iceoryx_hoofs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ iox_add_library(
${PROJECT_SOURCE_DIR}/buffer/include
${PROJECT_SOURCE_DIR}/cli/include
${PROJECT_SOURCE_DIR}/concurrent/buffer/include
${PROJECT_SOURCE_DIR}/concurrent/sync/include
${PROJECT_SOURCE_DIR}/container/include
${PROJECT_SOURCE_DIR}/design/include
${PROJECT_SOURCE_DIR}/filesystem/include
Expand Down Expand Up @@ -81,6 +82,7 @@ iox_add_library(
buffer/include/
cli/include/
concurrent/buffer/include/
concurrent/sync/include/
container/include/
design/include/
filesystem/include/
Expand Down
8 changes: 4 additions & 4 deletions iceoryx_hoofs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ The module structure is a logical grouping. It is replicated for `concurrent` an
|`MpmcLockfreeQueue` | | Multi producer, multi consumer lock-free FiFo with ringbuffer like overflow handling |
|`MpmcLoFFLi` | i | Lock-free LIFO based index manager (lock-free free list). One building block of our memory manager. After construction it contains the indices {0 ... n} which you can acquire and release. |
|`SpscSofi` | i | Single producer, single consumer lock-free safely overflowing FiFo (SpscSofi). |
|`MpmcResizeableLockFreeQueue` | | Resizeable variant of the `LockfreeQueue` |
|`MpmcResizeableLockFreeQueue` | | Resizeable variant of the `MpmcLockfreeQueue` |
|`stack` | | Stack implementation with simple push/pop interface. |
|`VariantQueue` | | A queue which wraps multiple variants of Queues (SpscFifo, SpscSofi, ResizeableLockFreeQueue) - will be moved to `iceoryx_posh` - |
|`VariantQueue` | | A queue which wraps multiple variants of Queues (SpscFifo, SpscSofi, MpmcResizeableLockFreeQueue) - will be moved to `iceoryx_posh` - |

#### Attribute overview of the available buffers

Expand All @@ -115,7 +115,7 @@ The module structure is a logical grouping. It is replicated for `concurrent` an
|`MpmcLockfreeQueue` | Yes | Yes | Yes | n:m | Yes | Copyable or Movable | lock-free transfer of arbitrary data between multiple contexts in FIFO order with overflow handling (ringbuffer) |
|`MpmcLoFFLi` | Yes | Yes | Yes | n:m | Yes | int32 | manage memory access, LIFO order |
|`SpscSofi` | Yes | Yes | Yes | 1:1 | Yes | Trivially Copyable | lock-free transfer of small data (e.g. pointers) between two contexts in FIFO order with overflow handling (ringbuffer) |
|`MpmcResizeableLockFreeQueue`| Yes | Yes | Yes | n:m | Yes | Copyable or Movable | Resizeable variant of the `LockfreeQueue` |
|`MpmcResizeableLockFreeQueue`| Yes | Yes | Yes | n:m | Yes | Copyable or Movable | Resizeable variant of the `MpmcLockfreeQueue` |
|`stack` | Yes | No | - | - | Yes | None | Stack for a single-threaded application |

### Inter-process communication (ipc)
Expand All @@ -134,7 +134,7 @@ The module structure is a logical grouping. It is replicated for `concurrent` an
| class | internal | description |
|:---------------------:|:--------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|`PeriodicTask` | i | Periodically executes a callable specified by the template parameter in a configurable time interval. |
|`smart_lock` | i | Creates arbitrary thread-safe constructs which then can be used like smart pointers. If some STL type should be thread safe use the smart_lock to create the thread safe version in one line. Based on some ideas presented in [Wrapping C++ Member Function Calls](https://stroustrup.com/wrapper.pdf) |
|`smart_lock` | | Creates arbitrary thread-safe constructs which then can be used like smart pointers. If some STL type should be thread safe use the smart_lock to create the thread safe version in one line. Based on some ideas presented in [Wrapping C++ Member Function Calls](https://stroustrup.com/wrapper.pdf) |
|`mutex` | i | Mutex interface, see [ManPage pthread_mutex_lock](https://man7.org/linux/man-pages/man3/pthread_mutex_lock.3p.html). |
|`UnnamedSemaphore` | | Unamed semaphore interface, see [ManPage sem_overview](https://man7.org/linux/man-pages/man7/sem_overview.7.html) |
|`NamedSemaphore` | | Named semaphore interface, see [ManPage sem_overview](https://man7.org/linux/man-pages/man7/sem_overview.7.html) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_HOOFS_CONCURRENT_PERIODIC_TASK_HPP
#define IOX_HOOFS_CONCURRENT_PERIODIC_TASK_HPP
#ifndef IOX_HOOFS_CONCURRENT_SYNC_PERIODIC_TASK_HPP
#define IOX_HOOFS_CONCURRENT_SYNC_PERIODIC_TASK_HPP

#include "iox/detail/deprecation_marker.hpp"
#include "iox/duration.hpp"
#include "iox/string.hpp"
#include "iox/thread.hpp"
Expand All @@ -30,6 +31,8 @@ namespace iox
{
namespace concurrent
{
namespace detail
{
/// @brief This is a helper struct to make the immediate start of the task in the PeriodicTask ctor obvious to the user
struct PeriodicTaskAutoStart_t
{
Expand All @@ -45,15 +48,15 @@ static constexpr PeriodicTaskManualStart_t PeriodicTaskManualStart;
/// @brief This class periodically executes a callable specified by the template parameter.
/// This can be a struct with a 'operator()()' overload, a 'iox::function_ref<void()>' or 'std::fuction<void()>'.
/// @code
/// #include <iceoryx_hoofs/internal/concurrent/periodic_task.hpp>
/// #include <iox/detail//periodic_task.hpp>
/// #include <iox/duration.hpp>
/// #include <iostream>
///
/// int main()
/// {
/// using namespace iox::units::duration_literals;
/// PeriodicTask<iox::function_ref<void()>> task{
/// PeriodicTaskAutoStart, 1_s, "MyTask", [] { IOX_LOG(INFO, "Hello World"; }});
/// iox::concurrent::detail::PeriodicTask<iox::function_ref<void()>> task{
/// iox::concurrent::detail::PeriodicTaskAutoStart, 1_s, "MyTask", [] { IOX_LOG(INFO, "Hello World"; }});
///
/// return 0;
/// }
Expand Down Expand Up @@ -116,6 +119,9 @@ class PeriodicTask

/// @brief This method check if a thread is spawned and running, potentially executing a task.
/// @return true if the thread is running, false otherwise.
bool is_active() const noexcept;

IOX_DEPRECATED_SINCE(3, "Please use 'is_active' instead.")
bool isActive() const noexcept;

private:
Expand All @@ -129,9 +135,10 @@ class PeriodicTask
std::thread m_taskExecutor;
};

} // namespace detail
} // namespace concurrent
} // namespace iox

#include "iceoryx_hoofs/internal/concurrent/periodic_task.inl"
#include "iox/detail/periodic_task.inl"

#endif // IOX_HOOFS_CONCURRENT_PERIODIC_TASK_HPP
#endif // IOX_HOOFS_CONCURRENT_SYNC_PERIODIC_TASK_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_HOOFS_CONCURRENT_PERIODIC_TASK_INL
#define IOX_HOOFS_CONCURRENT_PERIODIC_TASK_INL
#ifndef IOX_HOOFS_CONCURRENT_SYNC_PERIODIC_TASK_INL
#define IOX_HOOFS_CONCURRENT_SYNC_PERIODIC_TASK_INL

#include "iceoryx_hoofs/internal/concurrent/periodic_task.hpp"
#include "iox/detail/periodic_task.hpp"

namespace iox
{
namespace concurrent
{
namespace detail
{
template <typename T>
template <typename... Args>
// NOLINTNEXTLINE(hicpp-named-parameter, readability-named-parameter) justification in header
Expand Down Expand Up @@ -74,11 +76,17 @@ inline void PeriodicTask<T>::stop() noexcept
}

template <typename T>
inline bool PeriodicTask<T>::isActive() const noexcept
inline bool PeriodicTask<T>::is_active() const noexcept
{
return m_taskExecutor.joinable();
}

template <typename T>
inline bool PeriodicTask<T>::isActive() const noexcept
{
return is_active();
}

template <typename T>
inline void PeriodicTask<T>::run() noexcept
{
Expand All @@ -96,6 +104,7 @@ inline void PeriodicTask<T>::run() noexcept
} while (waitState == SemaphoreWaitState::TIMEOUT);
}

} // namespace detail
} // namespace concurrent
} // namespace iox

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_CONCURRENT_SMART_LOCK_INL
#define IOX_HOOFS_CONCURRENT_SMART_LOCK_INL

#include "iceoryx_hoofs/internal/concurrent/smart_lock.hpp"
#ifndef IOX_HOOFS_CONCURRENT_SYNC_SMART_LOCK_INL
#define IOX_HOOFS_CONCURRENT_SYNC_SMART_LOCK_INL

#include "iox/smart_lock.hpp"

namespace iox
{
Expand Down Expand Up @@ -98,27 +99,47 @@ inline const typename smart_lock<T, MutexType>::Proxy smart_lock<T, MutexType>::
}

template <typename T, typename MutexType>
inline typename smart_lock<T, MutexType>::Proxy smart_lock<T, MutexType>::getScopeGuard() noexcept
inline typename smart_lock<T, MutexType>::Proxy smart_lock<T, MutexType>::get_scope_guard() noexcept
{
return Proxy(base, lock);
}

template <typename T, typename MutexType>
// const return type improves const correctness, operator-> can be chained with underlying operator->
// NOLINTNEXTLINE(readability-const-return-type)
inline const typename smart_lock<T, MutexType>::Proxy smart_lock<T, MutexType>::getScopeGuard() const noexcept
inline const typename smart_lock<T, MutexType>::Proxy smart_lock<T, MutexType>::get_scope_guard() const noexcept
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) const_cast to avoid code duplication
return const_cast<smart_lock<T, MutexType>*>(this)->getScopeGuard();
return const_cast<smart_lock<T, MutexType>*>(this)->get_scope_guard();
}

template <typename T, typename MutexType>
inline T smart_lock<T, MutexType>::getCopy() const noexcept
inline typename smart_lock<T, MutexType>::Proxy smart_lock<T, MutexType>::getScopeGuard() noexcept
{
return get_scope_guard();
}

template <typename T, typename MutexType>
// const return type improves const correctness, operator-> can be chained with underlying operator->
// NOLINTNEXTLINE(readability-const-return-type)
inline const typename smart_lock<T, MutexType>::Proxy smart_lock<T, MutexType>::getScopeGuard() const noexcept
{
return get_scope_guard();
}

template <typename T, typename MutexType>
inline T smart_lock<T, MutexType>::get_copy() const noexcept
{
std::lock_guard<MutexType> guard(lock);
return base;
}

template <typename T, typename MutexType>
inline T smart_lock<T, MutexType>::getCopy() const noexcept
{
return get_copy();
}

// PROXY OBJECT

template <typename T, typename MutexType>
Expand Down Expand Up @@ -163,4 +184,4 @@ inline const T& smart_lock<T, MutexType>::Proxy::operator*() const noexcept
} // namespace concurrent
} // namespace iox

#endif // IOX_HOOFS_CONCURRENT_SMART_LOCK_INL
#endif // IOX_HOOFS_CONCURRENT_SYNC_SMART_LOCK_INL
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_CONCURRENT_SMART_LOCK_HPP
#define IOX_HOOFS_CONCURRENT_SMART_LOCK_HPP

#ifndef IOX_HOOFS_CONCURRENT_SYNC_SMART_LOCK_HPP
#define IOX_HOOFS_CONCURRENT_SYNC_SMART_LOCK_HPP

#include "iox/detail/deprecation_marker.hpp"
#include <mutex>

namespace iox
Expand Down Expand Up @@ -47,7 +49,7 @@ constexpr ForwardArgsToCTor_t ForwardArgsToCTor{};
/// size_t vectorSize = threadSafeVector->size();
///
/// {
/// auto guardedVector = threadSafeVector.getScopeGuard();
/// auto guardedVector = threadSafeVector.get_scope_guard();
/// auto iter = std::find(guardVector->begin(), guardVector->end(), 456);
/// if (iter != guardVector->end()) guardVector->erase(iter);
/// }
Expand Down Expand Up @@ -134,12 +136,15 @@ class smart_lock
/// // since it would lead to a deadlock.
/// // You access the underlying object by using the vectorGuard object!
/// {
/// auto vectorGuard = threadSafeVector.getScopeGuard();
/// auto vectorGuard = threadSafeVector.get_scope_guard();
/// auto iter = std::find(vectorGuard->begin(), vectorGuard->end(),
/// 123);
/// if ( iter != vectorGuard->end() )
/// vectorGuard->erase(iter);
/// }
Proxy get_scope_guard() noexcept;

IOX_DEPRECATED_SINCE(3, "Please use 'get_scope_guard' instead.")
Proxy getScopeGuard() noexcept;

/// @brief If you need to lock your object over multiple method calls you
Expand All @@ -157,15 +162,21 @@ class smart_lock
/// // since it would lead to a deadlock.
/// // You access the underlying object by using the vectorGuard object!
/// {
/// auto vectorGuard = threadSafeVector.getScopeGuard();
/// auto vectorGuard = threadSafeVector.get_scope_guard();
/// auto iter = std::find(vectorGuard->begin(), vectorGuard->end(),
/// 123);
/// if ( iter != vectorGuard->end() )
/// vectorGuard->erase(iter);
/// }
const Proxy get_scope_guard() const noexcept;

IOX_DEPRECATED_SINCE(3, "Please use 'get_scope_guard' instead.")
const Proxy getScopeGuard() const noexcept;

/// @brief Returns a copy of the underlying object
T get_copy() const noexcept;

IOX_DEPRECATED_SINCE(3, "Please use 'get_copy' instead.")
T getCopy() const noexcept;

private:
Expand All @@ -175,6 +186,6 @@ class smart_lock
} // namespace concurrent
} // namespace iox

#include "iceoryx_hoofs/internal/concurrent/smart_lock.inl"
#include "iox/detail/smart_lock.inl"

#endif // IOX_HOOFS_CONCURRENT_SMART_LOCK_HPP
#endif // IOX_HOOFS_CONCURRENT_SYNC_SMART_LOCK_HPP
Loading

0 comments on commit 8c32765

Please sign in to comment.