From 76cc6fd8ec1a0eda9c04ae2e0750d99003b260dc Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 8 Jul 2016 02:38:33 +0200 Subject: [PATCH] Start implementing signal handler code once in frontend driver code --- frontend/drivers/platform_bsd.c | 31 +++++++++++++++++++++--- frontend/drivers/platform_linux.c | 40 ++++++++++++++++++++++++++++--- gfx/common/egl_common.c | 29 ++++------------------ gfx/common/egl_common.h | 5 ---- gfx/common/x11_common.c | 30 +++++------------------ gfx/common/x11_common.h | 2 -- gfx/drivers/xvideo.c | 4 +++- gfx/drivers_context/drm_ctx.c | 26 +++----------------- gfx/drivers_context/x_ctx.c | 3 ++- gfx/drivers_context/xegl_ctx.c | 4 +++- 10 files changed, 86 insertions(+), 88 deletions(-) diff --git a/frontend/drivers/platform_bsd.c b/frontend/drivers/platform_bsd.c index 957aaf4861..b4938c77be 100644 --- a/frontend/drivers/platform_bsd.c +++ b/frontend/drivers/platform_bsd.c @@ -18,6 +18,31 @@ #include #include +#include + +static volatile sig_atomic_t bsd_sighandler_quit; + +static void frontend_bsd_install_signal_handlers(void) +{ + struct sigaction sa; + + sa.sa_sigaction = NULL; + sa.sa_handler = frontend_bsd_sighandler; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGINT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); +} + +static int frontend_bsd_get_signal_handler_state(void) +{ + return (int)bsd_sighandler_quit; +} + +static void frontend_bsd_destroy_signal_handler_state(void) +{ + bsd_sighandler_quit = 0; +} frontend_ctx_driver_t frontend_ctx_bsd = { NULL, /* environment_get */ @@ -37,8 +62,8 @@ frontend_ctx_driver_t frontend_ctx_bsd = { NULL, /* parse_drive_list */ NULL, /* get_mem_total */ NULL, /* get_mem_free */ - NULL, /* install_signal_handler */ - NULL, /* get_sighandler_state */ - NULL, /* destroy_signal_handler_state */ + frontend_bsd_install_signal_handler, + frontend_bsd_get_signal_handler_state, + frontend_bsd_destroy_signal_handler_state, "bsd", }; diff --git a/frontend/drivers/platform_linux.c b/frontend/drivers/platform_linux.c index 5ddecf9e95..28e6c26b02 100644 --- a/frontend/drivers/platform_linux.c +++ b/frontend/drivers/platform_linux.c @@ -26,6 +26,7 @@ #include #include +#include #include #ifdef ANDROID @@ -66,6 +67,7 @@ enum struct android_app *g_android; + static pthread_key_t thread_key; static char screenshot_dir[PATH_MAX_LENGTH]; @@ -81,6 +83,8 @@ static const char *proc_acpi_sysfs_battery_path = "/sys/class/power_supply"; static const char *proc_acpi_ac_adapter_path = "/proc/acpi/ac_adapter"; #endif +static volatile sig_atomic_t linux_sighandler_quit; + #ifndef HAVE_DYNAMIC static enum frontend_fork linux_fork_mode = FRONTEND_FORK_NONE; #endif @@ -1959,6 +1963,36 @@ static uint64_t frontend_linux_get_mem_used(void) return total - freemem - buffers - cached; } +static void frontend_linux_sighandler(int sig) +{ + (void)sig; + if (linux_sighandler_quit) + exit(1); + linux_sighandler_quit = 1; +} + +static void frontend_linux_install_signal_handlers(void) +{ + struct sigaction sa; + + sa.sa_sigaction = NULL; + sa.sa_handler = frontend_linux_sighandler; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGINT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); +} + +static int frontend_linux_get_signal_handler_state(void) +{ + return (int)linux_sighandler_quit; +} + +static void frontend_linux_destroy_signal_handler_state(void) +{ + linux_sighandler_quit = 0; +} + frontend_ctx_driver_t frontend_ctx_linux = { frontend_linux_get_env, /* environment_get */ frontend_linux_init, /* init */ @@ -1995,9 +2029,9 @@ frontend_ctx_driver_t frontend_ctx_linux = { #endif frontend_linux_get_mem_total, frontend_linux_get_mem_used, - NULL, /* install_signal_handler */ - NULL, /* get_sighandler_state */ - NULL, /* destroy_sighandler_state */ + frontend_linux_install_signal_handlers, + frontend_linux_get_signal_handler_state, + frontend_linux_destroy_signal_handler_state, #ifdef ANDROID "android" #else diff --git a/gfx/common/egl_common.c b/gfx/common/egl_common.c index 6be7c1cbfa..a1a3aee483 100644 --- a/gfx/common/egl_common.c +++ b/gfx/common/egl_common.c @@ -23,7 +23,8 @@ #include "gl_common.h" #endif -volatile sig_atomic_t g_egl_quit; +#include "../../frontend/frontend_driver.h" + bool g_egl_inited; unsigned g_egl_major = 0; @@ -100,8 +101,9 @@ void egl_destroy(egl_ctx_data_t *egl) egl->surf = EGL_NO_SURFACE; egl->dpy = EGL_NO_DISPLAY; egl->config = 0; - g_egl_quit = 0; g_egl_inited = false; + + frontend_driver_destroy_signal_handler_state(); } void egl_bind_hw_render(egl_ctx_data_t *egl, bool enable) @@ -166,29 +168,6 @@ void egl_get_video_size(egl_ctx_data_t *egl, unsigned *width, unsigned *height) } } -#ifndef HAVE_BB10 -static void egl_sighandler(int sig) -{ - (void)sig; - if (g_egl_quit) exit(1); - g_egl_quit = 1; -} -#endif - -void egl_install_sighandlers(void) -{ -#ifndef HAVE_BB10 - struct sigaction sa; - - sa.sa_sigaction = NULL; - sa.sa_handler = egl_sighandler; - sa.sa_flags = SA_RESTART; - sigemptyset(&sa.sa_mask); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); -#endif -} - bool egl_init_context(egl_ctx_data_t *egl, void *display_data, EGLint *major, EGLint *minor, diff --git a/gfx/common/egl_common.h b/gfx/common/egl_common.h index 0f153219b3..e5658154d3 100644 --- a/gfx/common/egl_common.h +++ b/gfx/common/egl_common.h @@ -16,8 +16,6 @@ #ifndef __EGL_COMMON_H #define __EGL_COMMON_H -#include - #ifdef HAVE_GBM /* presense or absense of this include makes egl.h change NativeWindowType between gbm_device* and _XDisplay* */ #include @@ -61,7 +59,6 @@ typedef struct bool use_hw_ctx; } egl_ctx_data_t; -extern volatile sig_atomic_t g_egl_quit; extern bool g_egl_inited; /* bind_api is called before init so we need these, please @@ -83,8 +80,6 @@ void egl_set_swap_interval(egl_ctx_data_t *egl, unsigned interval); void egl_get_video_size(egl_ctx_data_t *egl, unsigned *width, unsigned *height); -void egl_install_sighandlers(void); - bool egl_init_context(egl_ctx_data_t *egl, void *display_data, EGLint *major, diff --git a/gfx/common/x11_common.c b/gfx/common/x11_common.c index ddf0294613..b3c4f72e55 100644 --- a/gfx/common/x11_common.c +++ b/gfx/common/x11_common.c @@ -24,6 +24,7 @@ #include #include "x11_common.h" +#include "../../frontend/frontend_driver.h" #include "../../input/common/input_x11_common.h" #include "../../configuration.h" #include "../../verbosity.h" @@ -38,7 +39,6 @@ static Atom XA_NET_WM_STATE_FULLSCREEN; static Atom XA_NET_MOVERESIZE_WINDOW; static Atom g_x11_quit_atom; -static volatile sig_atomic_t g_x11_quit; static bool g_x11_has_focus; static XIM g_x11_xim; static XIC g_x11_xic; @@ -419,12 +419,12 @@ bool x11_alive(void *data) case ClientMessage: if (event.xclient.window == g_x11_win && (Atom)event.xclient.data.l[0] == g_x11_quit_atom) - g_x11_quit = true; + frontend_driver_destroy_signal_handler_state(); break; case DestroyNotify: if (event.xdestroywindow.window == g_x11_win) - g_x11_quit = true; + frontend_driver_destroy_signal_handler_state(); break; case MapNotify: @@ -452,7 +452,7 @@ bool x11_alive(void *data) } } - return !g_x11_quit; + return !((bool)frontend_driver_get_signal_handler_state()); } void x11_check_window(void *data, bool *quit, @@ -472,7 +472,7 @@ void x11_check_window(void *data, bool *quit, x11_alive(data); - *quit = g_x11_quit; + *quit = (bool)frontend_driver_get_signal_handler_state(); } void x11_get_video_size(void *data, unsigned *width, unsigned *height) @@ -516,27 +516,9 @@ bool x11_has_focus(void *data) return (win == g_x11_win && g_x11_has_focus) || g_x11_true_full; } -static void x11_sighandler(int sig) -{ - (void)sig; - if (g_x11_quit) exit(1); - g_x11_quit = 1; -} - -void x11_install_sighandlers(void) -{ - struct sigaction sa = {{0}}; - - sa.sa_handler = x11_sighandler; - sa.sa_flags = SA_RESTART; - sigemptyset(&sa.sa_mask); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); -} - bool x11_connect(void) { - g_x11_quit = 0; + frontend_driver_destroy_signal_handler_state(); /* Keep one g_x11_dpy alive the entire process lifetime. * This is necessary for nVidia's EGL implementation for now. */ diff --git a/gfx/common/x11_common.h b/gfx/common/x11_common.h index 4f27c991e4..0bfea3202f 100644 --- a/gfx/common/x11_common.h +++ b/gfx/common/x11_common.h @@ -80,8 +80,6 @@ bool x11_has_focus_internal(void *data); bool x11_alive(void *data); -void x11_install_sighandlers(void); - bool x11_connect(void); void x11_update_window_title(void *data); diff --git a/gfx/drivers/xvideo.c b/gfx/drivers/xvideo.c index 34d14e80c8..7ecd1a193f 100644 --- a/gfx/drivers/xvideo.c +++ b/gfx/drivers/xvideo.c @@ -31,6 +31,7 @@ #include #include "../../driver.h" +#include "../../frontend/frontend_driver.h" #include "../../general.h" #include "../../verbosity.h" #include "../font_driver.h" @@ -567,7 +568,8 @@ static void *xv_init(const video_info_t *video, memset(xv->image->data, 128, xv->image->data_size); x11_install_quit_atom(); - x11_install_sighandlers(); + + frontend_driver_install_signal_handler(); xv_set_nonblock_state(xv, !video->vsync); diff --git a/gfx/drivers_context/drm_ctx.c b/gfx/drivers_context/drm_ctx.c index c8d1c029e0..efd6f1d790 100644 --- a/gfx/drivers_context/drm_ctx.c +++ b/gfx/drivers_context/drm_ctx.c @@ -38,6 +38,7 @@ #include "../../verbosity.h" #include "../../driver.h" #include "../../runloop.h" +#include "../../frontend/frontend_driver.h" #include "../common/drm_common.h" #ifdef HAVE_EGL @@ -60,8 +61,6 @@ #endif -static volatile sig_atomic_t drm_quit = 0; - static enum gfx_ctx_api drm_api; static struct gbm_bo *g_bo; @@ -90,25 +89,6 @@ struct drm_fb uint32_t fb_id; }; -static void drm_sighandler(int sig) -{ - (void)sig; - if (drm_quit) exit(1); - drm_quit = 1; -} - -static void drm_install_sighandler(void) -{ - struct sigaction sa; - - sa.sa_sigaction = NULL; - sa.sa_handler = drm_sighandler; - sa.sa_flags = SA_RESTART; - sigemptyset(&sa.sa_mask); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); -} - static void drm_fb_destroy_callback(struct gbm_bo *bo, void *data) { struct drm_fb *fb = (struct drm_fb*)data; @@ -170,7 +150,7 @@ static void gfx_ctx_drm_check_window(void *data, bool *quit, (void)height; *resize = false; - *quit = drm_quit; + *quit = (bool)frontend_driver_get_signal_handler_state(); } @@ -646,7 +626,7 @@ static bool gfx_ctx_drm_set_video_mode(void *data, if (!drm) return false; - drm_install_sighandler(); + frontend_driver_install_signal_handler(); /* If we use black frame insertion, * we fake a 60 Hz monitor for 120 Hz one, diff --git a/gfx/drivers_context/x_ctx.c b/gfx/drivers_context/x_ctx.c index 4a52efb6f3..cdc1647411 100644 --- a/gfx/drivers_context/x_ctx.c +++ b/gfx/drivers_context/x_ctx.c @@ -23,6 +23,7 @@ #include "../../driver.h" +#include "../../frontend/frontend_driver.h" #include "../common/gl_common.h" #include "../common/x11_common.h" @@ -433,7 +434,7 @@ static bool gfx_ctx_x_set_video_mode(void *data, settings_t *settings = config_get_ptr(); gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t*)data; - x11_install_sighandlers(); + frontend_driver_install_signal_handler(); if (!x) return false; diff --git a/gfx/drivers_context/xegl_ctx.c b/gfx/drivers_context/xegl_ctx.c index 5d21b9c250..69199a9837 100644 --- a/gfx/drivers_context/xegl_ctx.c +++ b/gfx/drivers_context/xegl_ctx.c @@ -19,6 +19,8 @@ #include #include "../../driver.h" +#include "../../../frontend/frontend_driver.h" + #include "../common/egl_common.h" #include "../common/gl_common.h" #include "../common/x11_common.h" @@ -270,7 +272,7 @@ static bool gfx_ctx_xegl_set_video_mode(void *data, int (*old_handler)(Display*, XErrorEvent*) = NULL; - x11_install_sighandlers(); + frontend_driver_install_signal_handler(); windowed_full = settings->video.windowed_fullscreen;