Skip to main content
summaryrefslogtreecommitdiffstats
blob: 178b82d1f82991e6b53a1df68d20fcb18f51015a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*******************************************************************************
 * Copyright (c) 2007, 2009 Wind River Systems and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.dsf.debug.internal.ui.disassembly.model;

import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.DisassemblyMessages;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;


/**
 * Low-level job to read source files in the background.
 */
public class SourceReadingJob extends Job {

	private final static String NAME = DisassemblyMessages.SourceReadingJob_name;

	private SourceFileInfo fFileInfo;
	private Runnable fDone;

	public SourceReadingJob(SourceFileInfo fi, Runnable done) {
		super(NAME);
		fFileInfo = fi;
		fFileInfo.fReadingJob = this;
		fDone = done;
		if (fi.fFile instanceof ISchedulingRule) {
			setRule((ISchedulingRule)fi.fFile);
		}
		setSystem(true);
		// usually short lived job
		setPriority(SHORT);
		if (fi.fFile.getFullPath() != null) {
			String fileName = fi.fFile.getFullPath().lastSegment();
			setName(NAME + " (" + fileName + ')'); //$NON-NLS-1$
		}
	}

	public synchronized void dispose() {
		fDone = null;
		Thread thread = getThread();
		if (thread != null && thread.isAlive()) {
			thread.interrupt();
		}
	}

	@Override
	public IStatus run(IProgressMonitor monitor) {
		if (fFileInfo.fEditionJob != null) {
			try {
				fFileInfo.fEditionJob.join();
			} catch (InterruptedException e) {
				// ignore
			}
		}
		try {
			fFileInfo.initSource();
		} catch (Throwable e) {
			fFileInfo.fError = e;
		} finally {
			fFileInfo.fReadingJob = null;
			synchronized (this) {
				if (fDone != null && !getThread().isInterrupted()) {
					fDone.run();
				}
			}
		}
		// errors are handled elsewhere
		return Status.OK_STATUS;
	}
}

Back to the top