Commit 82954512f323c8a2d4f89d51be1e6b0f707b6c3a

Stefan Sperling 2020-02-03T18:10:18

revert 6b8a2b8fcd99c4365b1aa9513c0f0149beac2491; it broke 'n' (search next) In the log view, 'n' sometimes failed to search for the next matching commit and tog dead-locked. So a yield or mutex unlock/lock is required for search to work. Perhaps we need a different fix?

diff --git a/tog/tog.c b/tog/tog.c
index ca95914..99c464b 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -755,6 +755,15 @@ view_input(struct tog_view **new, struct tog_view **dead,
 	*focus = NULL;
 
 	if (view->searching && !view->search_next_done) {
+		errcode = pthread_mutex_unlock(&tog_mutex);
+		if (errcode)
+			return got_error_set_errno(errcode,
+			    "pthread_mutex_unlock");
+		pthread_yield();
+		errcode = pthread_mutex_lock(&tog_mutex);
+		if (errcode)
+			return got_error_set_errno(errcode,
+			    "pthread_mutex_lock");
 		view->search_next(view);
 		return NULL;
 	}
@@ -1633,6 +1642,16 @@ trigger_log_thread(int load_all, int *commits_needed, int *log_complete,
 		if (errcode)
 			return got_error_set_errno(errcode,
 			    "pthread_cond_signal");
+		errcode = pthread_mutex_unlock(&tog_mutex);
+		if (errcode)
+			return got_error_set_errno(errcode,
+			    "pthread_mutex_unlock");
+		pthread_yield();
+		errcode = pthread_mutex_lock(&tog_mutex);
+		if (errcode)
+			return got_error_set_errno(errcode,
+			    "pthread_mutex_lock");
+
 		if (*commits_needed > 0 && (!load_all || --max_wait <= 0)) {
 			/*
 			 * Thread is not done yet; lose a key press