diff --git a/src/qsched.c b/src/qsched.c index 745391d2cf1bd177167634fb953f2693b2901a60..bec536a0572b85d975794c27c8127d73c7ed0c56 100644 --- a/src/qsched.c +++ b/src/qsched.c @@ -537,8 +537,6 @@ void *qsched_getdata(struct qsched *s, struct task *t) { void qsched_enqueue(struct qsched *s, struct task *t) { - int j, qid, scores[s->nr_queues], oid; - /* If this is a virtual task, just do its unlocks and leave. */ if (t->flags & task_flag_virtual) { @@ -552,23 +550,28 @@ void qsched_enqueue(struct qsched *s, struct task *t) { else { /* Init the scores for each queue. */ - for (j = 0; j < s->nr_queues; j++) scores[j] = 0; + int scores[s->nr_queues]; + for (int j = 0; j < s->nr_queues; j++) scores[j] = 0; /* Loop over the locks and uses, and get their owners. */ - for (j = 0; j < t->nr_locks; j++) - if ((oid = s->res[t->locks[j]].owner) != qsched_owner_none) - scores[oid] += 1; - for (j = 0; j < t->nr_uses; j++) - if ((oid = s->res[t->uses[j]].owner) != qsched_owner_none) - scores[oid] += 1; + for (int j = 0; j < t->nr_locks; j++) { + int oid = s->res[t->locks[j]].owner; + if (oid != qsched_owner_none) scores[oid] += 1; + } + for (int j = 0; j < t->nr_uses; j++) { + int oid = s->res[t->uses[j]].owner; + if (oid != qsched_owner_none) scores[oid] += 1; + } /* Find the queue with the highest score. */ - qid = 0; - for (j = 1; j < s->nr_queues; j++) + int qid = 0; + for (int j = 1; j < s->nr_queues; j++) { if (scores[j] > scores[qid] || (scores[j] == scores[qid] && - s->queues[j].count < s->queues[qid].count)) + s->queues[j].count < s->queues[qid].count)) { qid = j; + } + } /* Put the unlocked task in that queue. */ queue_put(&s->queues[qid], s, t - s->tasks); @@ -584,9 +587,6 @@ void qsched_enqueue(struct qsched *s, struct task *t) { void qsched_done(struct qsched *s, struct task *t) { - int k; - struct task *t2; - TIMER_TIC /* Set the task stats. */ @@ -594,17 +594,18 @@ void qsched_done(struct qsched *s, struct task *t) { if (!(s->flags & qsched_flag_norecost)) t->cost = t->toc - t->tic; /* Release this task's locks. */ - for (k = 0; k < t->nr_locks; k++) qsched_unlockres(s, t->locks[k]); + for (int k = 0; k < t->nr_locks; k++) qsched_unlockres(s, t->locks[k]); /* Loop over the task's unlocks... */ - for (k = 0; k < t->nr_unlocks; k++) { + for (int k = 0; k < t->nr_unlocks; k++) { /* Get a grip on the unlocked task. */ - t2 = &s->tasks[t->unlocks[k]]; + struct task *t2 = &s->tasks[t->unlocks[k]]; /* Is the unlocked task ready to run? */ - if (atomic_dec(&t2->wait) == 1 && !(t2->flags & task_flag_skip)) + if (atomic_dec(&t2->wait) == 1 && !(t2->flags & task_flag_skip)) { qsched_enqueue(s, t2); + } } /* Decrease the number of tasks in this space. */ @@ -635,8 +636,6 @@ void qsched_done(struct qsched *s, struct task *t) { int qsched_lockres(struct qsched *s, int rid) { - int finger, finger2; - /* Try to lock the root-level resource. */ if (s->res[rid].hold || lock_trylock(&s->res[rid].lock)) return 0; @@ -648,6 +647,7 @@ int qsched_lockres(struct qsched *s, int rid) { /* Follow parents and increase their hold counter, but fail if any are locked. */ + int finger; for (finger = s->res[rid].parent; finger != qsched_res_none; finger = s->res[finger].parent) { if (lock_trylock(&s->res[finger].lock)) break; @@ -662,9 +662,10 @@ int qsched_lockres(struct qsched *s, int rid) { lock_unlock_blind(&s->res[rid].lock); /* Go back up the tree and undo the holds. */ - for (finger2 = s->res[rid].parent; finger2 != finger; - finger2 = s->res[finger2].parent) + for (int finger2 = s->res[rid].parent; finger2 != finger; + finger2 = s->res[finger2].parent) { atomic_dec(&s->res[finger2].hold); + } /* Fail. */ return 0; @@ -672,8 +673,9 @@ int qsched_lockres(struct qsched *s, int rid) { } /* Otherwise, all went well. */ - else + else { return 1; + } } /**