From 60f668f259bb648f696bf851fc8e5abc7b9b3c50 Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Wed, 19 Oct 2022 11:51:26 -0400 Subject: [PATCH] Resolve deadlock in Jobmanager related code Because of [changes](https://www.eclipse.org/eclipse/news/4.26/platform_isv.php#JobManager_Implementation) in Eclipse Platform where the jobmanager's behaviour changes (within the API), the consumers of the jobmanager can deadlock due to incorrect assumptions. In particular, where we call job.schedule(), the callback can happen in different threads to the IJobChangeListener's. As CDT was holding a lock while calling schedule that is also required in those listeners, we need to no longer lock when calling schedule. As the code already dealt with the case of when there was a delay between the job.schedule() and where & when it was run, we can move the schedule call out of the synchronized block. Fixes #81 --- .../eclipse/cdt/internal/core/pdom/PDOMManager.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java index 868780685ae..78a52a1cd6d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMManager.java @@ -709,8 +709,8 @@ public class PDOMManager implements IWritableIndexManager, IListener { } } fTaskQueue.addLast(subjob); - fIndexerJob.schedule(); } + fIndexerJob.schedule(); } IPDOMIndexerTask getNextTask() { @@ -734,14 +734,16 @@ public class PDOMManager implements IWritableIndexManager, IListener { } void indexerJobCanceled(boolean byManager) { + boolean scheduleJob; synchronized (fTaskQueue) { fCurrentTask = null; if (!byManager) { fTaskQueue.clear(); } - if (!fTaskQueue.isEmpty()) { - fIndexerJob.schedule(); - } + scheduleJob = !fTaskQueue.isEmpty(); + } + if (scheduleJob) { + fIndexerJob.schedule(); } }