diff options
Diffstat (limited to 'zenstore/gc.cpp')
| -rw-r--r-- | zenstore/gc.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/zenstore/gc.cpp b/zenstore/gc.cpp index f7e448887..612cceed9 100644 --- a/zenstore/gc.cpp +++ b/zenstore/gc.cpp @@ -35,6 +35,18 @@ GcContext::ContributeCas(std::span<const IoHash> Cas) ////////////////////////////////////////////////////////////////////////// +GcContributor::GcContributor(CasGc& Gc) : m_Gc(Gc) +{ + m_Gc.AddGcContributor(this); +} + +GcContributor::~GcContributor() +{ + m_Gc.RemoveGcContributor(this); +} + +////////////////////////////////////////////////////////////////////////// + CasGc::CasGc(CasStore& Store) : m_CasStore(Store) { } @@ -43,6 +55,20 @@ CasGc::~CasGc() { } +void +CasGc::AddGcContributor(GcContributor* Contributor) +{ + RwLock::ExclusiveLockScope _(m_Lock); + m_GcContribs.push_back(Contributor); +} + +void +CasGc::RemoveGcContributor(GcContributor* Contributor) +{ + RwLock::ExclusiveLockScope _(m_Lock); + std::erase_if(m_GcContribs, [&](GcContributor* $) { return $ == Contributor; }); +} + void CasGc::CollectGarbage() { |