Remove some OpenBSD time variable warnings.

Since time is a function OpenBSD does not like us using a variable
named time. This patch fixes that in the sys_queue.c file.
This commit is contained in:
Cary R 2011-04-20 19:41:19 -07:00 committed by Stephen Williams
parent 8e4008ae19
commit dfedd3dda1
1 changed files with 48 additions and 46 deletions

View File

@ -56,12 +56,12 @@
/* /*
* Routine to add the given time to the the total time (high/low). * Routine to add the given time to the the total time (high/low).
*/ */
void add_to_wait_time(uint64_t *high, uint64_t *low, uint64_t time) void add_to_wait_time(uint64_t *high, uint64_t *low, uint64_t c_time)
{ {
uint64_t carry = 0U; uint64_t carry = 0U;
if ((UINT64_MAX - *low) < time) carry = 1U; if ((UINT64_MAX - *low) < c_time) carry = 1U;
*low += time; *low += c_time;
assert((carry == 0U) || (*high < UINT64_MAX)); assert((carry == 0U) || (*high < UINT64_MAX));
*high += carry; *high += carry;
} }
@ -228,7 +228,7 @@ static unsigned add_to_queue(int64_t idx, p_vpi_vecval job,
PLI_INT32 elems = base[idx].elems; PLI_INT32 elems = base[idx].elems;
PLI_INT32 loc; PLI_INT32 loc;
s_vpi_time cur_time; s_vpi_time cur_time;
uint64_t time; uint64_t c_time;
assert(elems <= length); assert(elems <= length);
@ -255,10 +255,10 @@ static unsigned add_to_queue(int64_t idx, p_vpi_vecval job,
/* Save the current time with this entry for the statistics. */ /* Save the current time with this entry for the statistics. */
cur_time.type = vpiSimTime; cur_time.type = vpiSimTime;
vpi_get_time(NULL, &cur_time); vpi_get_time(NULL, &cur_time);
time = cur_time.high; c_time = cur_time.high;
time <<= 32; c_time <<= 32;
time |= cur_time.low; c_time |= cur_time.low;
base[idx].queue[loc].time = time; base[idx].queue[loc].time = c_time;
/* Increment the maximum length if needed. */ /* Increment the maximum length if needed. */
if (base[idx].max_len == elems) base[idx].max_len += 1; if (base[idx].max_len == elems) base[idx].max_len += 1;
@ -266,8 +266,8 @@ static unsigned add_to_queue(int64_t idx, p_vpi_vecval job,
/* Update the inter-arrival statistics. */ /* Update the inter-arrival statistics. */
assert(base[idx].number_of_adds < UINT64_MAX); assert(base[idx].number_of_adds < UINT64_MAX);
base[idx].number_of_adds += 1; base[idx].number_of_adds += 1;
if (base[idx].number_of_adds == 1) base[idx].first_add_time = time; if (base[idx].number_of_adds == 1) base[idx].first_add_time = c_time;
base[idx].latest_add_time = time; base[idx].latest_add_time = c_time;
return 0; return 0;
} }
@ -284,7 +284,7 @@ static unsigned remove_from_queue(int64_t idx, p_vpi_vecval job,
PLI_INT32 elems = base[idx].elems - 1; PLI_INT32 elems = base[idx].elems - 1;
PLI_INT32 loc; PLI_INT32 loc;
s_vpi_time cur_time; s_vpi_time cur_time;
uint64_t time; uint64_t c_time;
assert(elems >= -1); assert(elems >= -1);
@ -313,21 +313,21 @@ static unsigned remove_from_queue(int64_t idx, p_vpi_vecval job,
/* Get the current simulation time. */ /* Get the current simulation time. */
cur_time.type = vpiSimTime; cur_time.type = vpiSimTime;
vpi_get_time(NULL, &cur_time); vpi_get_time(NULL, &cur_time);
time = cur_time.high; c_time = cur_time.high;
time <<= 32; c_time <<= 32;
time |= cur_time.low; c_time |= cur_time.low;
/* Set the shortest wait time if needed. */ /* Set the shortest wait time if needed. */
assert(time >= base[idx].queue[loc].time); assert(c_time >= base[idx].queue[loc].time);
time -= base[idx].queue[loc].time; c_time -= base[idx].queue[loc].time;
if (time < base[idx].shortest_wait_time) { if (c_time < base[idx].shortest_wait_time) {
base[idx].shortest_wait_time = time; base[idx].shortest_wait_time = c_time;
} }
base[idx].have_shortest_statistic = 1; base[idx].have_shortest_statistic = 1;
/* Add the current element wait time to the total wait time. */ /* Add the current element wait time to the total wait time. */
add_to_wait_time(&(base[idx].wait_time_high), &(base[idx].wait_time_low), add_to_wait_time(&(base[idx].wait_time_high), &(base[idx].wait_time_low),
time); c_time);
return 0; return 0;
} }
@ -356,20 +356,21 @@ static PLI_INT32 get_maximum_queue_length(int64_t idx)
static uint64_t get_longest_queue_time(int64_t idx) static uint64_t get_longest_queue_time(int64_t idx)
{ {
s_vpi_time cur_time; s_vpi_time cur_time;
uint64_t time; uint64_t c_time;
/* Get the current simulation time. */ /* Get the current simulation time. */
cur_time.type = vpiSimTime; cur_time.type = vpiSimTime;
vpi_get_time(NULL, &cur_time); vpi_get_time(NULL, &cur_time);
time = cur_time.high; c_time = cur_time.high;
time <<= 32; c_time <<= 32;
time |= cur_time.low; c_time |= cur_time.low;
/* Subtract the element with the longest time (the head) from the /* Subtract the element with the longest time (the head) from the
* current time. */ * current time. */
time -= base[idx].queue[base[idx].head].time; assert(c_time >= base[idx].queue[base[idx].head].time);
c_time -= base[idx].queue[base[idx].head].time;
return time; return c_time;
} }
/* /*
@ -428,20 +429,21 @@ static uint64_t get_average_wait_time(int64_t idx)
uint64_t high = base[idx].wait_time_high; uint64_t high = base[idx].wait_time_high;
uint64_t low = base[idx].wait_time_low; uint64_t low = base[idx].wait_time_low;
s_vpi_time cur_time; s_vpi_time cur_time;
uint64_t time, add_time; uint64_t c_time, add_time;
/* Get the current simulation time. */ /* Get the current simulation time. */
cur_time.type = vpiSimTime; cur_time.type = vpiSimTime;
vpi_get_time(NULL, &cur_time); vpi_get_time(NULL, &cur_time);
time = cur_time.high; c_time = cur_time.high;
time <<= 32; c_time <<= 32;
time |= cur_time.low; c_time |= cur_time.low;
/* For each element still in the queue, add its wait time to the /* For each element still in the queue, add its wait time to the
* total wait time. */ * total wait time. */
for (count = 0; count < elems; count += 1) { for (count = 0; count < elems; count += 1) {
add_time = base[idx].queue[loc].time; add_time = base[idx].queue[loc].time;
add_to_wait_time(&high, &low, time-add_time); assert(c_time >= add_time);
add_to_wait_time(&high, &low, c_time-add_time);
/* Move to the next element. */ /* Move to the next element. */
loc += 1; loc += 1;
@ -696,7 +698,7 @@ static void fill_variable_with_x(vpiHandle var)
* of the normal OK. The value is a time and needs to be scaled to the * of the normal OK. The value is a time and needs to be scaled to the
* calling module's timescale. * calling module's timescale.
*/ */
static PLI_INT32 fill_variable_with_scaled_time(vpiHandle var, uint64_t time) static PLI_INT32 fill_variable_with_scaled_time(vpiHandle var, uint64_t c_time)
{ {
s_vpi_value val; s_vpi_value val;
PLI_INT32 size = vpi_get(vpiSize, var); PLI_INT32 size = vpi_get(vpiSize, var);
@ -720,9 +722,9 @@ static PLI_INT32 fill_variable_with_scaled_time(vpiHandle var, uint64_t time)
scale *= 10; scale *= 10;
units -= 1; units -= 1;
} }
frac = time % scale; frac = c_time % scale;
time /= scale; c_time /= scale;
if ((scale > 1) && (frac >= scale/2)) time += 1; if ((scale > 1) && (frac >= scale/2)) c_time += 1;
/* Find the maximum value + 1 that can be put into the variable. */ /* Find the maximum value + 1 that can be put into the variable. */
if (size < 64) { if (size < 64) {
@ -733,7 +735,7 @@ static PLI_INT32 fill_variable_with_scaled_time(vpiHandle var, uint64_t time)
/* If the time is too big to fit then return the maximum positive /* If the time is too big to fit then return the maximum positive
* value and that the value overflowed. Otherwise, return the time * value and that the value overflowed. Otherwise, return the time
* and OK. */ * and OK. */
if (max_val && (time >= max_val)) { if (max_val && (c_time >= max_val)) {
/* For a single word only the MSB is cleared if signed. */ /* For a single word only the MSB is cleared if signed. */
if (words == 1) { if (words == 1) {
if (is_signed) { if (is_signed) {
@ -765,9 +767,9 @@ static PLI_INT32 fill_variable_with_scaled_time(vpiHandle var, uint64_t time)
/* Add the time to the vector. */ /* Add the time to the vector. */
switch (words) { switch (words) {
default: default:
val_ptr[1].aval = (time >> 32) & 0xffffffff; val_ptr[1].aval = (c_time >> 32) & 0xffffffff;
case 1: case 1:
val_ptr[0].aval = time & 0xffffffff; val_ptr[0].aval = c_time & 0xffffffff;
} }
rtn = IVL_QUEUE_OK; rtn = IVL_QUEUE_OK;
} }
@ -1324,8 +1326,8 @@ static PLI_INT32 sys_q_exam_calltf(PLI_BYTE8 *name)
fill_variable_with_x(value); fill_variable_with_x(value);
rtn = IVL_QUEUE_NO_STATISTICS; rtn = IVL_QUEUE_NO_STATISTICS;
} else { } else {
uint64_t time = get_mean_interarrival_time(idx); uint64_t ia_time = get_mean_interarrival_time(idx);
rtn = fill_variable_with_scaled_time(value, time); rtn = fill_variable_with_scaled_time(value, ia_time);
} }
break; break;
/* The maximum queue length. */ /* The maximum queue length. */
@ -1340,8 +1342,8 @@ static PLI_INT32 sys_q_exam_calltf(PLI_BYTE8 *name)
fill_variable_with_x(value); fill_variable_with_x(value);
rtn = IVL_QUEUE_NO_STATISTICS; rtn = IVL_QUEUE_NO_STATISTICS;
} else { } else {
uint64_t time = get_shortest_wait_time(idx); uint64_t sw_time = get_shortest_wait_time(idx);
rtn = fill_variable_with_scaled_time(value, time); rtn = fill_variable_with_scaled_time(value, sw_time);
} }
break; break;
/* The longest wait time for elements still in the queue. */ /* The longest wait time for elements still in the queue. */
@ -1350,8 +1352,8 @@ static PLI_INT32 sys_q_exam_calltf(PLI_BYTE8 *name)
fill_variable_with_x(value); fill_variable_with_x(value);
rtn = IVL_QUEUE_NO_STATISTICS; rtn = IVL_QUEUE_NO_STATISTICS;
} else { } else {
uint64_t time = get_longest_queue_time(idx); uint64_t lq_time = get_longest_queue_time(idx);
rtn = fill_variable_with_scaled_time(value, time); rtn = fill_variable_with_scaled_time(value, lq_time);
} }
break; break;
/* The average queue wait time. */ /* The average queue wait time. */
@ -1360,8 +1362,8 @@ static PLI_INT32 sys_q_exam_calltf(PLI_BYTE8 *name)
fill_variable_with_x(value); fill_variable_with_x(value);
rtn = IVL_QUEUE_NO_STATISTICS; rtn = IVL_QUEUE_NO_STATISTICS;
} else { } else {
uint64_t time = get_average_wait_time(idx); uint64_t aw_time = get_average_wait_time(idx);
rtn = fill_variable_with_scaled_time(value, time); rtn = fill_variable_with_scaled_time(value, aw_time);
} }
break; break;
default: default: