* Add the provided dependency to the current Checkable list of dependencies. * * @param dependency The dependency to add. */
| 64 | * @param dependency The dependency to add. |
| 65 | */ |
| 66 | void Checkable::AddDependency(const Dependency::Ptr& dependency) |
| 67 | { |
| 68 | std::unique_lock lock(m_DependencyMutex); |
| 69 | |
| 70 | auto dependencyGroupKey(GetDependencyGroupKey(dependency)); |
| 71 | if (m_PendingDependencies != nullptr) { |
| 72 | (*m_PendingDependencies)[dependencyGroupKey].emplace(dependency); |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | std::set<Dependency::Ptr> dependencies; |
| 77 | bool removeGroup(false); |
| 78 | |
| 79 | DependencyGroup::Ptr existingGroup; |
| 80 | if (auto it(m_DependencyGroups.find(dependencyGroupKey)); it != m_DependencyGroups.end()) { |
| 81 | existingGroup = it->second; |
| 82 | std::tie(dependencies, removeGroup) = DependencyGroup::Unregister(existingGroup, this); |
| 83 | m_DependencyGroups.erase(it); |
| 84 | } |
| 85 | |
| 86 | dependencies.emplace(dependency); |
| 87 | |
| 88 | auto dependencyGroup(DependencyGroup::Register(new DependencyGroup(dependency->GetRedundancyGroup(), dependencies))); |
| 89 | m_DependencyGroups.emplace(dependencyGroupKey, dependencyGroup); |
| 90 | |
| 91 | lock.unlock(); |
| 92 | |
| 93 | if (existingGroup) { |
| 94 | dependencies.erase(dependency); |
| 95 | DependencyGroup::OnChildRemoved(existingGroup, {dependencies.begin(), dependencies.end()}, removeGroup); |
| 96 | } |
| 97 | DependencyGroup::OnChildRegistered(this, dependencyGroup); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Remove the provided dependency from the current Checkable list of dependencies. |