From 80143d6826f180a4a3e742f34d6c3093fc3d3b3a Mon Sep 17 00:00:00 2001 From: Pedro Gonnet <gonnet@google.com> Date: Sun, 18 Jan 2015 22:47:55 +0100 Subject: [PATCH] more cleanup. --- src/qsched.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/qsched.c b/src/qsched.c index bec536a..b7c43cc 100644 --- a/src/qsched.c +++ b/src/qsched.c @@ -686,16 +686,14 @@ int qsched_lockres(struct qsched *s, int rid) { */ void qsched_unlockres(struct qsched *s, int rid) { - - int finger; - /* Unlock the resource. */ lock_unlock_blind(&s->res[rid].lock); /* Go back up the tree and undo the holds. */ - for (finger = s->res[rid].parent; finger != qsched_res_none; - finger = s->res[finger].parent) + for (int finger = s->res[rid].parent; finger != qsched_res_none; + finger = s->res[finger].parent) { atomic_dec(&s->res[finger].hold); + } } /** @@ -709,23 +707,24 @@ void qsched_unlockres(struct qsched *s, int rid) { int qsched_locktask(struct qsched *s, int tid) { - int k; - struct task *t; - TIMER_TIC /* Get a pointer on the task. */ - t = &s->tasks[tid]; + struct task *t = &s->tasks[tid]; /* Try to lock all the task's locks. */ - for (k = 0; k < t->nr_locks; k++) - if (qsched_lockres(s, t->locks[k]) == 0) break; + int lock_id; + for (lock_id = 0; lock_id < t->nr_locks; lock_id++) { + if (qsched_lockres(s, t->locks[lock_id]) == 0) break; + } /* If I didn't get all the locks... */ - if (k < t->nr_locks) { + if (lock_id < t->nr_locks) { /* Unroll the locks I got. */ - for (k -= 1; k >= 0; k--) qsched_unlockres(s, t->locks[k]); + for (lock_id -= 1; lock_id >= 0; lock_id--) { + qsched_unlockres(s, t->locks[lock_id]); + } /* Fail. */ TIMER_TOC(s, qsched_timer_lock) @@ -749,16 +748,13 @@ int qsched_locktask(struct qsched *s, int tid) { void qsched_unlocktask(struct qsched *s, int tid) { - int k; - struct task *t; - TIMER_TIC /* Get a pointer on the task. */ - t = &s->tasks[tid]; + struct task *t = &s->tasks[tid]; /* Unlock the used resources. */ - 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]); TIMER_TOC(s, qsched_timer_lock) } -- GitLab