Skip to content
Snippets Groups Projects

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

Merged Matthieu Schaller requested to merge short_int_unlocks into master
+ 28
5
Compare changes
  • Side-by-side
  • Inline
+ 28
5
@@ -747,18 +747,34 @@ struct task *scheduler_addtask(struct scheduler *s, enum task_types type,
@@ -747,18 +747,34 @@ struct task *scheduler_addtask(struct scheduler *s, enum task_types type,
void scheduler_set_unlocks(struct scheduler *s) {
void scheduler_set_unlocks(struct scheduler *s) {
/* Store the counts for each task. */
/* Store the counts for each task. */
int *counts;
short int *counts;
if ((counts = (int *)malloc(sizeof(int) * s->nr_tasks)) == NULL)
if ((counts = (short int *)malloc(sizeof(short int) * s->nr_tasks)) == NULL)
error("Failed to allocate temporary counts array.");
error("Failed to allocate temporary counts array.");
bzero(counts, sizeof(int) * s->nr_tasks);
bzero(counts, sizeof(short int) * s->nr_tasks);
for (int k = 0; k < s->nr_unlocks; k++) counts[s->unlock_ind[k]] += 1;
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. */
/* Compute the offset for each unlock block. */
int *offsets;
int *offsets;
if ((offsets = (int *)malloc(sizeof(int) * (s->nr_tasks + 1))) == NULL)
if ((offsets = (int *)malloc(sizeof(int) * (s->nr_tasks + 1))) == NULL)
error("Failed to allocate temporary offsets array.");
error("Failed to allocate temporary offsets array.");
offsets[0] = 0;
offsets[0] = 0;
for (int k = 0; k < s->nr_tasks; k++) offsets[k + 1] = offsets[k] + counts[k];
for (int k = 0; k < s->nr_tasks; k++) {
 
offsets[k + 1] = offsets[k] + counts[k];
 
 
#ifdef SWIFT_DEBUG_CHECKS
 
/* Check that we are not overflowing */
 
if (offsets[k + 1] < 0) error("Task unlock offset array overflowing");
 
#endif
 
}
/* Create and fill a temporary array with the sorted unlocks. */
/* Create and fill a temporary array with the sorted unlocks. */
struct task **unlocks;
struct task **unlocks;
@@ -1031,10 +1047,17 @@ void scheduler_rewait_mapper(void *map_data, int num_elements,
@@ -1031,10 +1047,17 @@ void scheduler_rewait_mapper(void *map_data, int num_elements,
/* Increment the task's own wait counter for the enqueueing. */
/* Increment the task's own wait counter for the enqueueing. */
atomic_inc(&t->wait);
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 */
/* Skip sort tasks that have already been performed */
if (t->type == task_type_sort && t->flags == 0) {
if (t->type == task_type_sort && t->flags == 0) {
error("Empty sort task encountered.");
error("Empty sort task encountered.");
}
}
 
#endif
/* Sets the waits of the dependances */
/* Sets the waits of the dependances */
for (int k = 0; k < t->nr_unlock_tasks; k++) {
for (int k = 0; k < t->nr_unlock_tasks; k++) {
Loading