MCPcopy Create free account
hub / github.com/catboost/catboost / TryToFreeAsyncMemory

Method TryToFreeAsyncMemory

util/thread/lfqueue.h:72–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70 alignas(64) std::atomic<TRootNode*> FreePtr;
71
72 void TryToFreeAsyncMemory() {
73 const auto keepCounter = FreeingTaskCounter.load();
74 TRootNode* current = FreePtr.load(std::memory_order_acquire);
75 if (current == nullptr) {
76 return;
77 }
78 if (FreememCounter.load() == 1) {
79 // we are the last thread, try to cleanup
80 // check if another thread have cleaned up
81 if (keepCounter != FreeingTaskCounter.load()) {
82 return;
83 }
84 if (FreePtr.compare_exchange_strong(current, nullptr)) {
85 // free list
86 while (current) {
87 TRootNode* p = current->NextFree.load(std::memory_order_acquire);
88 EraseList(current->ToDelete.load(std::memory_order_acquire));
89 delete current;
90 current = p;
91 }
92 ++FreeingTaskCounter;
93 }
94 }
95 }
96 void AsyncRef() {
97 ++FreememCounter;
98 }

Callers

nothing calls this directly

Calls 3

EraseListFunction · 0.50
loadMethod · 0.45

Tested by

no test coverage detected