Commit 7226d972852afba286a7e46e9f3854667e1a816f

Stefan Sperling 2019-02-21T22:20:06

tog: better thread synchronization in scroll_down()

diff --git a/tog/tog.c b/tog/tog.c
index 00edfdb..e7f70ed 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1204,24 +1204,23 @@ scroll_down(struct commit_queue_entry **first_displayed_entry, int maxscroll,
 
 	do {
 		pentry = TAILQ_NEXT(*last_displayed_entry, entry);
-		if (pentry == NULL)
+		if (pentry == NULL) {
 			*commits_needed = maxscroll + 20;
-		while (pentry == NULL) {
-			int errcode;
-			if (*log_complete)
-				break;
-			errcode = pthread_cond_signal(need_commits);
-			if (errcode)
-				return got_error_set_errno(errcode);
-			errcode = pthread_mutex_unlock(&tog_mutex);
-			if (errcode)
-				return got_error_set_errno(errcode);
-			pthread_yield();
-			errcode = pthread_mutex_lock(&tog_mutex);
-			if (errcode)
-				return got_error_set_errno(errcode);
-			pentry = TAILQ_NEXT(*last_displayed_entry, entry);
+			while (*commits_needed > 0) {
+				int errcode;
+				errcode = pthread_cond_signal(need_commits);
+				if (errcode)
+					return got_error_set_errno(errcode);
+				errcode = pthread_mutex_unlock(&tog_mutex);
+				if (errcode)
+					return got_error_set_errno(errcode);
+				pthread_yield();
+				errcode = pthread_mutex_lock(&tog_mutex);
+				if (errcode)
+					return got_error_set_errno(errcode);
+			}
 		}
+		pentry = TAILQ_NEXT(*last_displayed_entry, entry);
 		if (pentry == NULL)
 			break;