That fuck shit the fascists are using
1package org.tm.archive.groups;
2
3import androidx.annotation.WorkerThread;
4
5import org.signal.core.util.ThreadUtil;
6import org.signal.core.util.logging.Log;
7import org.tm.archive.crypto.ReentrantSessionLock;
8import org.tm.archive.database.SignalDatabase;
9import org.tm.archive.util.FeatureFlags;
10
11import java.io.Closeable;
12import java.util.concurrent.TimeUnit;
13import java.util.concurrent.locks.ReentrantLock;
14
15public final class GroupsV2ProcessingLock {
16
17 private static final String TAG = Log.tag(GroupsV2ProcessingLock.class);
18
19 private GroupsV2ProcessingLock() {
20 }
21
22 private static final ReentrantLock lock = new ReentrantLock();
23
24 @WorkerThread
25 public static Closeable acquireGroupProcessingLock() throws GroupChangeBusyException {
26 if (FeatureFlags.internalUser()) {
27 if (!lock.isHeldByCurrentThread()) {
28 if (SignalDatabase.inTransaction()) {
29 throw new AssertionError("Tried to acquire the group lock inside of a database transaction!");
30 }
31 if (ReentrantSessionLock.INSTANCE.isHeldByCurrentThread()) {
32 throw new AssertionError("Tried to acquire the group lock inside of the ReentrantSessionLock!!");
33 }
34 }
35 }
36 return acquireGroupProcessingLock(5000);
37 }
38
39 @WorkerThread
40 public static Closeable acquireGroupProcessingLock(long timeoutMs) throws GroupChangeBusyException {
41 ThreadUtil.assertNotMainThread();
42
43 try {
44 if (!lock.tryLock(timeoutMs, TimeUnit.MILLISECONDS)) {
45 throw new GroupChangeBusyException("Failed to get a lock on the group processing in the timeout period");
46 }
47 return lock::unlock;
48 } catch (InterruptedException e) {
49 Log.w(TAG, e);
50 throw new GroupChangeBusyException(e);
51 }
52 }
53}