From 817f15b03197afcbba438cad202fad7b84174e9b Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Wed, 3 May 1995 17:05:09 +0000 Subject: (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. --- libps/proclist.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'libps/proclist.c') 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); + } +} -- cgit v1.2.3