ctf: Fix race condition in ctfiterator
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfIterator.java
index 45b163f452648838446c1aabd6bc0e2f29c57b84..8311e7acb8fc351abd3183feab786cb491110e6f 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 2013 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License v1.0 which
@@ -25,7 +25,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
  * @author Matthew Khouzam
  */
 public class CtfIterator extends CTFTraceReader implements ITmfContext,
-        Comparable<CtfIterator>, Cloneable {
+        Comparable<CtfIterator> {
 
     private final CtfTmfTrace ctfTmfTrace;
 
@@ -72,7 +72,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      * @since 2.0
      */
     public CtfIterator(final CtfTmfTrace trace,
-            final CtfLocationData ctfLocationData, final long rank) {
+            final CtfLocationInfo ctfLocationData, final long rank) {
         super(trace.getCTFTrace());
 
         this.ctfTmfTrace = trace;
@@ -101,20 +101,17 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      * @return CtfTmfEvent
      */
     public CtfTmfEvent getCurrentEvent() {
-        final StreamInputReader top = super.prio.peek();
+        final StreamInputReader top = super.getPrio().peek();
         if (top != null) {
-            return new CtfTmfEvent(top.getCurrentEvent(), top.getFilename(),
-                    ctfTmfTrace);
+            return CtfTmfEventFactory.createEvent(top.getCurrentEvent(),
+                    top.getFilename(), ctfTmfTrace);
         }
         return null;
     }
 
-    /* (non-Javadoc)
-     * @see org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader#seek(long)
-     */
     @Override
     public boolean seek(long timestamp) {
-        return seek(new CtfLocationData(timestamp, 0));
+        return seek(new CtfLocationInfo(timestamp, 0));
     }
 
     /**
@@ -125,7 +122,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      * @return boolean
      * @since 2.0
      */
-    public boolean seek(final CtfLocationData ctfLocationData) {
+    public synchronized boolean seek(final CtfLocationInfo ctfLocationData) {
         boolean ret = false;
 
         /* Adjust the timestamp depending on the trace's offset */
@@ -142,11 +139,12 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
          * assign the location index correctly
          */
         long index = 0;
-        if (this.getCurrentEvent() != null) {
-            currTimestamp = this.getCurrentEvent().getTimestamp().getValue();
+        final CtfTmfEvent currentEvent = this.getCurrentEvent();
+        if (currentEvent != null) {
+            currTimestamp = currentEvent.getTimestamp().getValue();
 
             for (long i = 0; i < ctfLocationData.getIndex(); i++) {
-                if (currTimestamp == this.getCurrentEvent().getTimestamp().getValue()) {
+                if (currTimestamp == currentEvent.getTimestamp().getValue()) {
                     index++;
                 } else {
                     index = 0;
@@ -158,7 +156,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
         }
         /* Seek the current location accordingly */
         if (ret) {
-            curLocation = new CtfLocation(new CtfLocationData(getCurrentEvent().getTimestamp().getValue(), index));
+            curLocation = new CtfLocation(new CtfLocationInfo(getCurrentEvent().getTimestamp().getValue(), index));
         } else {
             curLocation = NULL_LOCATION;
         }
@@ -185,11 +183,6 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
         curRank = rank;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.eclipse.linuxtools.tmf.core.trace.TmfContext#clone()
-     */
     @Override
     public CtfIterator clone() {
         CtfIterator clone = null;
@@ -203,8 +196,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      */
     @Override
     public void dispose() {
-        // FIXME add dispose() stuff to CTFTrace and call it here...
-
+        super.dispose();
     }
 
     /**
@@ -255,7 +247,7 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
      * @return boolean successful or not
      */
     @Override
-    public boolean advance() {
+    public synchronized boolean advance() {
         long index = curLocation.getLocationInfo().getIndex();
         long timestamp = curLocation.getLocationInfo().getTimestamp();
         boolean ret = super.advance();
@@ -288,9 +280,6 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
         return 0;
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#hashCode()
-     */
     @Override
     public int hashCode() {
         final int prime = 31;
@@ -303,9 +292,6 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext,
         return result;
     }
 
-    /* (non-Javadoc)
-     * @see java.lang.Object#equals(java.lang.Object)
-     */
     @Override
     public boolean equals(Object obj) {
         if (this == obj) {
This page took 0.025891 seconds and 5 git commands to generate.