-
Notifications
You must be signed in to change notification settings - Fork 586
Checkable#ProcessCheckResult(): discard🗑️ CR or delay its producers shutdown #10397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
18fb93f
Introduce WaitGroup and StoppableWaitGroup
Al2Klimov c7cca7b
Add a StoppableWaitGroup, and join it on #Stop(), to:
Al2Klimov f4691dd
Require to pass WaitGroup::Ptr to several methods
Al2Klimov 36743f3
Checkable#ProcessCheckResult(): discard CR or delay its producers shu…
Al2Klimov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* Icinga 2 | (c) 2025 Icinga GmbH | GPLv2+ */ | ||
|
||
#include "base/wait-group.hpp" | ||
|
||
using namespace icinga; | ||
|
||
bool StoppableWaitGroup::try_lock_shared() | ||
{ | ||
std::unique_lock lock (m_Mutex); | ||
|
||
if (m_Stopped) { | ||
return false; | ||
} | ||
|
||
++m_SharedLocks; | ||
return true; | ||
} | ||
|
||
void StoppableWaitGroup::unlock_shared() | ||
{ | ||
std::unique_lock lock (m_Mutex); | ||
|
||
if (!--m_SharedLocks && m_Stopped) { | ||
lock.unlock(); | ||
m_CV.notify_all(); | ||
} | ||
} | ||
|
||
/** | ||
* Disallow new shared locks, wait for all existing ones. | ||
*/ | ||
void StoppableWaitGroup::Join() | ||
{ | ||
std::unique_lock lock (m_Mutex); | ||
|
||
m_Stopped = true; | ||
m_CV.wait(lock, [this] { return !m_SharedLocks; }); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* Icinga 2 | (c) 2025 Icinga GmbH | GPLv2+ */ | ||
|
||
#pragma once | ||
|
||
#include "base/object.hpp" | ||
#include <condition_variable> | ||
#include <cstdint> | ||
#include <mutex> | ||
|
||
namespace icinga | ||
{ | ||
|
||
/** | ||
* A synchronization interface that allows concurrent shared locking. | ||
* | ||
* @ingroup base | ||
*/ | ||
class WaitGroup : public Object | ||
{ | ||
public: | ||
DECLARE_PTR_TYPEDEFS(WaitGroup); | ||
|
||
virtual bool try_lock_shared() = 0; | ||
virtual void unlock_shared() = 0; | ||
}; | ||
|
||
/** | ||
* A thread-safe wait group that can be stopped to prevent further shared locking. | ||
* | ||
* @ingroup base | ||
*/ | ||
class StoppableWaitGroup : public WaitGroup | ||
{ | ||
public: | ||
DECLARE_PTR_TYPEDEFS(StoppableWaitGroup); | ||
|
||
StoppableWaitGroup() = default; | ||
StoppableWaitGroup(const StoppableWaitGroup&) = delete; | ||
StoppableWaitGroup(StoppableWaitGroup&&) = delete; | ||
StoppableWaitGroup& operator=(const StoppableWaitGroup&) = delete; | ||
StoppableWaitGroup& operator=(StoppableWaitGroup&&) = delete; | ||
|
||
bool try_lock_shared() override; | ||
void unlock_shared() override; | ||
void Join(); | ||
|
||
private: | ||
std::mutex m_Mutex; | ||
std::condition_variable m_CV; | ||
uint_fast32_t m_SharedLocks = 0; | ||
bool m_Stopped = false; | ||
}; | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.