File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
src/main/java/org/yatopiamc/c2me/common/util Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -42,12 +42,21 @@ private synchronized void tryAcquire() { // TODO optimize logic
4242 if (allAcquired ) {
4343 future .complete (new CombinedLockToken (tryLocks .stream ().flatMap (lockEntry -> lockEntry .lockToken .stream ()).collect (Collectors .toUnmodifiableSet ())));
4444 } else {
45- tryLocks .stream ().flatMap (lockEntry -> lockEntry .lockToken .stream ()).forEach (AsyncLock .LockToken ::releaseLock );
46- tryLocks .stream ().unordered ().filter (lockEntry -> lockEntry .lockToken .isEmpty ()).findFirst ().ifPresentOrElse (lockEntry ->
47- lockEntry .lock .acquireLock ().thenCompose (lockToken -> {
45+ boolean triedRelock = false ;
46+ for (LockEntry entry : tryLocks ) {
47+ entry .lockToken .ifPresent (AsyncLock .LockToken ::releaseLock );
48+ if (!triedRelock && entry .lockToken .isEmpty ()) {
49+ entry .lock .acquireLock ().thenCompose (lockToken -> {
4850 lockToken .releaseLock ();
4951 return CompletableFuture .runAsync (this ::tryAcquire , lockWorker );
50- }), this ::tryAcquire );
52+ });
53+ triedRelock = true ;
54+ }
55+ }
56+ if (!triedRelock ) {
57+ // shouldn't happen at all...
58+ lockWorker .execute (this ::tryAcquire );
59+ }
5160 }
5261 }
5362
You can’t perform that action at this time.
0 commit comments