Skip to content

Commit

Permalink
iox-eclipse-iceoryx#325 rework cleanup method
Browse files Browse the repository at this point in the history
Signed-off-by: Mathias Kraus <[email protected]>
  • Loading branch information
elBoberido committed May 5, 2021
1 parent d87c9a8 commit eccbe18
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ class DualAccessTransactionTray
AccessToken m_accessToken{AccessToken::NONE};
};

/// @brief Clean up a potential locking when LEFT or RIGHT terminated abnormally.
/// @param[in] tokenToCleanup is the DualAccessTransactionTray::LEFT or DualAccessTransactionTray::RIGHT token
/// @attention this should only be called if the thread with `tokenToCleanup` is not running anymore else the
/// @brief Revokes the lock from an absent participant when LEFT or RIGHT terminated abnormally.
/// @param[in] absentPaticipantToken is the DualAccessTransactionTray::LEFT or DualAccessTransactionTray::RIGHT
/// token
/// @attention this should only be called if the thread with `absentPaticipantToken` is not running anymore else the
/// invariants are broken and you might observe pink elephants and dragons
void cleanupAndSyncMemory(const AccessToken tokenToCleanup);
void revokeLockFromAbsentParticipant(const AccessToken absentPaticipantToken);

private:
void acquireExclusiveAccess(const AccessToken tokenToAcquireAccess);
Expand Down
11 changes: 4 additions & 7 deletions iceoryx_utils/source/concurrent/dual_access_transaction_tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,14 @@ DualAccessTransactionTray::AccessGuard::~AccessGuard()
m_transactionTray.releaseExclusiveAccess(m_accessToken);
}

void DualAccessTransactionTray::cleanupAndSyncMemory(const AccessToken tokenToCleanup)
void DualAccessTransactionTray::revokeLockFromAbsentParticipant(const AccessToken absentPaticipantToken)
{
releaseExclusiveAccess(tokenToCleanup);
// just to be sure the memory is synchronized
AccessToken expected = tokenToCleanup;
m_accessToken.compare_exchange_strong(expected, AccessToken::NONE, std::memory_order_acq_rel);
releaseExclusiveAccess(absentPaticipantToken);
}

void DualAccessTransactionTray::acquireExclusiveAccess(const AccessToken tokenToAcquireAccess)
{
auto existingToken = m_accessToken.exchange(tokenToAcquireAccess, std::memory_order_acquire);
auto existingToken = m_accessToken.exchange(tokenToAcquireAccess, std::memory_order_relaxed);
if (existingToken == tokenToAcquireAccess)
{
// TODO return expected DOUBLE_ACQUIRE_BROKEN_INVARIANT
Expand Down Expand Up @@ -71,7 +68,7 @@ void DualAccessTransactionTray::acquireExclusiveAccess(const AccessToken tokenTo
void DualAccessTransactionTray::releaseExclusiveAccess(const AccessToken tokenToBeReleased)
{
AccessToken expected = tokenToBeReleased;
auto casSuccessful = m_accessToken.compare_exchange_strong(expected, AccessToken::NONE, std::memory_order_release);
auto casSuccessful = m_accessToken.compare_exchange_strong(expected, AccessToken::NONE, std::memory_order_relaxed);
if (!casSuccessful)
{
if (expected == AccessToken::NONE)
Expand Down

0 comments on commit eccbe18

Please sign in to comment.