Commit a1fb04a8 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Use short int consistently for unlocks. Check that the waits and unlocks don't overflow.

parent 80610af7
......@@ -747,15 +747,25 @@ struct task *scheduler_addtask(struct scheduler *s, enum task_types type,
void scheduler_set_unlocks(struct scheduler *s) {
/* Store the counts for each task. */
int *counts;
if ((counts = (int *)malloc(sizeof(int) * s->nr_tasks)) == NULL)
short int *counts;
if ((counts = (short int *)malloc(sizeof(short int) * s->nr_tasks)) == NULL)
error("Failed to allocate temporary counts array.");
bzero(counts, sizeof(int) * s->nr_tasks);
for (int k = 0; k < s->nr_unlocks; k++) counts[s->unlock_ind[k]] += 1;
bzero(counts, sizeof(short int) * s->nr_tasks);
for (int k = 0; k < s->nr_unlocks; k++) {
counts[s->unlock_ind[k]] += 1;
#ifdef SWIFT_DEBUG_CHECKS
/* Check that we are not overflowing */
if (counts[s->unlock_ind[k]] < 0)
error("Task unlocking more than %d other tasks!",
(1 << (sizeof(short int) - 1)) - 1);
#endif
}
/* Compute the offset for each unlock block. */
int *offsets;
if ((offsets = (int *)malloc(sizeof(int) * (s->nr_tasks + 1))) == NULL)
short int *offsets;
if ((offsets = (short int *)malloc(sizeof(short int) * (s->nr_tasks + 1))) ==
NULL)
error("Failed to allocate temporary offsets array.");
offsets[0] = 0;
for (int k = 0; k < s->nr_tasks; k++) offsets[k + 1] = offsets[k] + counts[k];
......@@ -1031,10 +1041,17 @@ void scheduler_rewait_mapper(void *map_data, int num_elements,
/* Increment the task's own wait counter for the enqueueing. */
atomic_inc(&t->wait);
#ifdef SWIFT_DEBUG_CHECKS
/* Check that we don't have more waits that what can be stored. */
if (t->wait < 0)
error("Task unlocked by more than %d tasks!",
(1 << (8 * sizeof(t->wait) - 1)) - 1);
/* Skip sort tasks that have already been performed */
if (t->type == task_type_sort && t->flags == 0) {
error("Empty sort task encountered.");
}
#endif
/* Sets the waits of the dependances */
for (int k = 0; k < t->nr_unlock_tasks; k++) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment