library: more pids_fetch struct opaqueness, <PIDS> api

With all our 3rd generation interfaces, we're now well
positioned to preserve binary compatibility should new
fields be added to any public structure (assuming that
the 'result' union already contains its largest type).

This remains true even for the <pids> interface, which
unlike the others, has one structure embedded within a
separate struct rather than declaring a pointer to it.

The counts struct was positioned after the stacks ptrs
array so as to preserve that ABI if ever new ints were
added. Logically, however, the counts (especially that
total) should precede the stacks array if we wished to
properly place a horse (total) before a cart (stacks).

So to enable relocating those counts we will no longer
embed that structure, but provide a pointer to it. And
this will make accessing syntax feel more natural too.

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2016-06-23 00:00:00 -05:00 committed by Craig Small
parent ddb4754b33
commit 380253ff7f
2 changed files with 6 additions and 5 deletions

View File

@ -63,6 +63,7 @@ struct fetch_support {
int n_inuse; // number of above pointers occupied int n_inuse; // number of above pointers occupied
int n_alloc_save; // last known results.stacks allocation int n_alloc_save; // last known results.stacks allocation
struct pids_fetch results; // counts + stacks for return to caller struct pids_fetch results; // counts + stacks for return to caller
struct pids_counts counts; // actual counts pointed to by 'results'
}; };
struct procps_pidsinfo { struct procps_pidsinfo {
@ -367,7 +368,6 @@ typedef int (*QSR_t)(const void *, const void *, void *);
#define FF(e) (FRE_t)freNAME(e) #define FF(e) (FRE_t)freNAME(e)
#define QS(t) (QSR_t)srtNAME(t) #define QS(t) (QSR_t)srtNAME(t)
/* /*
* Need it be said? * Need it be said?
* This table must be kept in the exact same order as * This table must be kept in the exact same order as
@ -1073,7 +1073,7 @@ static int stacks_fetch (
} }
cleanup_stacks_all(info); cleanup_stacks_all(info);
toggle_history(info); toggle_history(info);
memset(&info->fetch.results.counts, 0, sizeof(struct pids_counts)); memset(&info->fetch.counts, 0, sizeof(struct pids_counts));
// iterate stuff -------------------------------------- // iterate stuff --------------------------------------
n_inuse = 0; n_inuse = 0;
@ -1085,7 +1085,7 @@ static int stacks_fetch (
return -1; return -1;
memcpy(info->fetch.anchor + n_inuse, ext->stacks, sizeof(void *) * MEMORY_INCR); memcpy(info->fetch.anchor + n_inuse, ext->stacks, sizeof(void *) * MEMORY_INCR);
} }
if (!proc_tally(info, &info->fetch.results.counts, &task)) if (!proc_tally(info, &info->fetch.counts, &task))
return -1; return -1;
assign_results(info, info->fetch.anchor[n_inuse++], &task); assign_results(info, info->fetch.anchor[n_inuse++], &task);
} }
@ -1167,6 +1167,8 @@ PROCPS_EXPORT int procps_pids_new (
procps_uptime(&uptime_secs, NULL); procps_uptime(&uptime_secs, NULL);
p->boot_seconds = uptime_secs; p->boot_seconds = uptime_secs;
p->fetch.results.counts = &p->fetch.counts;
p->refcount = 1; p->refcount = 1;
*info = p; *info = p;
return 0; return 0;

View File

@ -23,7 +23,6 @@
#ifndef _PROC_PIDS_H #ifndef _PROC_PIDS_H
#define _PROC_PIDS_H #define _PROC_PIDS_H
#include <features.h>
__BEGIN_DECLS __BEGIN_DECLS
enum pids_item { enum pids_item {
@ -187,8 +186,8 @@ struct pids_counts {
}; };
struct pids_fetch { struct pids_fetch {
struct pids_counts *counts;
struct pids_stack **stacks; struct pids_stack **stacks;
struct pids_counts counts;
}; };