Lines Matching refs:vc

36 void DRD_(vc_reserve)(VectorClock* const vc, const unsigned new_capacity);
42 * Initialize the memory 'vc' points at as a vector clock with size 'size'.
46 void DRD_(vc_init)(VectorClock* const vc,
50 tl_assert(vc);
51 vc->size = 0;
52 vc->capacity = 0;
53 vc->vc = 0;
54 DRD_(vc_reserve)(vc, size);
55 tl_assert(size == 0 || vc->vc != 0);
58 VG_(memcpy)(vc->vc, vcelem, size * sizeof(vcelem[0]));
59 vc->size = size;
63 /** Reset vc to the empty vector clock. */
64 void DRD_(vc_cleanup)(VectorClock* const vc)
66 DRD_(vc_reserve)(vc, 0);
72 DRD_(vc_init)(new, rhs->vc, rhs->size);
82 /** Increment the clock of thread 'tid' in vector clock 'vc'. */
83 void DRD_(vc_increment)(VectorClock* const vc, DrdThreadId const tid)
86 for (i = 0; i < vc->size; i++)
88 if (vc->vc[i].threadid == tid)
90 typeof(vc->vc[i].count) const oldcount = vc->vc[i].count;
91 vc->vc[i].count++;
93 tl_assert(oldcount < vc->vc[i].count);
106 DRD_(vc_combine)(vc, &vc2);
136 while (i < result->size && result->vc[i].threadid < rhs->vc[j].threadid)
139 result->vc[i].count = 0;
146 if (result->vc[i].threadid <= rhs->vc[j].threadid)
149 /* minimum of vc[i].count and vc[j].count. */
150 tl_assert(result->vc[i].threadid == rhs->vc[j].threadid);
151 if (rhs->vc[j].count < result->vc[i].count)
153 result->vc[i].count = rhs->vc[j].count;
178 while (j < rhs->size && rhs->vc[j].threadid < result->vc[i].threadid)
182 if (result->vc[i].threadid == rhs->vc[j].threadid)
198 /* First of all, skip those clocks in result->vc[] for which there */
199 /* is no corresponding clock in rhs->vc[]. */
200 while (i < result->size && result->vc[i].threadid < rhs->vc[j].threadid)
204 /* If the end of *result is met, append rhs->vc[j] to *result. */
208 result->vc[i] = rhs->vc[j];
210 /* If clock rhs->vc[j] is not in *result, insert it. */
211 else if (result->vc[i].threadid > rhs->vc[j].threadid)
216 result->vc[k] = result->vc[k - 1];
219 result->vc[i] = rhs->vc[j];
222 /* result->vc[i].threadid == rhs->vc[j].threadid. Compute the maximum. */
225 tl_assert(result->vc[i].threadid == rhs->vc[j].threadid);
226 if (rhs->vc[j].count > result->vc[i].count)
228 result->vc[i].count = rhs->vc[j].count;
236 /** Print the contents of vector clock 'vc'. */
237 void DRD_(vc_print)(const VectorClock* const vc)
241 if ((str = DRD_(vc_aprint)(vc)) != NULL)
249 * Print the contents of vector clock 'vc' to a newly allocated string.
252 HChar* DRD_(vc_aprint)(const VectorClock* const vc)
259 tl_assert(vc);
262 str = VG_(realloc)("drd.vc.aprint.1", str, reserved);
266 for (i = 0; i < vc->size; i++)
268 tl_assert(vc->vc);
272 str = VG_(realloc)("drd.vc.aprint.2", str, reserved);
278 vc->vc[i].threadid, vc->vc[i].count);
295 void DRD_(vc_check)(const VectorClock* const vc)
298 tl_assert(vc->size <= vc->capacity);
299 for (i = 1; i < vc->size; i++)
301 tl_assert(vc->vc[i-1].threadid < vc->vc[i].threadid);
306 * Change the size of the memory block pointed at by vc->vc.
311 void DRD_(vc_reserve)(VectorClock* const vc, const unsigned new_capacity)
313 tl_assert(vc);
314 tl_assert(vc->capacity > VC_PREALLOCATED
315 || vc->vc == 0
316 || vc->vc == vc->preallocated);
318 if (new_capacity > vc->capacity)
320 if (vc->vc && vc->capacity > VC_PREALLOCATED)
322 tl_assert(vc->vc
323 && vc->vc != vc->preallocated
324 && vc->capacity > VC_PREALLOCATED);
325 vc->vc = VG_(realloc)("drd.vc.vr.1",
326 vc->vc, new_capacity * sizeof(vc->vc[0]));
328 else if (vc->vc && new_capacity > VC_PREALLOCATED)
330 tl_assert((vc->vc == 0 || vc->vc == vc->preallocated)
332 && vc->capacity <= VC_PREALLOCATED);
333 vc->vc = VG_(malloc)("drd.vc.vr.2",
334 new_capacity * sizeof(vc->vc[0]));
335 VG_(memcpy)(vc->vc, vc->preallocated,
336 vc->capacity * sizeof(vc->vc[0]));
338 else if (vc->vc)
340 tl_assert(vc->vc == vc->preallocated
342 && vc->capacity <= VC_PREALLOCATED);
346 tl_assert(vc->vc == 0
348 && vc->capacity == 0);
349 vc->vc = VG_(malloc)("drd.vc.vr.3",
350 new_capacity * sizeof(vc->vc[0]));
354 tl_assert(vc->vc == 0
356 && vc->capacity == 0);
357 vc->vc = vc->preallocated;
359 vc->capacity = new_capacity;
361 else if (new_capacity == 0 && vc->vc)
363 if (vc->capacity > VC_PREALLOCATED)
364 VG_(free)(vc->vc);
365 vc->vc = 0;
366 vc->capacity = 0;
369 tl_assert(new_capacity == 0 || vc->vc != 0);
370 tl_assert(vc->capacity > VC_PREALLOCATED
371 || vc->vc == 0
372 || vc->vc == vc->preallocated);