ctf: Fix seek bug with multi-threaded access
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 21 Jun 2013 20:02:36 +0000 (16:02 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 26 Jun 2013 17:53:53 +0000 (13:53 -0400)
Store the map of event definitions per stream reader, not per
trace. This allows multiple parallel stream readers to work
correctly (same with multiple CtfIterator's).

Fixes bug #405411.

Change-Id: I43e4e05b5d8313410905e90cb23badbd1d54b9f8
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/13994

org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java

index f7b0bad5fa0ec4a1bd8596c28fd5db38384d1bdf..9c3553dc129823e13287a0d0ddb53da3d2394df0 100644 (file)
@@ -138,8 +138,7 @@ public class CTFTrace implements IDefinitionScope {
 
     /** map of all the event types */
     private final Map<Long,HashMap<Long, IEventDeclaration>> eventDecs = new HashMap<Long, HashMap<Long,IEventDeclaration>>();
-    /** map of all the event types */
-    private final Map<StreamInput,HashMap<Long, EventDefinition>> eventDefs = new HashMap<StreamInput, HashMap<Long,EventDefinition>>();
+
     /** map of all the indexes */
     private final Map<StreamInput, StreamInputPacketIndex> indexes = new HashMap<StreamInput, StreamInputPacketIndex>();
 
@@ -276,17 +275,20 @@ public class CTFTrace implements IDefinitionScope {
         return indexes.get(id);
     }
 
+
     /**
      * Gets an event Declaration hashmap for a given StreamInput
-     * @param id the StreamInput
-     * @return the hashmap with the event definitions
+     *
+     * @param id
+     *            the StreamInput
+     * @return an empty hashmap, please see deprecated
      * @since 2.0
+     * @deprecated You should be using {@link StreamInputReader#getEventDefinitions()}
+     *             instead.
      */
+    @Deprecated
     public Map<Long, EventDefinition> getEventDefs(StreamInput id) {
-        if(! eventDefs.containsKey(id)){
-            eventDefs.put(id, new HashMap<Long, EventDefinition>());
-        }
-        return eventDefs.get(id);
+        return new HashMap<Long, EventDefinition>();
     }
 
     /**
index 7076d26719ba5720978a951adf174bae548d6fd2..9bd42b8b71f6482e867e84d688702c9ca091698d 100644 (file)
@@ -15,7 +15,6 @@ import java.io.IOException;
 import java.nio.MappedByteBuffer;
 import java.nio.channels.FileChannel.MapMode;
 import java.util.Collection;
-import java.util.Map;
 
 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
@@ -61,9 +60,6 @@ public class StreamInputPacketReader implements IDefinitionScope {
     /** Stream event context definition.*/
     private final StructDefinition streamEventContextDef;
 
-    /** Maps event ID to event definitions. */
-    private final Map<Long, EventDefinition> events;
-
     /** Reference to the index entry of the current packet. */
     private StreamInputPacketIndexEntry currentPacket = null;
 
@@ -100,7 +96,6 @@ public class StreamInputPacketReader implements IDefinitionScope {
         bitBuffer = new BitBuffer();
         bitBuffer.setByteOrder(streamInputReader.getByteOrder());
 
-        events = streamInputReader.getStreamInput().getStream().getTrace().getEventDefs(streamInputReader.getStreamInput());
         lostSoFar = 0;
 
         /* Create trace packet header definition. */
@@ -140,9 +135,9 @@ public class StreamInputPacketReader implements IDefinitionScope {
         Collection<IEventDeclaration> eventDecls = streamInputReader.getStreamInput().getStream().getEvents().values();
 
         for (IEventDeclaration event : eventDecls) {
-            if (!events.containsKey(event.getId())) {
+            if (!streamInputReader.getEventDefinitions().containsKey(event.getId())) {
                 EventDefinition eventDef = event.createDefinition(streamInputReader);
-                events.put(event.getId(), eventDef);
+                streamInputReader.addEventDefinition(event.getId(), eventDef);
             }
         }
     }
@@ -350,7 +345,7 @@ public class StreamInputPacketReader implements IDefinitionScope {
         }
 
         /* Get the right event definition using the event id. */
-        EventDefinition eventDef = events.get(eventID);
+        EventDefinition eventDef = streamInputReader.getEventDefinitions().get(eventID);
         if (eventDef == null) {
             throw new CTFReaderException("Incorrect event id : " + eventID); //$NON-NLS-1$
         }
index 0c77abef53c098cc05b38cfbbd460aec3e2a3f3e..13bfa922a8a9f067229769598f45e1b7a35ad1b2 100644 (file)
@@ -13,6 +13,9 @@
 package org.eclipse.linuxtools.ctf.core.trace;
 
 import java.nio.ByteOrder;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
@@ -56,6 +59,8 @@ public class StreamInputReader {
 
     private CTFTraceReader parent;
 
+    /** Map of all the event types */
+    private final Map<Long, EventDefinition> eventDefs = new HashMap<Long,EventDefinition>();
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -165,6 +170,30 @@ public class StreamInputReader {
         return streamInput;
     }
 
+    /**
+     * Gets the event definition hashmap for this StreamInput
+     *
+     * @return Unmodifiable map with the event definitions
+     * @since 2.1
+     */
+    public Map<Long, EventDefinition> getEventDefinitions() {
+        return Collections.unmodifiableMap(eventDefs);
+    }
+
+    /**
+     * Add an event definition to this stream input reader.
+     *
+     * @param id
+     *            The id of the event definition. This will overwrite any
+     *            existing definition with the same id.
+     * @param def
+     *            The matching event definition
+     * @since 2.1
+     */
+    public void addEventDefinition(Long id, EventDefinition def) {
+        eventDefs.put(id, def);
+    }
+
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
This page took 0.03673 seconds and 5 git commands to generate.