Skip to content

Commit

Permalink
Register/Unregister: ensure sink exists in the list or not before reg…
Browse files Browse the repository at this point in the history
…istering and unregistering
  • Loading branch information
HaseenaSainul committed Jul 1, 2024
1 parent 5aa8fea commit 5dc3058
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,26 @@ class Launcher : public PluginHost::IPlugin {

public:
void Register(IProcessState* observer) {
ASSERT(observer != nullptr);

_adminLock.Lock();
ASSERT (std::find(_callbacks.begin(), _callbacks.end(), observer) == _callbacks.end());
auto found = std::find(_callbacks.begin(), _callbacks.end(), observer);
ASSERT (found == _callbacks.end());

if (_callbacks.empty()) {
const bool opened = Open();
DEBUG_VARIABLE(opened);
ASSERT(opened);
}
_callbacks.push_back(observer);
if (found == _callbacks.end()) {
_callbacks.push_back(observer);
}

_adminLock.Unlock();
}
void Unregister(IProcessState* observer) {
ASSERT(observer != nullptr);

_adminLock.Lock();
auto found = std::find(_callbacks.begin(), _callbacks.end(), observer);
ASSERT(found != _callbacks.end());
Expand Down

0 comments on commit 5dc3058

Please sign in to comment.