Lines Matching defs: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;
62 DRD_(vc_check)(vc);
66 /** Reset vc to the empty vector clock. */
67 void DRD_(vc_cleanup)(VectorClock* const vc)
69 DRD_(vc_reserve)(vc, 0);
75 DRD_(vc_init)(new, rhs->vc, rhs->size);
85 /** Increment the clock of thread 'tid' in vector clock 'vc'. */
86 void DRD_(vc_increment)(VectorClock* const vc, DrdThreadId const tid)
89 for (i = 0; i < vc->size; i++)
91 if (vc->vc[i].threadid == tid)
93 typeof(vc->vc[i].count) const oldcount = vc->vc[i].count;
94 vc->vc[i].count++;
96 tl_assert(oldcount < vc->vc[i].count);
109 DRD_(vc_combine)(vc, &vc2);
139 while (i < result->size && result->vc[i].threadid < rhs->vc[j].threadid)
142 result->vc[i].count = 0;
149 if (result->vc[i].threadid <= rhs->vc[j].threadid)
152 /* minimum of vc[i].count and vc[j].count. */
153 tl_assert(result->vc[i].threadid == rhs->vc[j].threadid);
154 if (rhs->vc[j].count < result->vc[i].count)
156 result->vc[i].count = rhs->vc[j].count;
181 while (j < rhs->size && rhs->vc[j].threadid < result->vc[i].threadid)
185 if (result->vc[i].threadid == rhs->vc[j].threadid)
201 /* First of all, skip those clocks in result->vc[] for which there */
202 /* is no corresponding clock in rhs->vc[]. */
203 while (i < result->size && result->vc[i].threadid < rhs->vc[j].threadid)
207 /* If the end of *result is met, append rhs->vc[j] to *result. */
211 result->vc[i] = rhs->vc[j];
213 /* If clock rhs->vc[j] is not in *result, insert it. */
214 else if (result->vc[i].threadid > rhs->vc[j].threadid)
219 result->vc[k] = result->vc[k - 1];
222 result->vc[i] = rhs->vc[j];
225 /* result->vc[i].threadid == rhs->vc[j].threadid. Compute the maximum. */
228 tl_assert(result->vc[i].threadid == rhs->vc[j].threadid);
229 if (rhs->vc[j].count > result->vc[i].count)
231 result->vc[i].count = rhs->vc[j].count;
239 /** Print the contents of vector clock 'vc'. */
240 void DRD_(vc_print)(const VectorClock* const vc)
244 if ((str = DRD_(vc_aprint)(vc)) != NULL)
252 * Print the contents of vector clock 'vc' to a newly allocated string.
255 HChar* DRD_(vc_aprint)(const VectorClock* const vc)
262 tl_assert(vc);
265 str = VG_(realloc)("drd.vc.aprint.1", str, reserved);
269 for (i = 0; i < vc->size; i++)
271 tl_assert(vc->vc);
275 str = VG_(realloc)("drd.vc.aprint.2", str, reserved);
281 vc->vc[i].threadid, vc->vc[i].count);
298 void DRD_(vc_check)(const VectorClock* const vc)
302 tl_assert(vc->size <= vc->capacity);
304 for (i = 1; i < vc->size; i++)
305 tl_assert(vc->vc[i-1].threadid < vc->vc[i].threadid);
309 * Change the size of the memory block pointed at by vc->vc.
314 void DRD_(vc_reserve)(VectorClock* const vc, const unsigned new_capacity)
316 tl_assert(vc);
317 tl_assert(vc->capacity > VC_PREALLOCATED
318 || vc->vc == 0
319 || vc->vc == vc->preallocated);
321 if (new_capacity > vc->capacity)
323 if (vc->vc && vc->capacity > VC_PREALLOCATED)
325 tl_assert(vc->vc
326 && vc->vc != vc->preallocated
327 && vc->capacity > VC_PREALLOCATED);
328 vc->vc = VG_(realloc)("drd.vc.vr.1",
329 vc->vc, new_capacity * sizeof(vc->vc[0]));
331 else if (vc->vc && new_capacity > VC_PREALLOCATED)
333 tl_assert((vc->vc == 0 || vc->vc == vc->preallocated)
335 && vc->capacity <= VC_PREALLOCATED);
336 vc->vc = VG_(malloc)("drd.vc.vr.2",
337 new_capacity * sizeof(vc->vc[0]));
338 VG_(memcpy)(vc->vc, vc->preallocated,
339 vc->capacity * sizeof(vc->vc[0]));
341 else if (vc->vc)
343 tl_assert(vc->vc == vc->preallocated
345 && vc->capacity <= VC_PREALLOCATED);
349 tl_assert(vc->vc == 0
351 && vc->capacity == 0);
352 vc->vc = VG_(malloc)("drd.vc.vr.3",
353 new_capacity * sizeof(vc->vc[0]));
357 tl_assert(vc->vc == 0
359 && vc->capacity == 0);
360 vc->vc = vc->preallocated;
362 vc->capacity = new_capacity;
364 else if (new_capacity == 0 && vc->vc)
366 if (vc->capacity > VC_PREALLOCATED)
367 VG_(free)(vc->vc);
368 vc->vc = 0;
369 vc->capacity = 0;
372 tl_assert(new_capacity == 0 || vc->vc != 0);
373 tl_assert(vc->capacity > VC_PREALLOCATED
374 || vc->vc == 0
375 || vc->vc == vc->preallocated);