Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/subr_kdb.c
Show First 20 Lines • Show All 602 Lines • ▼ Show 20 Lines | |||||
struct thread * | struct thread * | ||||
kdb_thr_first(void) | kdb_thr_first(void) | ||||
{ | { | ||||
struct proc *p; | struct proc *p; | ||||
struct thread *thr; | struct thread *thr; | ||||
u_int i; | u_int i; | ||||
/* This function may be called early. */ | |||||
if (pidhashtbl == NULL) | |||||
markj: Why not check pidhashtbl != NULL instead? | |||||
Done Inline ActionsSure, this is slightly preferable. mhorne: Sure, this is slightly preferable. | |||||
return (&thread0); | |||||
for (i = 0; i <= pidhash; i++) { | for (i = 0; i <= pidhash; i++) { | ||||
LIST_FOREACH(p, &pidhashtbl[i], p_hash) { | LIST_FOREACH(p, &pidhashtbl[i], p_hash) { | ||||
thr = FIRST_THREAD_IN_PROC(p); | thr = FIRST_THREAD_IN_PROC(p); | ||||
if (thr != NULL) | if (thr != NULL) | ||||
return (thr); | return (thr); | ||||
} | } | ||||
} | } | ||||
return (NULL); | return (NULL); | ||||
Show All 25 Lines | |||||
struct thread * | struct thread * | ||||
kdb_thr_next(struct thread *thr) | kdb_thr_next(struct thread *thr) | ||||
{ | { | ||||
struct proc *p; | struct proc *p; | ||||
u_int hash; | u_int hash; | ||||
p = thr->td_proc; | p = thr->td_proc; | ||||
thr = TAILQ_NEXT(thr, td_plist); | thr = TAILQ_NEXT(thr, td_plist); | ||||
if (thr != NULL) | if (thr != NULL) | ||||
Done Inline ActionsSimilarly here, we could check pidhashtbl != NULL after checking TAILQ_NEXT(thr, td_plist). markj: Similarly here, we could check `pidhashtbl != NULL` after checking `TAILQ_NEXT(thr, td_plist)`. | |||||
Done Inline ActionsWhy is it better after this check? It doesn't seem possible for td_plist to be populated but pidhashtbl be NULL. mhorne: Why is it better after this check? It doesn't seem possible for `td_plist` to be populated but… | |||||
Done Inline ActionsIt's not possible today, it just seemed very slightly cleaner to me to not make that assumption, supposing that someone might someday add a static thread1 to proc0 or something. markj: It's not possible today, it just seemed very slightly cleaner to me to not make that assumption… | |||||
return (thr); | return (thr); | ||||
if (pidhashtbl == NULL) | |||||
return (NULL); | |||||
hash = p->p_pid & pidhash; | hash = p->p_pid & pidhash; | ||||
for (;;) { | for (;;) { | ||||
p = LIST_NEXT(p, p_hash); | p = LIST_NEXT(p, p_hash); | ||||
while (p == NULL) { | while (p == NULL) { | ||||
if (++hash > pidhash) | if (++hash > pidhash) | ||||
return (NULL); | return (NULL); | ||||
p = LIST_FIRST(&pidhashtbl[hash]); | p = LIST_FIRST(&pidhashtbl[hash]); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |
Why not check pidhashtbl != NULL instead?