tog: better thread synchronization in scroll_down()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
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;