This reverts commit 44bd29a3b068363e013cd425c68fd00dba21d633. Reason for revert: Going for an alternative implementation that makes this unnecessary https://webrtc-review.googlesource.com/c/src/+/150649 Original change's description: > Detect leaks of TextureBufferImpl objects. > > The performance cost is not trivial but according to my profiling, > it is acceptable. > > Bug: b/139745386 > Change-Id: I0e63221ccf22e9f6fb32c630ff63a279e765994a > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/150539 > Reviewed-by: Kári Helgason <kthelgason@webrtc.org> > Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#28973} TBR=sakal@webrtc.org,kthelgason@webrtc.org Change-Id: Ic6266e5fd24389d41a6d5dbfe51de6505b861b12 Bug: b/139745386 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/150650 Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Cr-Commit-Position: refs/heads/master@{#28983}
49 lines
1.5 KiB
Java
49 lines
1.5 KiB
Java
/*
|
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
package org.webrtc;
|
|
|
|
import android.support.annotation.Nullable;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
/**
|
|
* Implementation of RefCounted that executes a Runnable once the ref count reaches zero.
|
|
*/
|
|
class RefCountDelegate implements RefCounted {
|
|
private final AtomicInteger refCount = new AtomicInteger(1);
|
|
private final @Nullable Runnable releaseCallback;
|
|
|
|
/**
|
|
* @param releaseCallback Callback that will be executed once the ref count reaches zero.
|
|
*/
|
|
public RefCountDelegate(@Nullable Runnable releaseCallback) {
|
|
this.releaseCallback = releaseCallback;
|
|
}
|
|
|
|
@Override
|
|
public void retain() {
|
|
int updated_count = refCount.incrementAndGet();
|
|
if (updated_count < 2) {
|
|
throw new IllegalStateException("retain() called on an object with refcount < 1");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void release() {
|
|
int updated_count = refCount.decrementAndGet();
|
|
if (updated_count < 0) {
|
|
throw new IllegalStateException("release() called on an object with refcount < 1");
|
|
}
|
|
if (updated_count == 0 && releaseCallback != null) {
|
|
releaseCallback.run();
|
|
}
|
|
}
|
|
}
|