2017-09-08 12:05:08 +00:00
|
|
|
#include <linux/kernel.h>
|
2012-11-13 13:30:32 +00:00
|
|
|
#include "../cache.h"
|
|
|
|
#include "progress.h"
|
|
|
|
|
2013-10-23 18:40:38 +00:00
|
|
|
static void null_progress__update(struct ui_progress *p __maybe_unused)
|
2012-11-13 13:30:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-10-23 17:08:48 +00:00
|
|
|
static struct ui_progress_ops null_progress__ops =
|
2012-11-13 13:30:32 +00:00
|
|
|
{
|
2013-10-23 17:08:48 +00:00
|
|
|
.update = null_progress__update,
|
2012-11-13 13:30:32 +00:00
|
|
|
};
|
|
|
|
|
2013-10-23 17:08:48 +00:00
|
|
|
struct ui_progress_ops *ui_progress__ops = &null_progress__ops;
|
2012-11-13 13:30:32 +00:00
|
|
|
|
2013-10-23 18:40:38 +00:00
|
|
|
void ui_progress__update(struct ui_progress *p, u64 adv)
|
2012-11-13 13:30:32 +00:00
|
|
|
{
|
2017-09-08 12:05:08 +00:00
|
|
|
u64 last = p->curr;
|
|
|
|
|
2013-10-23 18:40:38 +00:00
|
|
|
p->curr += adv;
|
|
|
|
|
|
|
|
if (p->curr >= p->next) {
|
2017-09-08 12:05:08 +00:00
|
|
|
u64 nr = DIV_ROUND_UP(p->curr - last, p->step);
|
|
|
|
|
|
|
|
p->next += nr * p->step;
|
2013-10-23 18:40:38 +00:00
|
|
|
ui_progress__ops->update(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ui_progress__init(struct ui_progress *p, u64 total, const char *title)
|
|
|
|
{
|
|
|
|
p->curr = 0;
|
2017-09-08 12:05:07 +00:00
|
|
|
p->next = p->step = total / 16 ?: 1;
|
2013-10-23 18:40:38 +00:00
|
|
|
p->total = total;
|
|
|
|
p->title = title;
|
|
|
|
|
2017-09-08 12:05:09 +00:00
|
|
|
if (ui_progress__ops->init)
|
|
|
|
ui_progress__ops->init(p);
|
2012-11-13 13:30:32 +00:00
|
|
|
}
|
2012-11-13 13:30:34 +00:00
|
|
|
|
|
|
|
void ui_progress__finish(void)
|
|
|
|
{
|
2013-10-23 17:08:48 +00:00
|
|
|
if (ui_progress__ops->finish)
|
|
|
|
ui_progress__ops->finish();
|
2012-11-13 13:30:34 +00:00
|
|
|
}
|