diff options
Diffstat (limited to 'zenstore/gc.cpp')
| -rw-r--r-- | zenstore/gc.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/zenstore/gc.cpp b/zenstore/gc.cpp index 278f09b0b..52bb33955 100644 --- a/zenstore/gc.cpp +++ b/zenstore/gc.cpp @@ -2,9 +2,11 @@ #include <zenstore/gc.h> +#include <zencore/logging.h> +#include <zencore/string.h> +#include <zencore/timer.h> #include <zenstore/CAS.h> #include <zenstore/cidstore.h> -#include <zencore/logging.h> namespace zen { @@ -202,4 +204,28 @@ CasGc::OnDroppedCidReferences(std::span<IoHash> Hashes) ZEN_UNUSED(Hashes); } +bool +Gc::Trigger() +{ + uint32_t Expected = uint32_t(GcStatus::kIdle); + if (!m_Status.compare_exchange_strong(Expected, static_cast<uint32_t>(GcStatus::kRunning))) + { + return false; + } + + ZEN_ASSERT(GcStatus::kRunning == Status()); + + m_GcThread = std::jthread([this]() { + Stopwatch Timer; + ZEN_INFO("garbage collection STARTING"); + + m_CasGc.CollectGarbage(); + m_Status = static_cast<uint32_t>(GcStatus::kIdle); + + ZEN_INFO("garbage collection DONE after {}", NiceTimeSpanMs(Timer.GetElapsedTimeMs())); + }); + + return true; +} + } // namespace zen |