Start implementing signal handler code once in frontend driver code

This commit is contained in:
twinaphex 2016-07-08 02:38:33 +02:00
parent 24bfad033f
commit 76cc6fd8ec
10 changed files with 86 additions and 88 deletions

View File

@ -18,6 +18,31 @@
#include <stdint.h>
#include <string.h>
#include <signal.h>
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",
};

View File

@ -26,6 +26,7 @@
#include <sys/utsname.h>
#include <sys/resource.h>
#include <signal.h>
#include <pthread.h>
#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

View File

@ -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,

View File

@ -16,8 +16,6 @@
#ifndef __EGL_COMMON_H
#define __EGL_COMMON_H
#include <signal.h>
#ifdef HAVE_GBM
/* presense or absense of this include makes egl.h change NativeWindowType between gbm_device* and _XDisplay* */
#include <gbm.h>
@ -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,

View File

@ -24,6 +24,7 @@
#include <X11/Xatom.h>
#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. */

View File

@ -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);

View File

@ -31,6 +31,7 @@
#include <retro_inline.h>
#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);

View File

@ -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,

View File

@ -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;

View File

@ -19,6 +19,8 @@
#include <stdint.h>
#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;