X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=clockvector.cc;h=5e25e00f1ac625fc0c116b563dd83ffd4040d296;hb=e45f16f22c8e36652a8f11f6f085ac43da24e1a8;hp=c86995bc9bbb555cf9e2381d1b7df91036330a46;hpb=63b2c687570085f2a87b6a659d26608228af1ee0;p=c11tester.git diff --git a/clockvector.cc b/clockvector.cc index c86995bc..5e25e00f 100644 --- a/clockvector.cc +++ b/clockvector.cc @@ -18,8 +18,7 @@ */ ClockVector::ClockVector(ClockVector *parent, const ModelAction *act) { - ASSERT(act); - num_threads = int_to_id(act->get_tid()) + 1; + num_threads = act != NULL ? int_to_id(act->get_tid()) + 1 : 0; if (parent && parent->num_threads > num_threads) num_threads = parent->num_threads; @@ -27,7 +26,8 @@ ClockVector::ClockVector(ClockVector *parent, const ModelAction *act) if (parent) std::memcpy(clock, parent->clock, parent->num_threads * sizeof(modelclock_t)); - clock[id_to_int(act->get_tid())] = act->get_seq_number(); + if (act != NULL) + clock[id_to_int(act->get_tid())] = act->get_seq_number(); } /** @brief Destructor */ @@ -62,6 +62,32 @@ bool ClockVector::merge(const ClockVector *cv) return changed; } +/** + * Merge a clock vector into this vector, using a pairwise comparison. The + * resulting vector length will be the maximum length of the two being merged. + * @param cv is the ClockVector being merged into this vector. + */ +bool ClockVector::minmerge(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++) + clock[i] = 0; + num_threads = cv->num_threads; + } + + /* Element-wise maximum */ + for (int i = 0;i < cv->num_threads;i++) + if (cv->clock[i] < clock[i]) { + clock[i] = cv->clock[i]; + changed = true; + } + + return changed; +} + /** * Check whether this vector's thread has synchronized with another action's * thread. This effectively checks the happens-before relation (or actually,