Permalink
Browse files

Merge pull request #83 from yiding/master

small fix for syntax highlighter in async mode
  • Loading branch information...
2 parents 1688250 + 8deb3ac commit 3e6bd3d52cbb71bb5ecd1a121826edb157e5c152 @JPMoresmau committed Jan 11, 2013
@@ -63,7 +63,8 @@ public SyntaxColoringJob( final IRegion damage, final IDocument document ) {
@Override
protected IStatus run( final IProgressMonitor arg0 ) {
final TextPresentation p=HaskellPresentationReconciler.super.createPresentation( damage, document );
- if (p!=null && viewer!=null && viewer.getTextWidget()!=null && !viewer.getTextWidget().isDisposed()){
+ if (p!=null && viewer!=null && viewer.getTextWidget()!=null && !viewer.getTextWidget().isDisposed() &&
+ !queue.hasPendingJob()){
viewer.getTextWidget().getDisplay().syncExec( new Runnable(){
/* (non-Javadoc)
* @see java.lang.Runnable#run()
@@ -11,49 +11,44 @@
*/
public class SingleJobQueue {
/**
- * lock to ensure concurrency
- */
- private Object lock=new Object();
-
- /**
* the currently running job
*/
private Job current;
/**
* the next job to run
*/
private Job next;
-
+
/**
* add a job to the queue
* if the queue is empty, schedule the job straight away
* otherwise queue the job (losing the previously waiting job if any)
* @param j
*/
- public void addJob(Job j){
- synchronized (lock){
- if (current==null){
- current=j;
- launchCurrent();
- } else {
- next=j;
- }
+ public synchronized void addJob(Job j) {
+ if (current==null){
+ current=j;
+ launchCurrent();
+ } else {
+ next=j;
}
}
-
+
/**
* close the queue: cancel current job and remove next
*/
- public void close(){
- synchronized (lock){
- next=null;
- if (current!=null){
- current.cancel();
- }
- current=null;
+ public synchronized void close(){
+ next=null;
+ if (current!=null){
+ current.cancel();
}
+ current=null;
+ }
+
+ public synchronized boolean hasPendingJob() {
+ return next != null;
}
-
+
/**
* launch the current job with a listener that will launch the waiting job on completion
*/
@@ -63,11 +58,11 @@ private void launchCurrent(){
current.schedule();
}
}
-
+
private class ScheduleNextListener extends JobChangeAdapter {
@Override
public void done(IJobChangeEvent event) {
- synchronized (lock) {
+ synchronized (SingleJobQueue.this) {
// we're not running
current=null;
// we have a job waiting, let's run it
@@ -79,5 +74,5 @@ public void done(IJobChangeEvent event) {
}
}
}
-
+
}

0 comments on commit 3e6bd3d

Please sign in to comment.