summaryrefslogtreecommitdiff
path: root/libps
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1996-08-02 19:28:14 +0000
committerMiles Bader <miles@gnu.org>1996-08-02 19:28:14 +0000
commitd16407f8a19e85d1e1aa00bf58b050dba6b6e929 (patch)
tree354b90e780658fb494b8f67918ee54617ed6e9a4 /libps
parentf3833005784d979119c0002ae86066578bb9044c (diff)
(set_procinfo_flags): Pass HAVE to count_threads.
(count_threads): Take new argument HAVE, and use different thread counting method depending on whether we have thread detail info.
Diffstat (limited to 'libps')
-rw-r--r--libps/procstat.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/libps/procstat.c b/libps/procstat.c
index 6ab66f04..0938073e 100644
--- a/libps/procstat.c
+++ b/libps/procstat.c
@@ -524,17 +524,25 @@ summarize_thread_waits (struct procinfo *pi, char *waits, size_t waits_len,
/* Returns the number of threads in PI that aren't marked dead. */
static unsigned
-count_threads (struct procinfo *pi)
+count_threads (struct procinfo *pi, ps_flags_t have)
{
- int i;
- unsigned num_threads = 0;
+ if (have & (PSTAT_PROCINFO_THREAD & ~PSTAT_NUM_THREADS))
+ /* If we have thread info besides the number of threads, then the
+ threadinfos structures in PI are valid (we use the died bit). */
+ {
+ int i;
+ unsigned num_threads = 0;
- /* The union of all thread state bits... */
- for (i = 0; i < pi->nthreads; i++)
- if (! pi->threadinfos[i].died)
- num_threads++;
+ /* The union of all thread state bits... */
+ for (i = 0; i < pi->nthreads; i++)
+ if (! pi->threadinfos[i].died)
+ num_threads++;
- return num_threads;
+ return num_threads;
+ }
+ else
+ /* Otherwise just use the number proc gave us. */
+ return pi->nthreads;
}
/* Returns the threadinfo for the INDEX'th thread from PI that isn't marked
@@ -608,7 +616,7 @@ set_procinfo_flags (struct proc_stat *ps, ps_flags_t need, ps_flags_t have)
{
have = merge_procinfo (ps, PSTAT_NUM_THREADS, have);
if (have & PSTAT_NUM_THREADS)
- ps->num_threads = count_threads (ps->proc_info);
+ ps->num_threads = count_threads (ps->proc_info, have);
}
if ((have & PSTAT_NUM_THREADS) && ps->num_threads <= 3)
/* Perhaps only 1 user thread -- thread-wait info may be
@@ -624,7 +632,7 @@ set_procinfo_flags (struct proc_stat *ps, ps_flags_t need, ps_flags_t have)
if (have & PSTAT_TASK_BASIC)
ps->task_basic_info = &pi->taskinfo;
if (have & PSTAT_NUM_THREADS)
- ps->num_threads = count_threads (pi);
+ ps->num_threads = count_threads (pi, have);
if (had & PSTAT_THREAD_BASIC)
free (ps->thread_basic_info);
if (have & PSTAT_THREAD_BASIC)