execution: bugfix - resolved promises should propagate synchronization
[cdsspec-compiler.git] / clockvector.cc
index 14bb809dabddb051358e27776a0896ef978c62a5..0b325281007e35505f993c2f9798f5b02765621c 100644 (file)
@@ -1,7 +1,6 @@
 #include <cstring>
 #include <stdlib.h>
 
-#include "model.h"
 #include "action.h"
 #include "clockvector.h"
 #include "common.h"
  */
 ClockVector::ClockVector(ClockVector *parent, ModelAction *act)
 {
-       num_threads = model->get_num_threads();
+       ASSERT(act);
+       num_threads = int_to_id(act->get_tid()) + 1;
+       if (parent && parent->num_threads > num_threads)
+               num_threads = parent->num_threads;
+
        clock = (modelclock_t *)snapshot_calloc(num_threads, sizeof(int));
        if (parent)
                std::memcpy(clock, parent->clock, parent->num_threads * sizeof(modelclock_t));
 
-       if (act)
-               clock[id_to_int(act->get_tid())] = act->get_seq_number();
+       clock[id_to_int(act->get_tid())] = act->get_seq_number();
 }
 
 /** @brief Destructor */
@@ -37,10 +39,10 @@ ClockVector::~ClockVector()
  * resulting vector length will be the maximum length of the two being merged.
  * @param cv is the ClockVector being merged into this vector.
  */
-void ClockVector::merge(const ClockVector *cv)
+bool ClockVector::merge(const ClockVector *cv)
 {
        ASSERT(cv != NULL);
-
+       bool changed = false;
        if (cv->num_threads > num_threads) {
                clock = (modelclock_t *)snapshot_realloc(clock, cv->num_threads * sizeof(modelclock_t));
                for (int i = num_threads; i < cv->num_threads; i++)
@@ -50,8 +52,12 @@ void ClockVector::merge(const ClockVector *cv)
 
        /* Element-wise maximum */
        for (int i = 0; i < cv->num_threads; i++)
-               if (cv->clock[i] > clock[i])
+               if (cv->clock[i] > clock[i]) {
                        clock[i] = cv->clock[i];
+                       changed = true;
+               }
+       
+       return changed;
 }
 
 /**