1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 387507 - PDOMManager.joinIndexer() can wrongly return false

Change-Id: Iebe3bb8840ea4b27bb2624a0526cf0f0f6ac0669
Reviewed-on: https://git.eclipse.org/r/7281
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
John Cortell 2012-08-17 20:04:29 -05:00 committed by Sergey Prigogin
parent ae8af8e02f
commit e98ee53a9f

View file

@ -1088,6 +1088,10 @@ public class PDOMManager implements IWritableIndexManager, IListener {
@Override
public boolean joinIndexer(final int waitMaxMillis, final IProgressMonitor monitor) {
assert monitor != null;
long startMillis = System.currentTimeMillis();
// Unfortunately, IJobManager.join() doesn't take a timeout. So, we create a watchdog thread to
// interrupt the call if the indexer job doesn't complete in the alloted time
Thread th= null;
if (waitMaxMillis != FOREVER) {
final Thread callingThread= Thread.currentThread();
@ -1112,8 +1116,21 @@ public class PDOMManager implements IWritableIndexManager, IListener {
} catch (OperationCanceledException e) {
} catch (InterruptedException e) {
}
return Job.getJobManager().find(this).length == 0;
// When the indexer job is interrupted, the join() above will throw an exception and that can
// happen slightly before the JobManager updates its job collection. Wait for it.
while (Job.getJobManager().find(this).length != 0) {
if (System.currentTimeMillis() - startMillis > waitMaxMillis) {
return false;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
}
return true;
} finally {
// Make sure we don't leave the watchdog thread running
if (th != null) {
th.interrupt();
}