|
16 | 16 | import java.io.PrintWriter;
|
17 | 17 | import java.io.StringWriter;
|
18 | 18 | import java.util.ArrayList;
|
| 19 | +import java.util.Collection; |
| 20 | +import java.util.HashSet; |
| 21 | +import java.util.Set; |
19 | 22 | import org.eclipse.core.internal.runtime.RuntimeLog;
|
20 | 23 | import org.eclipse.core.runtime.Assert;
|
21 | 24 | import org.eclipse.core.runtime.IStatus;
|
@@ -304,23 +307,30 @@ void lockAcquired(Thread owner, ISchedulingRule lock) {
|
304 | 307 | * or conflict with a lock the given lock will acquire implicitly
|
305 | 308 | * (locks are acquired implicitly when a conflicting lock is acquired)
|
306 | 309 | */
|
307 |
| - ArrayList<ISchedulingRule> conflicting = new ArrayList<>(1); |
308 |
| - //only need two passes through all the locks to pick up all conflicting rules |
309 |
| - int NUM_PASSES = 2; |
310 |
| - conflicting.add(lock); |
311 | 310 | graph[threadIndex][lockIndex]++;
|
312 |
| - for (int i = 0; i < NUM_PASSES; i++) { |
313 |
| - for (int k = 0; k < conflicting.size(); k++) { |
314 |
| - ISchedulingRule current = conflicting.get(k); |
315 |
| - for (int j = 0; j < locks.size(); j++) { |
316 |
| - ISchedulingRule possible = locks.get(j); |
317 |
| - if (!conflicting.contains(possible) && current.isConflicting(possible)) { |
318 |
| - conflicting.add(possible); |
319 |
| - graph[threadIndex][j]++; |
320 |
| - } |
| 311 | + |
| 312 | + // first pass tests against lock: |
| 313 | + Collection<ISchedulingRule> conflicting = Set.of(lock); |
| 314 | + conflicting = computeConflicting(threadIndex, conflicting); |
| 315 | + |
| 316 | + // second pass tests also transitive: |
| 317 | + if (!conflicting.isEmpty()) { |
| 318 | + conflicting = computeConflicting(threadIndex, conflicting); |
| 319 | + } |
| 320 | + } |
| 321 | + |
| 322 | + private Collection<ISchedulingRule> computeConflicting(int threadIndex, Collection<ISchedulingRule> candidates) { |
| 323 | + Collection<ISchedulingRule> conflicting = new HashSet<>(candidates); |
| 324 | + for (ISchedulingRule current : candidates) { |
| 325 | + for (int j = 0; j < locks.size(); j++) { |
| 326 | + ISchedulingRule possible = locks.get(j); |
| 327 | + if (!conflicting.contains(possible) && current.isConflicting(possible)) { |
| 328 | + conflicting.add(possible); |
| 329 | + graph[threadIndex][j]++; |
321 | 330 | }
|
322 | 331 | }
|
323 | 332 | }
|
| 333 | + return conflicting; |
324 | 334 | }
|
325 | 335 |
|
326 | 336 | /**
|
|
0 commit comments