From: Bart Van Assche Date: Sun, 6 Apr 2008 14:57:37 +0000 (+0000) Subject: Added vc_combine2(). X-Git-Tag: svn/VALGRIND_3_4_0~745 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=279cdb1990f7f875f8c7d2de80949a721f010196;p=thirdparty%2Fvalgrind.git Added vc_combine2(). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7854 --- diff --git a/exp-drd/drd_vc.c b/exp-drd/drd_vc.c index d4ca878fe2..cefc3fa0c6 100644 --- a/exp-drd/drd_vc.c +++ b/exp-drd/drd_vc.c @@ -177,11 +177,24 @@ void vc_min(VectorClock* const result, const VectorClock* const rhs) */ void vc_combine(VectorClock* const result, const VectorClock* const rhs) +{ + vc_combine2(result, rhs, -1); +} + +/** Compute elementwise maximum. + * + * @return True if *result and *rhs are equal, or if *result and *rhs only + * differ in the component with thread ID tid. + */ +Bool vc_combine2(VectorClock* const result, + const VectorClock* const rhs, + const ThreadId tid) { unsigned i; unsigned j; unsigned shared; unsigned new_size; + Bool almost_equal = True; tl_assert(result); tl_assert(rhs); @@ -211,13 +224,27 @@ void vc_combine(VectorClock* const result, i = 0; for (j = 0; j < rhs->size; j++) { + /* First of all, skip those clocks in result->vc[] for which there */ + /* is no corresponding clock in rhs->vc[]. */ while (i < result->size && result->vc[i].threadid < rhs->vc[j].threadid) + { + if (result->vc[i].threadid != tid) + { + almost_equal = False; + } i++; + } + /* If the end of *result is met, append rhs->vc[j] to *result. */ if (i >= result->size) { result->size++; result->vc[i] = rhs->vc[j]; + if (result->vc[i].threadid != tid) + { + almost_equal = False; + } } + /* If clock rhs->vc[j] is not in *result, insert it. */ else if (result->vc[i].threadid > rhs->vc[j].threadid) { unsigned k; @@ -227,10 +254,21 @@ void vc_combine(VectorClock* const result, } result->size++; result->vc[i] = rhs->vc[j]; + if (result->vc[i].threadid != tid) + { + almost_equal = False; + } } + /* Otherwise, both *result and *rhs have a clock for thread */ + /* result->vc[i].threadid == rhs->vc[j].threadid. Compute the maximum. */ else { tl_assert(result->vc[i].threadid == rhs->vc[j].threadid); + if (result->vc[i].threadid != tid + && rhs->vc[j].count != result->vc[i].count) + { + almost_equal = False; + } if (rhs->vc[j].count > result->vc[i].count) { result->vc[i].count = rhs->vc[j].count; @@ -239,6 +277,8 @@ void vc_combine(VectorClock* const result, } vc_check(result); tl_assert(result->size == new_size); + + return almost_equal; } void vc_print(const VectorClock* const vc)