]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
runtime: mark scratch unused only when no further scratch references
authorWang, Xiang W <xiang.w.wang@intel.com>
Sun, 31 Mar 2019 15:19:48 +0000 (11:19 -0400)
committerWang Xiang W <xiang.w.wang@intel.com>
Wed, 10 Apr 2019 10:52:55 +0000 (06:52 -0400)
src/runtime.c

index 4934631143617dc1bc607df718d9fe8f1f015d09..cfcd0f7c88b1729b675d73ab19f408836a0ca4b6 100644 (file)
@@ -457,11 +457,11 @@ set_retval:
 
     if (rose->flushCombProgramOffset) {
         if (roseRunFlushCombProgram(rose, scratch, ~0ULL) == MO_HALT_MATCHING) {
-            unmarkScratchInUse(scratch);
             if (unlikely(internal_matching_error(scratch))) {
+                unmarkScratchInUse(scratch);
                 return HS_UNKNOWN_ERROR;
             }
-
+            unmarkScratchInUse(scratch);
             return HS_SCAN_TERMINATED;
         }
     }
@@ -760,10 +760,11 @@ hs_error_t HS_CDECL hs_reset_and_copy_stream(hs_stream_t *to_id,
             return HS_SCRATCH_IN_USE;
         }
         report_eod_matches(to_id, scratch, onEvent, context);
-        unmarkScratchInUse(scratch);
         if (unlikely(internal_matching_error(scratch))) {
+            unmarkScratchInUse(scratch);
             return HS_UNKNOWN_ERROR;
         }
+        unmarkScratchInUse(scratch);
     }
 
     size_t stateSize
@@ -1005,20 +1006,22 @@ hs_error_t HS_CDECL hs_close_stream(hs_stream_t *id, hs_scratch_t *scratch,
             return HS_SCRATCH_IN_USE;
         }
         report_eod_matches(id, scratch, onEvent, context);
-        unmarkScratchInUse(scratch);
         if (unlikely(internal_matching_error(scratch))) {
+            unmarkScratchInUse(scratch);
             return HS_UNKNOWN_ERROR;
         }
+        unmarkScratchInUse(scratch);
     }
 
     if (id->rose->flushCombProgramOffset && !told_to_stop_matching(scratch)) {
         if (roseRunFlushCombProgram(id->rose, scratch, ~0ULL)
             == MO_HALT_MATCHING) {
             scratch->core_info.status |= STATUS_TERMINATED;
-            unmarkScratchInUse(scratch);
             if (unlikely(internal_matching_error(scratch))) {
+                unmarkScratchInUse(scratch);
                 return HS_UNKNOWN_ERROR;
             }
+            unmarkScratchInUse(scratch);
         }
     }
 
@@ -1044,20 +1047,22 @@ hs_error_t HS_CDECL hs_reset_stream(hs_stream_t *id, UNUSED unsigned int flags,
             return HS_SCRATCH_IN_USE;
         }
         report_eod_matches(id, scratch, onEvent, context);
-        unmarkScratchInUse(scratch);
         if (unlikely(internal_matching_error(scratch))) {
+            unmarkScratchInUse(scratch);
             return HS_UNKNOWN_ERROR;
         }
+        unmarkScratchInUse(scratch);
     }
 
     if (id->rose->flushCombProgramOffset && !told_to_stop_matching(scratch)) {
         if (roseRunFlushCombProgram(id->rose, scratch, ~0ULL)
             == MO_HALT_MATCHING) {
             scratch->core_info.status |= STATUS_TERMINATED;
-            unmarkScratchInUse(scratch);
             if (unlikely(internal_matching_error(scratch))) {
+                unmarkScratchInUse(scratch);
                 return HS_UNKNOWN_ERROR;
             }
+            unmarkScratchInUse(scratch);
         }
     }
 
@@ -1273,10 +1278,11 @@ hs_error_t HS_CDECL hs_reset_and_expand_stream(hs_stream_t *to_stream,
             return HS_SCRATCH_IN_USE;
         }
         report_eod_matches(to_stream, scratch, onEvent, context);
-        unmarkScratchInUse(scratch);
         if (unlikely(internal_matching_error(scratch))) {
+            unmarkScratchInUse(scratch);
             return HS_UNKNOWN_ERROR;
         }
+        unmarkScratchInUse(scratch);
     }
 
     if (expand_stream(to_stream, rose, buf, buf_size)) {