diff options
author | Miles Bader <miles@gnu.org> | 1995-05-03 17:05:09 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1995-05-03 17:05:09 +0000 |
commit | 817f15b03197afcbba438cad202fad7b84174e9b (patch) | |
tree | e96dab17fd2ef765d35875e47748bb49e676a217 /libps/proclist.c | |
parent | f26d959254fc6d7dabc8f5f7531a3158a316fc28 (diff) |
(proc_stat_list_for_each): New function for iterating over proc_stat_lists.
(proc_stat_list_spec_nominal): New function for deciding if a particular spec
is always nominal.
Diffstat (limited to 'libps/proclist.c')
-rw-r--r-- | libps/proclist.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/libps/proclist.c b/libps/proclist.c index 18f28c7e..17e62f46 100644 --- a/libps/proclist.c +++ b/libps/proclist.c @@ -579,3 +579,50 @@ proc_stat_list_remove_threads(proc_stat_list_t pp) } return proc_stat_list_filter1(pp, is_thread, 0, FALSE); } + +/* ---------------------------------------------------------------- */ + +/* Calls FN in order for each proc_stat in PP. If FN ever returns a non-zero + value, then the iteration is stopped, and the value is returned + immediately; otherwise, 0 is returned. */ +int +proc_stat_list_for_each (proc_stat_list_t pp, int (*fn)(proc_stat_t ps)) +{ + unsigned nprocs = pp->num_procs; + proc_stat_t *procs = pp->proc_stats; + + while (nprocs-- > 0) + { + int val = (*fn)(*procs++); + if (val) + return val; + } + + return 0; +} + +/* ---------------------------------------------------------------- */ + +/* Returns true if SPEC is `nominal' in every entry in PP. */ +bool +proc_stat_list_spec_nominal (proc_stat_list_t pp, ps_fmt_spec_t spec) +{ + bool (*nominal_fn)(proc_stat_t ps, ps_getter_t getter) = + ps_fmt_spec_nominal_fn (spec); + + if (nominal_fn == NULL) + return FALSE; + else + { + ps_getter_t getter = ps_fmt_spec_getter (spec); + ps_flags_t needs = ps_getter_needs (getter); + int interesting (proc_stat_t ps) + { + return proc_stat_has (ps, needs) && !(*nominal_fn)(ps, getter); + } + + proc_stat_list_set_flags (pp, needs); + + return !proc_stat_list_for_each (pp, interesting); + } +} |