Skip to content

Commit fbdae45

Browse files
Merge pull request #1595 from ApexAI/iox-#1594-pass-cleanupcapacity-to-cxx-function
iox-#1594 Pass `CleanupCapacity` to underlying `cxx::function` in `ScopeGuard`
2 parents cdf6ef4 + bfaf16e commit fbdae45

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

doc/website/release-notes/iceoryx-unreleased.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
- Add "inline" keyword to smart_lock method implementation [\#1551](https://github.com/eclipse-iceoryx/iceoryx/issues/1551)
4646
- Fix RouDi crash due to uninitialized `ServiceRegistry` chunk [\#1575](https://github.com/eclipse-iceoryx/iceoryx/issues/1575)
4747
- Add check in `cxx::unique_ptr::get` to avoid `nullptr` dereferencing [\#1571](https://github.com/eclipse-iceoryx/iceoryx/issues/1571)
48+
- Pass `CleanupCapacity` to underlying `cxx::function` in `ScopeGuard` (formerly known as `cxx::GenericRAII`) [\#1594](https://github.com/eclipse-iceoryx/iceoryx/issues/1594)
4849

4950
**Refactoring:**
5051

iceoryx_hoofs/include/iceoryx_hoofs/cxx/scope_guard.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ namespace cxx
2828
/// idiom quickly. You set 2 functions, one which is called in the
2929
/// constructor and another function is called in the destructor
3030
/// which can be useful when handling resources.
31+
/// @tparam [in] CleanupCapacity The static storage capacity available to store a cleanup callable in bytes
3132
/// @code
3233
/// // This example leads to a console output of:
3334
/// // hello world
3435
/// // I am doing stuff
3536
/// // goodbye
3637
/// void someFunc() {
37-
/// auto raii{[](){ std::cout << "hello world\n"; },
38+
/// ScopeGuard myScopeGuard{[](){ std::cout << "hello world\n"; },
3839
/// [](){ std::cout << "goodbye\n"; }};
3940
/// std::cout << "I am doing stuff\n";
40-
/// // raii goes out of scope here and the cleanupFunction is called in the
41+
/// // myScopeGuard goes out of scope here and the cleanupFunction is called in the
4142
/// // destructor
4243
/// }
4344
/// @endcode
@@ -54,7 +55,7 @@ class ScopeGuardWithVariableCapacity
5455
/// @param[in] initFunction callable which will be called in the constructor
5556
/// @param[in] cleanupFunction callable which will be called in the destructor
5657
ScopeGuardWithVariableCapacity(const function_ref<void()>& initFunction,
57-
const function<void()>& cleanupFunction) noexcept;
58+
const function<void(), CleanupCapacity>& cleanupFunction) noexcept;
5859

5960
/// @brief calls m_cleanupFunction callable if it was set in the constructor
6061
~ScopeGuardWithVariableCapacity() noexcept;

iceoryx_hoofs/include/iceoryx_hoofs/internal/cxx/scope_guard.inl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,54 +24,54 @@ namespace iox
2424
{
2525
namespace cxx
2626
{
27-
template <uint64_t Capacity>
28-
inline ScopeGuardWithVariableCapacity<Capacity>::ScopeGuardWithVariableCapacity(
29-
const cxx::function<void(), Capacity>& cleanupFunction) noexcept
27+
template <uint64_t CleanupCapacity>
28+
inline ScopeGuardWithVariableCapacity<CleanupCapacity>::ScopeGuardWithVariableCapacity(
29+
const cxx::function<void(), CleanupCapacity>& cleanupFunction) noexcept
3030
: m_cleanupFunction(cleanupFunction)
3131
{
3232
}
3333

34-
template <uint64_t Capacity>
35-
inline ScopeGuardWithVariableCapacity<Capacity>::ScopeGuardWithVariableCapacity(
36-
const function_ref<void()>& initFunction, const function<void()>& cleanupFunction) noexcept
34+
template <uint64_t CleanupCapacity>
35+
inline ScopeGuardWithVariableCapacity<CleanupCapacity>::ScopeGuardWithVariableCapacity(
36+
const function_ref<void()>& initFunction, const function<void(), CleanupCapacity>& cleanupFunction) noexcept
3737
: m_cleanupFunction(cleanupFunction)
3838
{
3939
initFunction();
4040
}
4141

42-
template <uint64_t Capacity>
43-
inline ScopeGuardWithVariableCapacity<Capacity>::~ScopeGuardWithVariableCapacity() noexcept
42+
template <uint64_t CleanupCapacity>
43+
inline ScopeGuardWithVariableCapacity<CleanupCapacity>::~ScopeGuardWithVariableCapacity() noexcept
4444
{
4545
destroy();
4646
}
4747

48-
template <uint64_t Capacity>
49-
inline ScopeGuardWithVariableCapacity<Capacity>::ScopeGuardWithVariableCapacity(
48+
template <uint64_t CleanupCapacity>
49+
inline ScopeGuardWithVariableCapacity<CleanupCapacity>::ScopeGuardWithVariableCapacity(
5050
ScopeGuardWithVariableCapacity&& rhs) noexcept
5151
{
5252
*this = std::move(rhs);
5353
}
5454

55-
template <uint64_t Capacity>
56-
inline ScopeGuardWithVariableCapacity<Capacity>&
57-
ScopeGuardWithVariableCapacity<Capacity>::operator=(ScopeGuardWithVariableCapacity<Capacity>&& rhs) noexcept
55+
template <uint64_t CleanupCapacity>
56+
inline ScopeGuardWithVariableCapacity<CleanupCapacity>& ScopeGuardWithVariableCapacity<CleanupCapacity>::operator=(
57+
ScopeGuardWithVariableCapacity<CleanupCapacity>&& rhs) noexcept
5858
{
5959
if (this != &rhs)
6060
{
6161
destroy();
6262
m_cleanupFunction = rhs.m_cleanupFunction;
63-
rhs.m_cleanupFunction = function<void()>();
63+
rhs.m_cleanupFunction = function<void(), CleanupCapacity>();
6464
}
6565
return *this;
6666
}
6767

68-
template <uint64_t Capacity>
69-
inline void ScopeGuardWithVariableCapacity<Capacity>::destroy() noexcept
68+
template <uint64_t CleanupCapacity>
69+
inline void ScopeGuardWithVariableCapacity<CleanupCapacity>::destroy() noexcept
7070
{
7171
if (m_cleanupFunction)
7272
{
7373
m_cleanupFunction();
74-
m_cleanupFunction = function<void()>();
74+
m_cleanupFunction = function<void(), CleanupCapacity>();
7575
}
7676
}
7777

0 commit comments

Comments
 (0)