mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-26 17:12:31 -06:00
46 lines
1.3 KiB
Java
46 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;
|
||
|
}
|
||
|
}
|