Skip to content

Commit

Permalink
Rewrite the code that throttles UI updates to be in ui_print itself.
Browse files Browse the repository at this point in the history
Change-Id: I4fc59efc42991bdcf4fcd09feacfeb6fd984d58c
  • Loading branch information
koush authored and myfluxi committed Jul 3, 2012
1 parent 2a809ea commit 8842575
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void ui_printlogtail(int nb_lines);

void ui_reset_text_col();
void ui_set_show_text(int value);
void ui_set_nice(int enabled);
#define ui_nice_print(...) ui_set_nice(1); ui_print(__VA_ARGS__); ui_set_nice(0)

// Display some header text followed by a menu of items, which appears
// at the top of the screen (in place of any scrolling ui_print()
Expand Down
2 changes: 1 addition & 1 deletion nandroid.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static void yaffs_callback(const char* filename)
if (tmp[strlen(tmp) - 1] == '\n')
tmp[strlen(tmp) - 1] = NULL;
if (strlen(tmp) < 30)
ui_print("%s", tmp);
ui_nice_print("%s", tmp);
yaffs_files_count++;
if (yaffs_files_total != 0)
ui_set_progress((float)yaffs_files_count / (float)yaffs_files_total);
Expand Down
22 changes: 22 additions & 0 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,18 @@ void ui_reset_progress()
pthread_mutex_unlock(&gUpdateMutex);
}

static long delta_milliseconds(struct timeval from, struct timeval to) {
long delta_sec = (to.tv_sec - from.tv_sec)*1000;
long delta_usec = (to.tv_usec - from.tv_usec)/1000;
return (delta_sec + delta_usec);
}

static struct timeval lastupdate = (struct timeval) {0};
static int ui_nice = 0;
void ui_set_nice(int enabled) {
ui_nice = enabled;
}

void ui_print(const char *fmt, ...)
{
char buf[256];
Expand All @@ -846,6 +858,16 @@ void ui_print(const char *fmt, ...)
if (ui_log_stdout)
fputs(buf, stdout);

// if we are running 'ui nice' mode, we do not want to force a screen update
// for this line if not necessary.
if (ui_nice) {
struct timeval curtime;
gettimeofday(&curtime, NULL);
if (delta_milliseconds(lastupdate, curtime) > 1000)
return;
lastupdate = curtime;
}

// This can get called before ui_init(), so be careful.
pthread_mutex_lock(&gUpdateMutex);
if (text_rows > 0 && text_cols > 0) {
Expand Down

0 comments on commit 8842575

Please sign in to comment.