Skip to content

Create an asynchronous progress bar

Darshit Shah requested to merge gh-27cfc353/90/darnir/async_progressbar into master

Give the progress bar its own thread and let it update the entire display asynchronously at a specified time interval. The existing implementation refreshes the progress bar for each network packet downloaded. Over multiple downloader threads and a high speed network connection this can lead to far too many redrawings of the screen. Also, each of the downloader threads will block while trying to acquire the thread mutex because another thread just retrieved a packet. While I haven't profiled it, it seems like there would be extremely high lock contention in the existing implementation. Instead, with a separate thread, we can update all the progress bar slots simultaneously at regular intervals.

* bootstrap.conf: Include Gnulib module "ioctl"
* include/libwget.h.in: Define always_inline, flatten and deprecated
compiler attributes for both GCC and Clang
* include/libwget.h.in: Export new functions wget_human_readable,
wget_bar_register and wget_bar_deregister. Also remove unused
function wget_bar_update
* include/libwget.h.in (wget_http_response_t): Add new element
"cur_downloaded" to struct. This element keeps a track of the raw
number of bytes downloaded in the response
(_wget_bar_ctx): Define new struct for storing the progress bar
context.
* libwget/bar.c: Fix display of downlaoded ratio. Ensure it does not
exceed 100%.
Add support for printing the filename and downloaded bytes to the
progress bar.
Create a new progress bar thread on initialization
* libwget/http.c (wget_http_response_cb): Store the raw number of
bytes downloaded from the network in the response data
* libwget/utils.c (wget_human_readable): New function to convert an
int value to a human readable string
* src/bar.c: Use the entire screen width instead of just 70 columns
for the progress bar.
Provide methods to register and deregister a progress bar
context
* src/bar.h: Same
* src/job.h: Move definition of struct DOWNLOADER from main.c to
    here
* src/progress.h: Move definition of _body_callback_context from
    main.c to here
* src/utils.c: Add new method to determine the width of the screen
* src/utils.h: Same
* src/wget.c: Use the new progress bar contexts. Update, register
and deregister them
* src/Makefile.am: Add new files, progress.h, utils.c, utils.h

Merge request reports