Skip to content
Snippets Groups Projects
Commit ac7a9084 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

make sure we don't enqueue tasks twice, the non-hacky way.

parent 4bdb5527
Branches
Tags
2 merge requests!136Master,!66Dynamic unlocks
...@@ -65,7 +65,7 @@ void scheduler_addunlock(struct scheduler *s, struct task *ta, ...@@ -65,7 +65,7 @@ void scheduler_addunlock(struct scheduler *s, struct task *ta,
ta = ta->unlock_tasks[task_maxunlock]; ta = ta->unlock_tasks[task_maxunlock];
/* Get the index of the next free task. */ /* Get the index of the next free task. */
int ind = atomic_inc(&ta->nr_unlock_tasks); const int ind = atomic_inc(&ta->nr_unlock_tasks);
/* Is there room in this task? */ /* Is there room in this task? */
if (ind < task_maxunlock) { if (ind < task_maxunlock) {
...@@ -894,7 +894,7 @@ void scheduler_start(struct scheduler *s, unsigned int mask) { ...@@ -894,7 +894,7 @@ void scheduler_start(struct scheduler *s, unsigned int mask) {
/* Clear all the waits and rids. */ /* Clear all the waits and rids. */
// ticks tic = getticks(); // ticks tic = getticks();
for (int k = 0; k < s->nr_tasks; k++) { for (int k = 0; k < s->nr_tasks; k++) {
s->tasks[k].wait = 0; s->tasks[k].wait = 1;
s->tasks[k].rid = -1; s->tasks[k].rid = -1;
} }
...@@ -934,14 +934,13 @@ void scheduler_start(struct scheduler *s, unsigned int mask) { ...@@ -934,14 +934,13 @@ void scheduler_start(struct scheduler *s, unsigned int mask) {
/* Loop over the tasks and enqueue whoever is ready. */ /* Loop over the tasks and enqueue whoever is ready. */
// tic = getticks(); // tic = getticks();
for (int k = 0; k < nr_tasks; k++) { for (int k = 0; k < s->nr_tasks; k++) {
t = &tasks[tid[k]]; t = &tasks[tid[k]];
if (((1 << t->type) & s->mask) && !t->skip) { if (atomic_dec(&t->wait) == 1 &&
if (t->wait == 0) { ((1 << t->type) & s->mask) &&
scheduler_enqueue(s, t); !t->skip) {
pthread_cond_broadcast(&s->sleep_cond); scheduler_enqueue(s, t);
} else pthread_cond_broadcast(&s->sleep_cond);
break;
} }
} }
// message( "enqueueing tasks took %.3f ms." , (double)( getticks() - tic ) / // message( "enqueueing tasks took %.3f ms." , (double)( getticks() - tic ) /
...@@ -962,9 +961,11 @@ void scheduler_enqueue(struct scheduler *s, struct task *t) { ...@@ -962,9 +961,11 @@ void scheduler_enqueue(struct scheduler *s, struct task *t) {
int err; int err;
#endif #endif
/* Fail if this task has already been enqueued before. */
if (t->rid >= 0) error("Task has already been enqueued.");
/* Ignore skipped tasks and tasks not in the mask. */ /* Ignore skipped tasks and tasks not in the mask. */
if (t->skip || ((1 << t->type) & ~(s->mask) && t->type != task_type_link) || if (t->skip || ((1 << t->type) & ~(s->mask) && t->type != task_type_link)) {
atomic_cas(&t->rid, -1, 0) != -1) {
return; return;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment