diff mbox series

[V2,1/3] progress: add function to increase number of steps

Message ID 20230406200724.1192395-1-sbabic@denx.de
State Accepted
Headers show
Series [V2,1/3] progress: add function to increase number of steps | expand

Commit Message

Stefano Babic April 6, 2023, 8:07 p.m. UTC
It is not always possible to know the number of steps before updating.
There are some cases where a handler can split the update in multiple
single steps, calling a chained handler. A chained handler will update
the progress as ususal, but this means that a single step is multiplied
causing a total progress > 100%.

Add a funtion to increase during the update the number of steps.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 core/progress_thread.c | 7 +++++++
 include/progress.h     | 1 +
 2 files changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/core/progress_thread.c b/core/progress_thread.c
index b8aa3ad..e7794e4 100644
--- a/core/progress_thread.c
+++ b/core/progress_thread.c
@@ -119,6 +119,13 @@  void swupdate_progress_init(unsigned int nsteps) {
 	pthread_mutex_unlock(&pprog->lock);
 }
 
+void swupdate_progress_addstep(void) {
+	struct swupdate_progress *pprog = &progress;
+	pthread_mutex_lock(&pprog->lock);
+	pprog->msg.nsteps++;
+	pthread_mutex_unlock(&pprog->lock);
+}
+
 void swupdate_progress_update(unsigned int perc)
 {
 	struct swupdate_progress *pprog = &progress;
diff --git a/include/progress.h b/include/progress.h
index aa99ec8..11f1496 100644
--- a/include/progress.h
+++ b/include/progress.h
@@ -17,6 +17,7 @@ 
  * as well as external use are defined in progress_ipc.h
  */
 void swupdate_progress_init(unsigned int nsteps);
+void swupdate_progress_addstep(void);
 void swupdate_progress_update(unsigned int perc);
 void swupdate_progress_inc_step(const char *image, const char *handler_name);
 void swupdate_progress_step_completed(void);