Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
a82bfd04 | 2 | #include <linux/kernel.h> |
688f2f5b NK |
3 | #include "../cache.h" |
4 | #include "progress.h" | |
5 | ||
4d3001fd | 6 | static void null_progress__update(struct ui_progress *p __maybe_unused) |
688f2f5b NK |
7 | { |
8 | } | |
9 | ||
4779a2e9 | 10 | static struct ui_progress_ops null_progress__ops = |
688f2f5b | 11 | { |
4779a2e9 | 12 | .update = null_progress__update, |
688f2f5b NK |
13 | }; |
14 | ||
4779a2e9 | 15 | struct ui_progress_ops *ui_progress__ops = &null_progress__ops; |
688f2f5b | 16 | |
4d3001fd | 17 | void ui_progress__update(struct ui_progress *p, u64 adv) |
688f2f5b | 18 | { |
a82bfd04 JO |
19 | u64 last = p->curr; |
20 | ||
4d3001fd ACM |
21 | p->curr += adv; |
22 | ||
23 | if (p->curr >= p->next) { | |
a82bfd04 JO |
24 | u64 nr = DIV_ROUND_UP(p->curr - last, p->step); |
25 | ||
26 | p->next += nr * p->step; | |
4d3001fd ACM |
27 | ui_progress__ops->update(p); |
28 | } | |
29 | } | |
30 | ||
31 | void ui_progress__init(struct ui_progress *p, u64 total, const char *title) | |
32 | { | |
33 | p->curr = 0; | |
4d286c89 | 34 | p->next = p->step = total / 16 ?: 1; |
4d3001fd ACM |
35 | p->total = total; |
36 | p->title = title; | |
37 | ||
688f2f5b | 38 | } |
a5580f3e NK |
39 | |
40 | void ui_progress__finish(void) | |
41 | { | |
4779a2e9 ACM |
42 | if (ui_progress__ops->finish) |
43 | ui_progress__ops->finish(); | |
a5580f3e | 44 | } |