]> git.ipfire.org Git - pakfire.git/commitdiff
progressbar: Always finish properly
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 16 Sep 2022 12:10:29 +0000 (12:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 16 Sep 2022 12:10:29 +0000 (12:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/progressbar.c

index 98031667f16d00d68cd0d6511d824688e046d7a7..ed218d38bda75ad94880c5936edba441cbba68c0 100644 (file)
@@ -127,7 +127,29 @@ static void pakfire_progressbar_free_widgets(struct pakfire_progressbar* p) {
        }
 }
 
+static int __pakfire_progressbar_finish(struct pakfire_progressbar* p) {
+       int r;
+       int retval = 0;
+
+       // Do nothing if already finished
+       if (p->status == PAKFIRE_PROGRESSBAR_FINISHED)
+               return 0;
+
+       // Set status
+       p->status = PAKFIRE_PROGRESSBAR_FINISHED;
+
+       // Wait until the render thread is done
+       r = pthread_join(p->renderer, (void**)&retval);
+       if (r)
+               return r;
+
+       return retval;
+}
+
 static void pakfire_progressbar_free(struct pakfire_progressbar* p) {
+       // Ensure the progressbar has finished
+       __pakfire_progressbar_finish(p);
+
        pakfire_progressbar_free_widgets(p);
        free(p);
 }
@@ -339,21 +361,10 @@ PAKFIRE_EXPORT int pakfire_progressbar_increment(struct pakfire_progressbar* p,
 }
 
 PAKFIRE_EXPORT int pakfire_progressbar_finish(struct pakfire_progressbar* p) {
-       int r;
-       int retval = 0;
-
        if (p->status != PAKFIRE_PROGRESSBAR_RUNNING)
                return EINVAL;
 
-       // Set status
-       p->status = PAKFIRE_PROGRESSBAR_FINISHED;
-
-       // Wait until the render thread is done
-       r = pthread_join(p->renderer, (void**)&retval);
-       if (r)
-               return r;
-
-       return retval;
+       return __pakfire_progressbar_finish(p);
 }
 
 PAKFIRE_EXPORT int pakfire_progressbar_reset(struct pakfire_progressbar* p) {