From 546d83c6baf98e89d7e0f193354d66fb166d387b Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 21 Sep 2012 08:55:22 +0000 Subject: [PATCH] clock now uses timerfd_create() to receive updates when the system clock has changed to ensure proper sync SVN revision: 76946 --- configure.ac | 2 ++ src/modules/clock/e_mod_main.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/configure.ac b/configure.ac index 8b1fdfc3c..3f2432ad7 100644 --- a/configure.ac +++ b/configure.ac @@ -79,6 +79,8 @@ AC_CHECK_FUNCS(unsetenv) efl_version="1.7.0" +AC_CHECK_HEADERS([sys/timerfd.h]) + dnl AC_CHECK_HEADERS(X11/extensions/shape.h,, AC_MSG_ERROR([Cannot find X11/extensions/shape.h. Make sure your CFLAGS environment variable contains include lines for the location of this file])) AC_CHECK_HEADERS(fnmatch.h,, AC_MSG_ERROR([Cannot find fnmatch.h. Make sure your CFLAGS environment variable contains include lines for the location of this file])) diff --git a/src/modules/clock/e_mod_main.c b/src/modules/clock/e_mod_main.c index 34c6b80b0..ae44db4ca 100644 --- a/src/modules/clock/e_mod_main.c +++ b/src/modules/clock/e_mod_main.c @@ -3,6 +3,9 @@ #include #include +#ifdef HAVE_SYS_TIMERFD_H +# include +#endif /* actual module specifics */ typedef struct _Instance Instance; @@ -50,6 +53,9 @@ static E_Config_DD *conf_item_edd = NULL; static Eina_List *clock_instances = NULL; static E_Action *act = NULL; static Ecore_Timer *update_today = NULL; +#ifdef HAVE_SYS_TIMERFD_H +static Ecore_Fd_Handler *timerfd_handler = NULL; +#endif /* and actually define the gadcon class that this module provides (just 1) */ static const E_Gadcon_Client_Class _gadcon_class = @@ -810,6 +816,16 @@ _clock_eio_error(void *d __UNUSED__, int type __UNUSED__, void *event __UNUSED__ return ECORE_CALLBACK_RENEW; } +static Eina_Bool +_clock_fd_update(void *d __UNUSED__, Ecore_Fd_Handler *fdh) +{ + char buf[64]; + + read(ecore_main_fd_handler_fd_get(fdh), buf, sizeof(buf)); + e_int_clock_instances_redo(); + return EINA_TRUE; +} + /* module setup */ EAPI E_Module_Api e_modapi = { @@ -866,6 +882,16 @@ e_modapi_init(E_Module *m) E_LIST_HANDLERS_APPEND(clock_eio_handlers, EIO_MONITOR_SELF_RENAME, _clock_eio_update, NULL); e_gadcon_provider_register(&_gadcon_class); + +#ifdef HAVE_SYS_TIMERFD_H + int timer_fd; + + /* on old systems, flags must be 0, so we'll play nice and do it always */ + timer_fd = timerfd_create(CLOCK_REALTIME, 0); + if (timer_fd < 0) return m; + fcntl(timer_fd, F_SETFL, O_NONBLOCK | FD_CLOEXEC); + timerfd_handler = ecore_main_fd_handler_add(timer_fd, ECORE_FD_READ, _clock_fd_update, NULL, NULL, NULL); +#endif return m; } @@ -908,6 +934,9 @@ e_modapi_shutdown(E_Module *m __UNUSED__) } eio_monitor_del(clock_tz_monitor); clock_tz_monitor = NULL; +#ifdef HAVE_SYS_TIMERFD_H + timerfd_handler = ecore_main_fd_handler_del(timerfd_handler); +#endif return 1; }