]> git.cworth.org Git - apitrace/commitdiff
replay: Fix --loop to work when --singlethread is in effect
authorCarl Worth <cworth@cworth.org>
Mon, 15 Apr 2013 17:55:41 +0000 (10:55 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 15 Apr 2013 17:55:41 +0000 (10:55 -0700)
The original implementation of --loop was made only to the code
implementing multi-threaded replay, (the RelayRunner class and
friends), so that when --singlethread is in effect, the --loop option
has no effect.

This commit fixes the bug by copying the --loop logic to the
single-threaded case as well.

Thanks to Peter Lohrmann for reporting the bug.

retrace/retrace_main.cpp

index 0c358e185517a80e08973a23666a3ad89c62379c..fd45e782703dbf0fa14d5ca46afcba7bb268ab6b 100644 (file)
@@ -517,10 +517,42 @@ mainLoop() {
 
     if (singleThread) {
         trace::Call *call;
-        while ((call = parser.parse_call())) {
+
+        call = parser.parse_call();
+
+        /* If the user wants to loop we need to get a bookmark target. We
+         * usually get this after replaying a call that ends a frame, but
+         * for a trace that has only one frame we need to get it at the
+         * beginning. */
+        if (loopOnFinish) {
+            parser.getBookmark(lastFrameStart);
+        }
+
+        do {
+            bool callEndsFrame = false;
+            static trace::ParseBookmark frameStart;
+
+            if (loopOnFinish && call->flags & trace::CALL_FLAG_END_FRAME) {
+                callEndsFrame = true;
+                parser.getBookmark(frameStart);
+            }
+
             retraceCall(call);
             delete call;
-        };
+            call = parser.parse_call();
+
+            /* Restart last frame if looping is requested. */
+            if (loopOnFinish) {
+                if (!call) {
+                    parser.setBookmark(lastFrameStart);
+                    call = parser.parse_call();
+                } else if (callEndsFrame) {
+                    lastFrameStart = frameStart;
+                }
+            }
+
+        } while (call);
+
         flushRendering();
     } else {
         RelayRace race;