From: Stefan Sperling Subject: Re: Remove unnecessary context switches To: Martin Pieuchot Cc: gameoftrees@openbsd.org Date: Sun, 19 Jan 2020 14:17:36 +0100 On Sun, Jan 19, 2020 at 01:46:16PM +0100, Martin Pieuchot wrote: > tog(1) calls pthread_yield(3) without good reason. This function > commonly indicates a better synchronisation primitive is required. > However in the two places below this isn't the case. Removing those > calls makes the tool faster in my small tests. > > I'd appreciate more tests to be sure there's no regression. > > Ok? Sure. I don't see a downside and it still works. > diff --git tog/tog.c tog/tog.c > index c1f1819..db59543 100644 > --- tog/tog.c > +++ tog/tog.c > @@ -739,15 +739,6 @@ 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; > } > @@ -1652,16 +1643,6 @@ 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 > >