MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / removeAllNotInUseMatching

Method removeAllNotInUseMatching

python/mod_cvcuda/nvcv/Cache.cpp:156–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154}
155
156void Cache::removeAllNotInUseMatching(const IKey &key)
157{
158 // When we're removing items, we don't want their
159 // refcount getting to 0 while the mutex is locked, as
160 // deleting the object might recursively call removeAllNotInUseMatching,
161 // leading to a dead lock.
162 //
163 // Instead, we gather the removed objects in the vector below, which will
164 // be destroyed after the mutex is unlocked. When this happens, the items'
165 // refcount will be decremented, and any object destruction will happen
166 // after the mutex is unlocked. Recursion can happen in this case, but won't
167 // lead to deadlocks
168 std::vector<std::shared_ptr<CacheItem>> holdItemsUntilMtxUnlocked;
169
170 {
171 std::unique_lock<std::mutex> lk(pimpl->mtx);
172
173 auto itrange = pimpl->items.equal_range(&key);
174
175 int numItems = std::distance(itrange.first, itrange.second);
176
177 auto it = itrange.first;
178 for (int i = 0; i < numItems; ++i)
179 {
180 if (!it->second->isInUse())
181 {
182 holdItemsUntilMtxUnlocked.push_back(it->second);
183 pimpl->current_size_inbytes -= it->second->GetSizeInBytes();
184 pimpl->items.erase(it++);
185 }
186 else
187 {
188 ++it;
189 }
190 }
191 }
192}
193
194std::vector<std::shared_ptr<CacheItem>> Cache::fetch(const IKey &key) const
195{

Callers 7

WrapMethod · 0.45
WrapImageMethod · 0.45
ReshapeTensorMethod · 0.45
WrapMethod · 0.45
ResizeArrayMethod · 0.45
CAPI.cppFile · 0.45
CreateHostVectorMethod · 0.45

Calls 4

isInUseMethod · 0.80
push_backMethod · 0.45
GetSizeInBytesMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected