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:
parent
ae8af8e02f
commit
e98ee53a9f
1 changed files with 105 additions and 88 deletions
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue