diff options
author | Siva Velusamy <vsiva@google.com> | 2012-02-21 09:12:39 -0800 |
---|---|---|
committer | Siva Velusamy <vsiva@google.com> | 2012-02-21 14:56:22 -0800 |
commit | 34e4ce9cb42f4db512103b47445d4145c09fc806 (patch) | |
tree | 72b7d5396bb6fcce2fb199173b39210f5c574850 /eclipse | |
parent | e097a203213af3d593cc3e23f05c08abec9c53c6 (diff) | |
download | sdk-34e4ce9cb42f4db512103b47445d4145c09fc806.zip sdk-34e4ce9cb42f4db512103b47445d4145c09fc806.tar.gz sdk-34e4ce9cb42f4db512103b47445d4145c09fc806.tar.bz2 |
gltrace: Fix state update race condition.
The GL State is updated in reaction to user selections, and
should be performed only in a synchronized block.
Change-Id: Ieeaba4fd5a088b5b9e85a21fb6738c214d6f8c01
Diffstat (limited to 'eclipse')
-rw-r--r-- | eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/StateViewPage.java | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/StateViewPage.java b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/StateViewPage.java index 937a366..174e70f 100644 --- a/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/StateViewPage.java +++ b/eclipse/plugins/com.android.ide.eclipse.gldebugger/src/com/android/ide/eclipse/gltrace/editors/StateViewPage.java @@ -27,6 +27,7 @@ import com.android.ide.eclipse.gltrace.state.transforms.IStateTransform; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.ILock; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -57,6 +58,7 @@ import java.util.Set; */ public class StateViewPage extends Page implements ISelectionListener, ISelectionProvider { public static final String ID = "com.android.ide.eclipse.gltrace.views.GLState"; //$NON-NLS-1$ + private static final ILock sGlStateLock = Job.getJobManager().newLock(); private final GLTrace mTrace; private final List<GLCall> mGLCalls; @@ -138,41 +140,43 @@ public class StateViewPage extends Page implements ISelectionListener, ISelectio } final int selectedCallIndex = selectedCall.getIndex(); - if (selectedCall.getIndex() != mCurrentStateIndex) { - // Creation of texture images takes a few seconds on the first run. So run - // the update task as an Eclipse job. - Job job = new Job("Updating GL State") { - @Override - protected IStatus run(IProgressMonitor monitor) { - Set<IGLProperty> changedProperties = null; - - try { - changedProperties = updateState(mCurrentStateIndex, + + // Creation of texture images takes a few seconds on the first run. So run + // the update task as an Eclipse job. + Job job = new Job("Updating GL State") { + @Override + protected IStatus run(IProgressMonitor monitor) { + Set<IGLProperty> changedProperties = null; + + try { + sGlStateLock.acquire(); + changedProperties = updateState(mCurrentStateIndex, selectedCallIndex); - } catch (Exception e) { - return new Status(Status.ERROR, - Activator.PLUGIN_ID, - "Unexpected error while updating GL State.", - e); - } mCurrentStateIndex = selectedCallIndex; + } catch (Exception e) { + return new Status(Status.ERROR, + Activator.PLUGIN_ID, + "Unexpected error while updating GL State.", + e); + } finally { + sGlStateLock.release(); + } - mLabelProvider.setChangedProperties(changedProperties); - Display.getDefault().syncExec(new Runnable() { - @Override - public void run() { - if (!mTreeViewer.getTree().isDisposed()) { - mTreeViewer.refresh(); - } + mLabelProvider.setChangedProperties(changedProperties); + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + if (!mTreeViewer.getTree().isDisposed()) { + mTreeViewer.refresh(); } - }); + } + }); - return Status.OK_STATUS; - } - }; - job.setPriority(Job.SHORT); - job.schedule(); - } + return Status.OK_STATUS; + } + }; + job.setPriority(Job.SHORT); + job.schedule(); } @Override |