diff options
author | Alistair Popple <alistair@popple.id.au> | 2018-05-17 15:44:27 +1000 |
---|---|---|
committer | Alistair Popple <alistair@popple.id.au> | 2018-05-17 16:20:05 +1000 |
commit | f665008c3147e07fd59110d0a5d5aaba9f15ef28 (patch) | |
tree | e9e0cc14f545ad8b324d6a9c9bbbe51c223364d8 /src/progress.c | |
parent | 6e3ac338f3920596d9abf2cc3501d34d96ed7bf4 (diff) | |
download | pdbg-f665008c3147e07fd59110d0a5d5aaba9f15ef28.tar.gz pdbg-f665008c3147e07fd59110d0a5d5aaba9f15ef28.zip |
libpdbg: Add function to register progress tick callback
For long running library operations such as getmem it is useful to give the
application an ability to report progress back to the user. This adds a way to
register a progress_tick callback which takes the current and maximum progress
counts.
Signed-off-by: Alistair Popple <alistair@popple.id.au>
Suggested-by: Amitay Isaacs <amitay@ozlabs.org>
Diffstat (limited to 'src/progress.c')
-rw-r--r-- | src/progress.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/progress.c b/src/progress.c index cf95015..fe443b9 100644 --- a/src/progress.c +++ b/src/progress.c @@ -22,7 +22,6 @@ #include "progress.h" -static uint64_t progress_max; static uint64_t progress_pcent; static uint64_t progress_n_upd; static time_t progress_prevsec; @@ -30,11 +29,10 @@ static struct timespec progress_start; #define PROGRESS_CHARS 50 -void progress_init(uint64_t count) +void progress_init(void) { unsigned int i; - progress_max = count; progress_pcent = 0; progress_n_upd = ULONG_MAX; progress_prevsec = ULONG_MAX; @@ -46,16 +44,16 @@ void progress_init(uint64_t count) fflush(stderr); clock_gettime(CLOCK_MONOTONIC, &progress_start);} -void progress_tick(uint64_t cur) +void progress_tick(uint64_t cur, uint64_t end) { unsigned int i, pos; struct timespec now; uint64_t pcent; double sec; - pcent = (cur * 100) / progress_max; + pcent = (cur * 100) / end; if (progress_pcent == pcent && cur < progress_n_upd && - cur < progress_max) + cur < end) return; progress_pcent = pcent; pos = (pcent * PROGRESS_CHARS) / 101; |