Rabbit-R1/android (non root)/java/sources/org/webrtc/RefCountDelegate.java
2024-05-21 17:08:36 -04:00

45 lines
1.3 KiB
Java

package org.webrtc;
import java.util.concurrent.atomic.AtomicInteger;
/* loaded from: classes3.dex */
class RefCountDelegate implements RefCounted {
private final AtomicInteger refCount = new AtomicInteger(1);
private final Runnable releaseCallback;
public RefCountDelegate(Runnable runnable) {
this.releaseCallback = runnable;
}
@Override // org.webrtc.RefCounted
public void retain() {
if (this.refCount.incrementAndGet() < 2) {
throw new IllegalStateException("retain() called on an object with refcount < 1");
}
}
@Override // org.webrtc.RefCounted
public void release() {
Runnable runnable;
int decrementAndGet = this.refCount.decrementAndGet();
if (decrementAndGet < 0) {
throw new IllegalStateException("release() called on an object with refcount < 1");
}
if (decrementAndGet != 0 || (runnable = this.releaseCallback) == null) {
return;
}
runnable.run();
}
/* JADX INFO: Access modifiers changed from: package-private */
public boolean safeRetain() {
int i = this.refCount.get();
while (i != 0) {
if (this.refCount.weakCompareAndSet(i, i + 1)) {
return true;
}
i = this.refCount.get();
}
return false;
}
}