Skip to content

Commit 18b6b45

Browse files
Add isUI method to LockManager for identify UI thread and grant immediate access
1 parent a549a17 commit 18b6b45

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

runtime/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/LockManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ public boolean aboutToWait(Thread lockOwner) {
109109
return false;
110110
}
111111

112+
public boolean isUI() {
113+
try {
114+
return lockListener.isUI();
115+
} catch (Exception | LinkageError e) {
116+
handleException(e);
117+
}
118+
return false;
119+
}
120+
112121
/**
113122
* This thread has just acquired a lock. Update graph.
114123
*/

runtime/bundles/org.eclipse.core.jobs/src/org/eclipse/core/internal/jobs/ThreadJob.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static ThreadJob joinRun(ThreadJob threadJob, IProgressMonitor monitor) {
208208
boolean interruptedDuringWaitForRun;
209209
try {
210210
// just return if lock listener decided to grant immediate access
211-
if (manager.getLockManager().aboutToWait(blocker) || identifyThreadAction()) {
211+
if (manager.getLockManager().aboutToWait(blocker) || manager.getLockManager().isUI()) {
212212
return threadJob;
213213
}
214214
result = waitForRun(threadJob, monitor, blockingJob);
@@ -231,31 +231,6 @@ static ThreadJob joinRun(ThreadJob threadJob, IProgressMonitor monitor) {
231231
return result;
232232
}
233233

234-
235-
public static boolean identifyThreadAction() {
236-
String threadName = Thread.currentThread().getName();
237-
Job currentJob = Job.getJobManager().currentJob();
238-
239-
// UI Thread (User interactions)
240-
if ("main".equals(threadName)) { //$NON-NLS-1$
241-
return true;
242-
}
243-
244-
// Background Worker Threads
245-
if (threadName.contains("Worker") && currentJob != null) { //$NON-NLS-1$
246-
String jobName = currentJob.getName().toLowerCase();
247-
if (jobName.contains("build")) { //$NON-NLS-1$
248-
// This thread is handling a BUILD job
249-
return false;
250-
}
251-
// Any other worker-thread job
252-
return false;
253-
}
254-
255-
// Everything else defaults to false
256-
return false;
257-
}
258-
259234
/**
260235
* Waits until given {@code ThreadJob} "runs" (acquires the rule conflicting
261236
* with given {@code blockingJob} or is canceled. While the given

runtime/bundles/org.eclipse.core.jobs/src/org/eclipse/core/runtime/jobs/LockListener.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ public boolean aboutToWait(Thread lockOwner) {
4646
return false;
4747
}
4848

49+
/**
50+
* @since 3.16
51+
*/
52+
public boolean isUI() {
53+
return false;
54+
}
4955
/**
5056
* Notification that a thread is about to release a lock.
5157
* <p>

0 commit comments

Comments
 (0)