Give watches and timers names to ease debugging

This commit is contained in:
Kovid Goyal 2018-07-10 09:18:11 +05:30
parent 4070255dde
commit 6879a492dc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
7 changed files with 20 additions and 15 deletions

10
glfw/backend_utils.c vendored
View File

@ -44,9 +44,10 @@ update_fds(EventLoopData *eld) {
static id_type watch_counter = 0; static id_type watch_counter = 0;
id_type id_type
addWatch(EventLoopData *eld, int fd, int events, int enabled, watch_callback_func cb, void *cb_data) { addWatch(EventLoopData *eld, const char* name, int fd, int events, int enabled, watch_callback_func cb, void *cb_data) {
if (eld->watches_count >= sizeof(eld->watches)/sizeof(eld->watches[0])) return 0; if (eld->watches_count >= sizeof(eld->watches)/sizeof(eld->watches[0])) return 0;
Watch *w = eld->watches + eld->watches_count++; Watch *w = eld->watches + eld->watches_count++;
w->name = name;
w->fd = fd; w->events = events; w->enabled = enabled; w->fd = fd; w->events = events; w->enabled = enabled;
w->callback = cb; w->callback = cb;
w->callback_data = cb_data; w->callback_data = cb_data;
@ -97,10 +98,11 @@ update_timers(EventLoopData *eld) {
} }
id_type id_type
addTimer(EventLoopData *eld, double interval, int enabled, timer_callback_func cb, void *cb_data) { addTimer(EventLoopData *eld, const char *name, double interval, int enabled, timer_callback_func cb, void *cb_data) {
if (eld->timers_count >= sizeof(eld->timers)/sizeof(eld->timers[0])) return 0; if (eld->timers_count >= sizeof(eld->timers)/sizeof(eld->timers[0])) return 0;
Timer *t = eld->timers + eld->timers_count++; Timer *t = eld->timers + eld->timers_count++;
t->interval = interval; t->interval = interval;
t->name = name;
t->trigger_at = enabled ? monotonic() + interval : DBL_MAX; t->trigger_at = enabled ? monotonic() + interval : DBL_MAX;
t->callback = cb; t->callback = cb;
t->callback_data = cb_data; t->callback_data = cb_data;
@ -199,8 +201,8 @@ drain_wakeup_fd(int fd, int events, void* data) {
void void
initPollData(EventLoopData *eld, int wakeup_fd, int display_fd) { initPollData(EventLoopData *eld, int wakeup_fd, int display_fd) {
addWatch(eld, display_fd, POLLIN, 1, NULL, NULL); addWatch(eld, "display", display_fd, POLLIN, 1, NULL, NULL);
addWatch(eld, wakeup_fd, POLLIN, 1, drain_wakeup_fd, NULL); addWatch(eld, "wakeup", wakeup_fd, POLLIN, 1, drain_wakeup_fd, NULL);
} }

View File

@ -37,6 +37,7 @@ typedef struct {
watch_callback_func callback; watch_callback_func callback;
void *callback_data; void *callback_data;
id_type id; id_type id;
const char *name;
} Watch; } Watch;
typedef struct { typedef struct {
@ -44,6 +45,7 @@ typedef struct {
double interval, trigger_at; double interval, trigger_at;
timer_callback_func callback; timer_callback_func callback;
void *callback_data; void *callback_data;
const char *name;
} Timer; } Timer;
@ -56,10 +58,10 @@ typedef struct {
} EventLoopData; } EventLoopData;
id_type addWatch(EventLoopData *eld, int fd, int events, int enabled, watch_callback_func cb, void *cb_data); id_type addWatch(EventLoopData *eld, const char *name, int fd, int events, int enabled, watch_callback_func cb, void *cb_data);
void removeWatch(EventLoopData *eld, id_type watch_id); void removeWatch(EventLoopData *eld, id_type watch_id);
void toggleWatch(EventLoopData *eld, id_type watch_id, int enabled); void toggleWatch(EventLoopData *eld, id_type watch_id, int enabled);
id_type addTimer(EventLoopData *eld, double interval, int enabled, timer_callback_func cb, void *cb_data); id_type addTimer(EventLoopData *eld, const char *name, double interval, int enabled, timer_callback_func cb, void *cb_data);
void removeTimer(EventLoopData *eld, id_type timer_id); void removeTimer(EventLoopData *eld, id_type timer_id);
void toggleTimer(EventLoopData *eld, id_type timer_id, int enabled); void toggleTimer(EventLoopData *eld, id_type timer_id, int enabled);
void changeTimerInterval(EventLoopData *eld, id_type timer_id, double interval); void changeTimerInterval(EventLoopData *eld, id_type timer_id, double interval);

11
glfw/dbus_glfw.c vendored
View File

@ -28,6 +28,7 @@
#include "internal.h" #include "internal.h"
#include "dbus_glfw.h" #include "dbus_glfw.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
static inline void static inline void
report_error(DBusError *err, const char *fmt, ...) { report_error(DBusError *err, const char *fmt, ...) {
@ -72,7 +73,7 @@ events_for_watch(DBusWatch *watch) {
static dbus_bool_t static dbus_bool_t
add_dbus_watch(DBusWatch *watch, void *data) { add_dbus_watch(DBusWatch *watch, void *data) {
id_type watch_id = addWatch(dbus_data->eld, dbus_watch_get_unix_fd(watch), events_for_watch(watch), dbus_watch_get_enabled(watch), on_dbus_watch_ready, watch); id_type watch_id = addWatch(dbus_data->eld, data, dbus_watch_get_unix_fd(watch), events_for_watch(watch), dbus_watch_get_enabled(watch), on_dbus_watch_ready, watch);
if (!watch_id) return FALSE; if (!watch_id) return FALSE;
id_type *idp = malloc(sizeof(id_type)); id_type *idp = malloc(sizeof(id_type));
if (!idp) return FALSE; if (!idp) return FALSE;
@ -105,7 +106,7 @@ add_dbus_timeout(DBusTimeout *timeout, void *data) {
int enabled = dbus_timeout_get_enabled(timeout) ? 1 : 0; int enabled = dbus_timeout_get_enabled(timeout) ? 1 : 0;
double interval = ((double)dbus_timeout_get_interval(timeout)) / 1000.0; double interval = ((double)dbus_timeout_get_interval(timeout)) / 1000.0;
if (interval < 0) return FALSE; if (interval < 0) return FALSE;
id_type timer_id = addTimer(dbus_data->eld, interval, enabled, on_dbus_timer_ready, timeout); id_type timer_id = addTimer(dbus_data->eld, data, interval, enabled, on_dbus_timer_ready, timeout);
if (!timer_id) return FALSE; if (!timer_id) return FALSE;
id_type *idp = malloc(sizeof(id_type)); id_type *idp = malloc(sizeof(id_type));
if (!idp) return FALSE; if (!idp) return FALSE;
@ -129,7 +130,7 @@ toggle_dbus_timeout(DBusTimeout *timeout, void *data) {
DBusConnection* DBusConnection*
glfw_dbus_connect_to(const char *path, const char* err_msg) { glfw_dbus_connect_to(const char *path, const char* err_msg, const char *name) {
DBusError err; DBusError err;
dbus_error_init(&err); dbus_error_init(&err);
DBusConnection *ans = dbus_connection_open_private(path, &err); DBusConnection *ans = dbus_connection_open_private(path, &err);
@ -145,13 +146,13 @@ glfw_dbus_connect_to(const char *path, const char* err_msg) {
return NULL; return NULL;
} }
dbus_connection_flush(ans); dbus_connection_flush(ans);
if (!dbus_connection_set_watch_functions(ans, add_dbus_watch, remove_dbus_watch, toggle_dbus_watch, NULL, NULL)) { if (!dbus_connection_set_watch_functions(ans, add_dbus_watch, remove_dbus_watch, toggle_dbus_watch, (void*)name, NULL)) {
_glfwInputError(GLFW_PLATFORM_ERROR, "Failed to set DBUS watches on connection to: %s", path); _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to set DBUS watches on connection to: %s", path);
dbus_connection_close(ans); dbus_connection_close(ans);
dbus_connection_unref(ans); dbus_connection_unref(ans);
return NULL; return NULL;
} }
if (!dbus_connection_set_timeout_functions(ans, add_dbus_timeout, remove_dbus_timeout, toggle_dbus_timeout, NULL, NULL)) { if (!dbus_connection_set_timeout_functions(ans, add_dbus_timeout, remove_dbus_timeout, toggle_dbus_timeout, (void*)name, NULL)) {
_glfwInputError(GLFW_PLATFORM_ERROR, "Failed to set DBUS timeout functions on connection to: %s", path); _glfwInputError(GLFW_PLATFORM_ERROR, "Failed to set DBUS timeout functions on connection to: %s", path);
dbus_connection_close(ans); dbus_connection_close(ans);
dbus_connection_unref(ans); dbus_connection_unref(ans);

2
glfw/dbus_glfw.h vendored
View File

@ -39,7 +39,7 @@ typedef struct {
GLFWbool glfw_dbus_init(_GLFWDBUSData *dbus, EventLoopData *eld); GLFWbool glfw_dbus_init(_GLFWDBUSData *dbus, EventLoopData *eld);
void glfw_dbus_terminate(_GLFWDBUSData *dbus); void glfw_dbus_terminate(_GLFWDBUSData *dbus);
DBusConnection* glfw_dbus_connect_to(const char *path, const char* err_msg); DBusConnection* glfw_dbus_connect_to(const char *path, const char* err_msg, const char* name);
void glfw_dbus_close_connection(DBusConnection *conn); void glfw_dbus_close_connection(DBusConnection *conn);
GLFWbool glfw_dbus_call_void_method(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...); GLFWbool glfw_dbus_call_void_method(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...);
GLFWbool GLFWbool

2
glfw/ibus_glfw.c vendored
View File

@ -186,7 +186,7 @@ setup_connection(_GLFWIBUSData *ibus) {
ibus->conn = NULL; ibus->conn = NULL;
} }
debug("Connecting to IBUS daemon @ %s for IME input management\n", ibus->address); debug("Connecting to IBUS daemon @ %s for IME input management\n", ibus->address);
ibus->conn = glfw_dbus_connect_to(ibus->address, "Failed to connect to the IBUS daemon, with error"); ibus->conn = glfw_dbus_connect_to(ibus->address, "Failed to connect to the IBUS daemon, with error", "ibus");
if (!ibus->conn) return GLFW_FALSE; if (!ibus->conn) return GLFW_FALSE;
free((void*)ibus->input_ctx_path); ibus->input_ctx_path = NULL; free((void*)ibus->input_ctx_path); ibus->input_ctx_path = NULL;
if (!glfw_dbus_call_method_with_reply( if (!glfw_dbus_call_method_with_reply(

2
glfw/wl_init.c vendored
View File

@ -679,7 +679,7 @@ int _glfwPlatformInit(void)
} }
initPollData(&_glfw.wl.eventLoopData, _glfw.wl.eventLoopData.wakeupFds[0], wl_display_get_fd(_glfw.wl.display)); initPollData(&_glfw.wl.eventLoopData, _glfw.wl.eventLoopData.wakeupFds[0], wl_display_get_fd(_glfw.wl.display));
glfw_dbus_init(&_glfw.wl.dbus, &_glfw.wl.eventLoopData); glfw_dbus_init(&_glfw.wl.dbus, &_glfw.wl.eventLoopData);
_glfw.wl.keyRepeatInfo.keyRepeatTimer = addTimer(&_glfw.wl.eventLoopData, 0.5, 0, dispatchPendingKeyRepeats, NULL); _glfw.wl.keyRepeatInfo.keyRepeatTimer = addTimer(&_glfw.wl.eventLoopData, "wayland-keyrepeat", 0.5, 0, dispatchPendingKeyRepeats, NULL);
_glfw.wl.registry = wl_display_get_registry(_glfw.wl.display); _glfw.wl.registry = wl_display_get_registry(_glfw.wl.display);
wl_registry_add_listener(_glfw.wl.registry, &registryListener, NULL); wl_registry_add_listener(_glfw.wl.registry, &registryListener, NULL);

2
glfw/x11_init.c vendored
View File

@ -661,7 +661,7 @@ int _glfwPlatformInit(void)
if (!_glfwInitJoysticksLinux()) if (!_glfwInitJoysticksLinux())
return GLFW_FALSE; return GLFW_FALSE;
if (_glfw.linjs.inotify > 0) if (_glfw.linjs.inotify > 0)
addWatch(&_glfw.x11.eventLoopData, _glfw.linjs.inotify, POLLIN, 1, NULL, NULL); addWatch(&_glfw.x11.eventLoopData, "joystick", _glfw.linjs.inotify, POLLIN, 1, NULL, NULL);
#endif #endif
_glfwInitTimerPOSIX(); _glfwInitTimerPOSIX();