Project import generated by Copybara.

GitOrigin-RevId: 6e4aff1cc351be3ae4537b677f36d139ee50ce09
This commit is contained in:
MediaPipe Team
2021-03-25 22:09:18 -04:00
committed by chuoling
parent a92cff7a60
commit 7c331ad58b
175 changed files with 4804 additions and 1325 deletions
+11 -11
View File
@@ -52,15 +52,15 @@ GlTextureBufferSharedPtr GlTextureBufferPool::GetBuffer() {
// Return a shared_ptr with a custom deleter that adds the buffer back
// to our available list.
std::weak_ptr<GlTextureBufferPool> weak_pool(shared_from_this());
return std::shared_ptr<GlTextureBuffer>(buffer.release(),
[weak_pool](GlTextureBuffer* buf) {
auto pool = weak_pool.lock();
if (pool) {
pool->Return(buf);
} else {
delete buf;
}
});
return std::shared_ptr<GlTextureBuffer>(
buffer.release(), [weak_pool](GlTextureBuffer* buf) {
auto pool = weak_pool.lock();
if (pool) {
pool->Return(absl::WrapUnique(buf));
} else {
delete buf;
}
});
}
std::pair<int, int> GlTextureBufferPool::GetInUseAndAvailableCounts() {
@@ -68,12 +68,12 @@ std::pair<int, int> GlTextureBufferPool::GetInUseAndAvailableCounts() {
return {in_use_count_, available_.size()};
}
void GlTextureBufferPool::Return(GlTextureBuffer* buf) {
void GlTextureBufferPool::Return(std::unique_ptr<GlTextureBuffer> buf) {
std::vector<std::unique_ptr<GlTextureBuffer>> trimmed;
{
absl::MutexLock lock(&mutex_);
--in_use_count_;
available_.emplace_back(buf);
available_.emplace_back(std::move(buf));
TrimAvailable(&trimmed);
}
// The trimmed buffers will be released without holding the lock.