Introduce a handy list_first_entry macro
There are many places in the kernel where the construction like
foo = list_entry(head->next, struct foo_struct, list);
are used.
The code might look more descriptive and neat if using the macro
list_first_entry(head, type, member) \
list_entry((head)->next, type, member)
Here is the macro itself and the examples of its usage in the generic code.
If it will turn out to be useful, I can prepare the set of patches to
inject in into arch-specific code, drivers, networking, etc.
Signed-off-by: Pavel Emelianov <xemul@openvz.org>
Signed-off-by: Kirill Korotaev <dev@openvz.org>
Cc: Randy Dunlap <randy.dunlap@oracle.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Zach Brown <zach.brown@oracle.com>
Cc: Davide Libenzi <davidel@xmailserver.org>
Cc: John McCutchan <ttb@tentacle.dhs.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: john stultz <johnstul@us.ibm.com>
Cc: Ram Pai <linuxram@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
committed by
Linus Torvalds
parent
db9c02fa8b
commit
b5e618181a
@@ -971,7 +971,7 @@ static void check_thread_timers(struct task_struct *tsk,
|
||||
maxfire = 20;
|
||||
tsk->it_prof_expires = cputime_zero;
|
||||
while (!list_empty(timers)) {
|
||||
struct cpu_timer_list *t = list_entry(timers->next,
|
||||
struct cpu_timer_list *t = list_first_entry(timers,
|
||||
struct cpu_timer_list,
|
||||
entry);
|
||||
if (!--maxfire || cputime_lt(prof_ticks(tsk), t->expires.cpu)) {
|
||||
@@ -986,7 +986,7 @@ static void check_thread_timers(struct task_struct *tsk,
|
||||
maxfire = 20;
|
||||
tsk->it_virt_expires = cputime_zero;
|
||||
while (!list_empty(timers)) {
|
||||
struct cpu_timer_list *t = list_entry(timers->next,
|
||||
struct cpu_timer_list *t = list_first_entry(timers,
|
||||
struct cpu_timer_list,
|
||||
entry);
|
||||
if (!--maxfire || cputime_lt(virt_ticks(tsk), t->expires.cpu)) {
|
||||
@@ -1001,7 +1001,7 @@ static void check_thread_timers(struct task_struct *tsk,
|
||||
maxfire = 20;
|
||||
tsk->it_sched_expires = 0;
|
||||
while (!list_empty(timers)) {
|
||||
struct cpu_timer_list *t = list_entry(timers->next,
|
||||
struct cpu_timer_list *t = list_first_entry(timers,
|
||||
struct cpu_timer_list,
|
||||
entry);
|
||||
if (!--maxfire || tsk->sched_time < t->expires.sched) {
|
||||
@@ -1057,7 +1057,7 @@ static void check_process_timers(struct task_struct *tsk,
|
||||
maxfire = 20;
|
||||
prof_expires = cputime_zero;
|
||||
while (!list_empty(timers)) {
|
||||
struct cpu_timer_list *t = list_entry(timers->next,
|
||||
struct cpu_timer_list *t = list_first_entry(timers,
|
||||
struct cpu_timer_list,
|
||||
entry);
|
||||
if (!--maxfire || cputime_lt(ptime, t->expires.cpu)) {
|
||||
@@ -1072,7 +1072,7 @@ static void check_process_timers(struct task_struct *tsk,
|
||||
maxfire = 20;
|
||||
virt_expires = cputime_zero;
|
||||
while (!list_empty(timers)) {
|
||||
struct cpu_timer_list *t = list_entry(timers->next,
|
||||
struct cpu_timer_list *t = list_first_entry(timers,
|
||||
struct cpu_timer_list,
|
||||
entry);
|
||||
if (!--maxfire || cputime_lt(utime, t->expires.cpu)) {
|
||||
@@ -1087,7 +1087,7 @@ static void check_process_timers(struct task_struct *tsk,
|
||||
maxfire = 20;
|
||||
sched_expires = 0;
|
||||
while (!list_empty(timers)) {
|
||||
struct cpu_timer_list *t = list_entry(timers->next,
|
||||
struct cpu_timer_list *t = list_first_entry(timers,
|
||||
struct cpu_timer_list,
|
||||
entry);
|
||||
if (!--maxfire || sched_time < t->expires.sched) {
|
||||
@@ -1400,7 +1400,7 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
|
||||
*/
|
||||
head = &tsk->signal->cpu_timers[clock_idx];
|
||||
if (list_empty(head) ||
|
||||
cputime_ge(list_entry(head->next,
|
||||
cputime_ge(list_first_entry(head,
|
||||
struct cpu_timer_list, entry)->expires.cpu,
|
||||
*newval)) {
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user