Skip to content

Commit

Permalink
x11: never forcefully terminate xdg-screensaver process
Browse files Browse the repository at this point in the history
It sometimes happens on exit, and it's probably a bad idea. If the
process hangs on exit (possibly due to stupid hardcoded timeouts it's
doing), mpv will also hang now, unfortunately.

(cherry picked from commit be9bf4c)
  • Loading branch information
wm4 authored and Diogo Franco (Kovensky) committed May 19, 2015
1 parent 4d6470f commit a7794d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 5 additions & 8 deletions video/out/x11_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,11 @@ static void *screensaver_thread(void *arg)
// don't queue multiple wakeups
while (!sem_trywait(&x11->screensaver_sem)) {}

if (mp_cancel_test(x11->screensaver_terminate))
if (atomic_load(&x11->screensaver_terminate))
break;

char *args[] = {"xdg-screensaver", "reset", NULL};
if (mp_subprocess(args, x11->screensaver_terminate, NULL, NULL,
NULL, &(char*){0}))
{
if (mp_subprocess(args, NULL, NULL, NULL, NULL, &(char*){0})) {
MP_WARN(x11, "Disabling screensaver failed.\n");
break;
}
Expand All @@ -515,13 +513,12 @@ int vo_x11_init(struct vo *vo)
};
vo->x11 = x11;

x11->screensaver_terminate = mp_cancel_new(x11);
sem_init(&x11->screensaver_sem, 0, 0);
if (pthread_create(&x11->screensaver_thread, NULL, screensaver_thread, x11)) {
x11->screensaver_terminate = NULL;
sem_destroy(&x11->screensaver_sem);
goto error;
}
x11->screensaver_thread_running = true;

x11_error_output = x11->log;
XSetErrorHandler(x11_errorhandler);
Expand Down Expand Up @@ -731,8 +728,8 @@ void vo_x11_uninit(struct vo *vo)
XCloseDisplay(x11->display);
}

if (x11->screensaver_terminate) {
mp_cancel_trigger(x11->screensaver_terminate);
if (x11->screensaver_thread_running) {
atomic_store(&x11->screensaver_terminate, true);
sem_post(&x11->screensaver_sem);
pthread_join(x11->screensaver_thread, NULL);
sem_destroy(&x11->screensaver_sem);
Expand Down
4 changes: 3 additions & 1 deletion video/out/x11_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>

#include "osdep/atomics.h"
#include "osdep/semaphore.h"

#include "common/common.h"
Expand Down Expand Up @@ -61,8 +62,9 @@ struct vo_x11_state {
bool dpms_touched;
double screensaver_time_last;
pthread_t screensaver_thread;
bool screensaver_thread_running;
sem_t screensaver_sem;
struct mp_cancel *screensaver_terminate;
atomic_bool screensaver_terminate;

XIM xim;
XIC xic;
Expand Down

0 comments on commit a7794d6

Please sign in to comment.