Start implementing signal handler code once in frontend driver code
This commit is contained in:
parent
24bfad033f
commit
76cc6fd8ec
|
@ -18,6 +18,31 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.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 = {
|
frontend_ctx_driver_t frontend_ctx_bsd = {
|
||||||
NULL, /* environment_get */
|
NULL, /* environment_get */
|
||||||
|
@ -37,8 +62,8 @@ frontend_ctx_driver_t frontend_ctx_bsd = {
|
||||||
NULL, /* parse_drive_list */
|
NULL, /* parse_drive_list */
|
||||||
NULL, /* get_mem_total */
|
NULL, /* get_mem_total */
|
||||||
NULL, /* get_mem_free */
|
NULL, /* get_mem_free */
|
||||||
NULL, /* install_signal_handler */
|
frontend_bsd_install_signal_handler,
|
||||||
NULL, /* get_sighandler_state */
|
frontend_bsd_get_signal_handler_state,
|
||||||
NULL, /* destroy_signal_handler_state */
|
frontend_bsd_destroy_signal_handler_state,
|
||||||
"bsd",
|
"bsd",
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
|
@ -66,6 +67,7 @@ enum
|
||||||
|
|
||||||
struct android_app *g_android;
|
struct android_app *g_android;
|
||||||
|
|
||||||
|
|
||||||
static pthread_key_t thread_key;
|
static pthread_key_t thread_key;
|
||||||
|
|
||||||
static char screenshot_dir[PATH_MAX_LENGTH];
|
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";
|
static const char *proc_acpi_ac_adapter_path = "/proc/acpi/ac_adapter";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static volatile sig_atomic_t linux_sighandler_quit;
|
||||||
|
|
||||||
#ifndef HAVE_DYNAMIC
|
#ifndef HAVE_DYNAMIC
|
||||||
static enum frontend_fork linux_fork_mode = FRONTEND_FORK_NONE;
|
static enum frontend_fork linux_fork_mode = FRONTEND_FORK_NONE;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1959,6 +1963,36 @@ static uint64_t frontend_linux_get_mem_used(void)
|
||||||
return total - freemem - buffers - cached;
|
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_ctx_driver_t frontend_ctx_linux = {
|
||||||
frontend_linux_get_env, /* environment_get */
|
frontend_linux_get_env, /* environment_get */
|
||||||
frontend_linux_init, /* init */
|
frontend_linux_init, /* init */
|
||||||
|
@ -1995,9 +2029,9 @@ frontend_ctx_driver_t frontend_ctx_linux = {
|
||||||
#endif
|
#endif
|
||||||
frontend_linux_get_mem_total,
|
frontend_linux_get_mem_total,
|
||||||
frontend_linux_get_mem_used,
|
frontend_linux_get_mem_used,
|
||||||
NULL, /* install_signal_handler */
|
frontend_linux_install_signal_handlers,
|
||||||
NULL, /* get_sighandler_state */
|
frontend_linux_get_signal_handler_state,
|
||||||
NULL, /* destroy_sighandler_state */
|
frontend_linux_destroy_signal_handler_state,
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
"android"
|
"android"
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -23,7 +23,8 @@
|
||||||
#include "gl_common.h"
|
#include "gl_common.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
volatile sig_atomic_t g_egl_quit;
|
#include "../../frontend/frontend_driver.h"
|
||||||
|
|
||||||
bool g_egl_inited;
|
bool g_egl_inited;
|
||||||
|
|
||||||
unsigned g_egl_major = 0;
|
unsigned g_egl_major = 0;
|
||||||
|
@ -100,8 +101,9 @@ void egl_destroy(egl_ctx_data_t *egl)
|
||||||
egl->surf = EGL_NO_SURFACE;
|
egl->surf = EGL_NO_SURFACE;
|
||||||
egl->dpy = EGL_NO_DISPLAY;
|
egl->dpy = EGL_NO_DISPLAY;
|
||||||
egl->config = 0;
|
egl->config = 0;
|
||||||
g_egl_quit = 0;
|
|
||||||
g_egl_inited = false;
|
g_egl_inited = false;
|
||||||
|
|
||||||
|
frontend_driver_destroy_signal_handler_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
void egl_bind_hw_render(egl_ctx_data_t *egl, bool enable)
|
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,
|
bool egl_init_context(egl_ctx_data_t *egl,
|
||||||
void *display_data,
|
void *display_data,
|
||||||
EGLint *major, EGLint *minor,
|
EGLint *major, EGLint *minor,
|
||||||
|
|
|
@ -16,8 +16,6 @@
|
||||||
#ifndef __EGL_COMMON_H
|
#ifndef __EGL_COMMON_H
|
||||||
#define __EGL_COMMON_H
|
#define __EGL_COMMON_H
|
||||||
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#ifdef HAVE_GBM
|
#ifdef HAVE_GBM
|
||||||
/* presense or absense of this include makes egl.h change NativeWindowType between gbm_device* and _XDisplay* */
|
/* presense or absense of this include makes egl.h change NativeWindowType between gbm_device* and _XDisplay* */
|
||||||
#include <gbm.h>
|
#include <gbm.h>
|
||||||
|
@ -61,7 +59,6 @@ typedef struct
|
||||||
bool use_hw_ctx;
|
bool use_hw_ctx;
|
||||||
} egl_ctx_data_t;
|
} egl_ctx_data_t;
|
||||||
|
|
||||||
extern volatile sig_atomic_t g_egl_quit;
|
|
||||||
extern bool g_egl_inited;
|
extern bool g_egl_inited;
|
||||||
|
|
||||||
/* bind_api is called before init so we need these, please
|
/* 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_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,
|
bool egl_init_context(egl_ctx_data_t *egl,
|
||||||
void *display_data,
|
void *display_data,
|
||||||
EGLint *major,
|
EGLint *major,
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
|
||||||
#include "x11_common.h"
|
#include "x11_common.h"
|
||||||
|
#include "../../frontend/frontend_driver.h"
|
||||||
#include "../../input/common/input_x11_common.h"
|
#include "../../input/common/input_x11_common.h"
|
||||||
#include "../../configuration.h"
|
#include "../../configuration.h"
|
||||||
#include "../../verbosity.h"
|
#include "../../verbosity.h"
|
||||||
|
@ -38,7 +39,6 @@ static Atom XA_NET_WM_STATE_FULLSCREEN;
|
||||||
static Atom XA_NET_MOVERESIZE_WINDOW;
|
static Atom XA_NET_MOVERESIZE_WINDOW;
|
||||||
|
|
||||||
static Atom g_x11_quit_atom;
|
static Atom g_x11_quit_atom;
|
||||||
static volatile sig_atomic_t g_x11_quit;
|
|
||||||
static bool g_x11_has_focus;
|
static bool g_x11_has_focus;
|
||||||
static XIM g_x11_xim;
|
static XIM g_x11_xim;
|
||||||
static XIC g_x11_xic;
|
static XIC g_x11_xic;
|
||||||
|
@ -419,12 +419,12 @@ bool x11_alive(void *data)
|
||||||
case ClientMessage:
|
case ClientMessage:
|
||||||
if (event.xclient.window == g_x11_win &&
|
if (event.xclient.window == g_x11_win &&
|
||||||
(Atom)event.xclient.data.l[0] == g_x11_quit_atom)
|
(Atom)event.xclient.data.l[0] == g_x11_quit_atom)
|
||||||
g_x11_quit = true;
|
frontend_driver_destroy_signal_handler_state();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DestroyNotify:
|
case DestroyNotify:
|
||||||
if (event.xdestroywindow.window == g_x11_win)
|
if (event.xdestroywindow.window == g_x11_win)
|
||||||
g_x11_quit = true;
|
frontend_driver_destroy_signal_handler_state();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MapNotify:
|
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,
|
void x11_check_window(void *data, bool *quit,
|
||||||
|
@ -472,7 +472,7 @@ void x11_check_window(void *data, bool *quit,
|
||||||
|
|
||||||
x11_alive(data);
|
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)
|
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;
|
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)
|
bool x11_connect(void)
|
||||||
{
|
{
|
||||||
g_x11_quit = 0;
|
frontend_driver_destroy_signal_handler_state();
|
||||||
|
|
||||||
/* Keep one g_x11_dpy alive the entire process lifetime.
|
/* Keep one g_x11_dpy alive the entire process lifetime.
|
||||||
* This is necessary for nVidia's EGL implementation for now. */
|
* This is necessary for nVidia's EGL implementation for now. */
|
||||||
|
|
|
@ -80,8 +80,6 @@ bool x11_has_focus_internal(void *data);
|
||||||
|
|
||||||
bool x11_alive(void *data);
|
bool x11_alive(void *data);
|
||||||
|
|
||||||
void x11_install_sighandlers(void);
|
|
||||||
|
|
||||||
bool x11_connect(void);
|
bool x11_connect(void);
|
||||||
|
|
||||||
void x11_update_window_title(void *data);
|
void x11_update_window_title(void *data);
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include <retro_inline.h>
|
#include <retro_inline.h>
|
||||||
|
|
||||||
#include "../../driver.h"
|
#include "../../driver.h"
|
||||||
|
#include "../../frontend/frontend_driver.h"
|
||||||
#include "../../general.h"
|
#include "../../general.h"
|
||||||
#include "../../verbosity.h"
|
#include "../../verbosity.h"
|
||||||
#include "../font_driver.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);
|
memset(xv->image->data, 128, xv->image->data_size);
|
||||||
|
|
||||||
x11_install_quit_atom();
|
x11_install_quit_atom();
|
||||||
x11_install_sighandlers();
|
|
||||||
|
frontend_driver_install_signal_handler();
|
||||||
|
|
||||||
xv_set_nonblock_state(xv, !video->vsync);
|
xv_set_nonblock_state(xv, !video->vsync);
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "../../verbosity.h"
|
#include "../../verbosity.h"
|
||||||
#include "../../driver.h"
|
#include "../../driver.h"
|
||||||
#include "../../runloop.h"
|
#include "../../runloop.h"
|
||||||
|
#include "../../frontend/frontend_driver.h"
|
||||||
#include "../common/drm_common.h"
|
#include "../common/drm_common.h"
|
||||||
|
|
||||||
#ifdef HAVE_EGL
|
#ifdef HAVE_EGL
|
||||||
|
@ -60,8 +61,6 @@
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static volatile sig_atomic_t drm_quit = 0;
|
|
||||||
|
|
||||||
static enum gfx_ctx_api drm_api;
|
static enum gfx_ctx_api drm_api;
|
||||||
|
|
||||||
static struct gbm_bo *g_bo;
|
static struct gbm_bo *g_bo;
|
||||||
|
@ -90,25 +89,6 @@ struct drm_fb
|
||||||
uint32_t fb_id;
|
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)
|
static void drm_fb_destroy_callback(struct gbm_bo *bo, void *data)
|
||||||
{
|
{
|
||||||
struct drm_fb *fb = (struct drm_fb*)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;
|
(void)height;
|
||||||
|
|
||||||
*resize = false;
|
*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)
|
if (!drm)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
drm_install_sighandler();
|
frontend_driver_install_signal_handler();
|
||||||
|
|
||||||
/* If we use black frame insertion,
|
/* If we use black frame insertion,
|
||||||
* we fake a 60 Hz monitor for 120 Hz one,
|
* we fake a 60 Hz monitor for 120 Hz one,
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "../../driver.h"
|
#include "../../driver.h"
|
||||||
|
|
||||||
|
#include "../../frontend/frontend_driver.h"
|
||||||
#include "../common/gl_common.h"
|
#include "../common/gl_common.h"
|
||||||
#include "../common/x11_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();
|
settings_t *settings = config_get_ptr();
|
||||||
gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t*)data;
|
gfx_ctx_x_data_t *x = (gfx_ctx_x_data_t*)data;
|
||||||
|
|
||||||
x11_install_sighandlers();
|
frontend_driver_install_signal_handler();
|
||||||
|
|
||||||
if (!x)
|
if (!x)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "../../driver.h"
|
#include "../../driver.h"
|
||||||
|
#include "../../../frontend/frontend_driver.h"
|
||||||
|
|
||||||
#include "../common/egl_common.h"
|
#include "../common/egl_common.h"
|
||||||
#include "../common/gl_common.h"
|
#include "../common/gl_common.h"
|
||||||
#include "../common/x11_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;
|
int (*old_handler)(Display*, XErrorEvent*) = NULL;
|
||||||
|
|
||||||
x11_install_sighandlers();
|
frontend_driver_install_signal_handler();
|
||||||
|
|
||||||
windowed_full = settings->video.windowed_fullscreen;
|
windowed_full = settings->video.windowed_fullscreen;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue