From 380253ff7fd0de10426353cac2bfbebdc6ac9f89 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Thu, 23 Jun 2016 00:00:00 -0500 Subject: [PATCH] library: more pids_fetch struct opaqueness, 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 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 --- proc/pids.c | 8 +++++--- proc/pids.h | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/proc/pids.c b/proc/pids.c index d5758d38..0f221ff5 100644 --- a/proc/pids.c +++ b/proc/pids.c @@ -63,6 +63,7 @@ struct fetch_support { int n_inuse; // number of above pointers occupied int n_alloc_save; // last known results.stacks allocation struct pids_fetch results; // counts + stacks for return to caller + struct pids_counts counts; // actual counts pointed to by 'results' }; struct procps_pidsinfo { @@ -367,7 +368,6 @@ typedef int (*QSR_t)(const void *, const void *, void *); #define FF(e) (FRE_t)freNAME(e) #define QS(t) (QSR_t)srtNAME(t) - /* * Need it be said? * This table must be kept in the exact same order as @@ -1073,7 +1073,7 @@ static int stacks_fetch ( } cleanup_stacks_all(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 -------------------------------------- n_inuse = 0; @@ -1085,7 +1085,7 @@ static int stacks_fetch ( return -1; 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; assign_results(info, info->fetch.anchor[n_inuse++], &task); } @@ -1167,6 +1167,8 @@ PROCPS_EXPORT int procps_pids_new ( procps_uptime(&uptime_secs, NULL); p->boot_seconds = uptime_secs; + p->fetch.results.counts = &p->fetch.counts; + p->refcount = 1; *info = p; return 0; diff --git a/proc/pids.h b/proc/pids.h index a3285fc5..ebe72592 100644 --- a/proc/pids.h +++ b/proc/pids.h @@ -23,7 +23,6 @@ #ifndef _PROC_PIDS_H #define _PROC_PIDS_H -#include __BEGIN_DECLS enum pids_item { @@ -187,8 +186,8 @@ struct pids_counts { }; struct pids_fetch { + struct pids_counts *counts; struct pids_stack **stacks; - struct pids_counts counts; };