Date: Fri, 26 Jun 2015 22:11:31 +0300 From: Gleb Popov <6yearold@gmail.com> To: enlightenment@freebsd.org Subject: E on FreeBSD: FreeBSD Port: devel/efl Message-ID: <CALH631k-ucWYMS1j4-Gm=HQAb7v_QPf1HYmf%2BzWDpccOjHYsQw@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Hi, i wrote a patch for eio that adds kqeue/kevent backend. It works for
me, but before submitting it upstream i wanted someone to test it more
extensively, especially with Enlightenment DE, because i don't use it for
myself. Patch should be applied to the current devel/efl port.
Any input would be welcome.
[-- Attachment #2 --]
--- /usr/ports/devel/efl/files/patch-configure.ac 2014-11-25 06:07:22.000000000 +0300
+++ files/patch-configure.ac 2015-03-29 18:28:46.614271386 +0300
@@ -1,6 +1,6 @@
---- configure.ac.orig 2014-11-10 12:02:43.000000000 +0100
-+++ configure.ac 2014-11-20 23:35:26.000000000 +0100
-@@ -407,14 +407,15 @@
+--- configure.ac.orig 2015-03-27 23:47:18.733895302 +0300
++++ configure.ac 2015-03-27 23:58:21.482851902 +0300
+@@ -408,14 +408,15 @@
execinfo.h \
mcheck.h \
sys/epoll.h \
@@ -17,3 +17,18 @@
have_inotify="${ac_cv_header_sys_inotify_h}"
AM_CONDITIONAL([HAVE_INOTIFY], [test "x${have_inotify}" = "xyes"])
+@@ -425,6 +426,14 @@
+ [File monitoring with Windows notification])
+ AM_CONDITIONAL([HAVE_NOTIFY_WIN32], [test "x${have_notify_win32}" = "xyes"])
+
++AC_CHECK_FUNC([kevent])
++
++have_notify_kevent="${ac_cv_func_kevent}"
++AC_DEFINE_IF([HAVE_NOTIFY_KEVENT],
++ [test "x${have_notify_kevent}" = "xyes"], [1],
++ [File monitoring with kqueue/kevent mechanism])
++AM_CONDITIONAL([HAVE_NOTIFY_KEVENT], [test "x${have_notify_kevent}" = "xyes"])
++
+
+ EFL_CHECK_PATH_MAX
+
--- /dev/null 2015-06-26 21:55:00.000000000 +0300
+++ files/patch-src-Makefile_Eio.am 2015-03-28 00:05:07.685822381 +0300
@@ -0,0 +1,12 @@
+--- src/Makefile_Eio.am.orig 2015-03-28 00:04:25.000000000 +0300
++++ src/Makefile_Eio.am 2015-03-28 00:04:41.764821901 +0300
+@@ -24,6 +24,9 @@
+ if HAVE_NOTIFY_WIN32
+ lib_eio_libeio_la_SOURCES += lib/eio/eio_monitor_win32.c
+ endif
++if HAVE_NOTIFY_KEVENT
++lib_eio_libeio_la_SOURCES += lib/eio/eio_monitor_kevent.c
++endif
+ endif
+
+ lib_eio_libeio_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl @EIO_CFLAGS@
--- /dev/null 2015-06-26 21:55:00.000000000 +0300
+++ files/patch-src-lib-eio-eio_monitor_kevent.c 2015-06-26 21:45:28.666135220 +0300
@@ -0,0 +1,211 @@
+--- /dev/null 2015-06-26 21:44:00.000000000 +0300
++++ src/lib/eio/eio_monitor_kevent.c 2015-06-26 21:20:37.032232380 +0300
+@@ -0,0 +1,208 @@
++/* EIO - EFL data type library
++ * Copyright (C) 2011 Enlightenment Developers:
++ * Cedric Bail <cedric.bail@free.fr>
++ *
++ * This library is free software; you can redistribute it and/or
++ * modify it under the terms of the GNU Lesser General Public
++ * License as published by the Free Software Foundation; either
++ * version 2.1 of the License, or (at your option) any later version.
++ *
++ * This library is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
++ * Lesser General Public License for more details.
++ *
++ * You should have received a copy of the GNU Lesser General Public
++ * License along with this library;
++ * if not, see <http://www.gnu.org/licenses/>.
++ */
++
++#include "eio_private.h"
++#include "Eio.h"
++
++#include <sys/types.h>
++#include <sys/event.h>
++#include <sys/stat.h>
++
++/*============================================================================*
++ * Local *
++ *============================================================================*/
++
++/**
++ * @cond LOCAL
++ */
++
++#define KEVENT_USER_TRIGGER_ID 1
++#define KEVENT_NUM_EVENTS 5
++
++struct _Eio_Monitor_Backend
++{
++ Eio_Monitor *parent;
++
++ int fd;
++};
++
++static int _kqueue_fd = -1;
++static Eina_Hash *_kevent_monitors = NULL;
++
++static void
++_eio_kevent_del(void *data)
++{
++ Eio_Monitor_Backend *emb = data;
++
++ if (emb->fd)
++ {
++ close(emb->fd);
++ emb->fd = 0;
++ }
++
++ free(emb);
++}
++
++static void
++_eio_kevent_handler(void *data EINA_UNUSED, Ecore_Thread *thr EINA_UNUSED)
++{
++ Eio_Monitor_Backend *backend;
++ struct kevent evs[KEVENT_NUM_EVENTS];
++ int event_code = 0;
++
++ while(1)
++ {
++ int res = kevent(_kqueue_fd, 0, 0, evs, KEVENT_NUM_EVENTS, 0);
++
++ for(int i=0; i<res; ++i)
++ {
++ if(evs[i].filter == EVFILT_USER)
++ return;
++ backend = eina_hash_find(_kevent_monitors, &evs[i].ident);
++ if(evs[i].fflags & NOTE_DELETE)
++ event_code = EIO_MONITOR_FILE_DELETED;
++ if(evs[i].fflags & NOTE_WRITE)
++ event_code = EIO_MONITOR_FILE_MODIFIED;
++ ecore_thread_main_loop_begin();
++ _eio_monitor_send(backend->parent, backend->parent->path, event_code);
++ ecore_thread_main_loop_end();
++ }
++ }
++}
++
++/**
++ * @endcond
++ */
++
++
++/*============================================================================*
++ * Global *
++ *============================================================================*/
++
++/**
++ * @cond LOCAL
++ */
++
++/**
++ * @endcond
++ */
++
++void eio_monitor_backend_init(void)
++{
++ struct kevent e;
++
++ if(_kqueue_fd > 0)
++ return; // already initialized
++
++ _kqueue_fd = kqueue();
++ if(_kqueue_fd < 0) return;
++
++ _kevent_monitors = eina_hash_int32_new(_eio_kevent_del);
++
++ EV_SET(&e, KEVENT_USER_TRIGGER_ID, EVFILT_USER, EV_ADD, 0, 0, NULL);
++ kevent(_kqueue_fd, &e, 1, 0, 0, 0);
++
++ Ecore_Thread* thr = ecore_thread_feedback_run(
++ _eio_kevent_handler,NULL,
++ NULL,NULL,
++ NULL,EINA_TRUE);
++
++ if(!thr)
++ {
++ eio_monitor_backend_shutdown();
++ return;
++ }
++}
++
++void eio_monitor_backend_shutdown(void)
++{
++ struct kevent e;
++
++ if (_kqueue_fd < 0) return;
++
++ EV_SET(&e, KEVENT_USER_TRIGGER_ID, EVFILT_USER, EV_ADD, NOTE_TRIGGER, 0, NULL);
++ kevent(_kqueue_fd, &e, 1, 0, 0, 0);
++
++ eina_hash_free(_kevent_monitors);
++ close(_kqueue_fd);
++ _kqueue_fd = -1;
++}
++
++void eio_monitor_backend_add(Eio_Monitor *monitor)
++{
++ struct kevent e;
++ struct stat st;
++ Eio_Monitor_Backend* backend;
++ int fd, res = 0;
++
++ if (_kqueue_fd < 0)
++ {
++ eio_monitor_fallback_add(monitor);
++ return;
++ }
++
++ res = stat(monitor->path, &st);
++ if (res) return;
++
++ if (S_ISDIR(st.st_mode)) // let poller handle directories
++ {
++ eio_monitor_fallback_add(monitor);
++ return;
++ }
++
++ fd = open(monitor->path, O_RDONLY);
++ if(fd < 0) return;
++
++ backend = calloc(1, sizeof (Eio_Monitor_Backend));
++ if (!backend) return;
++
++ backend->fd = fd;
++ backend->parent = monitor;
++ monitor->backend = backend;
++
++ eina_hash_direct_add(_kevent_monitors, &backend->fd, backend);
++
++ EV_SET(&e, fd, EVFILT_VNODE, EV_ADD | EV_CLEAR,
++ NOTE_WRITE | NOTE_RENAME | NOTE_DELETE, 0, NULL);
++ res = kevent(_kqueue_fd, &e, 1, 0, 0, 0);
++ if(res)
++ {
++ eina_hash_del(_kevent_monitors, &backend->fd, backend);
++ eio_monitor_fallback_add(monitor);
++ return;
++ }
++}
++
++void eio_monitor_backend_del(Eio_Monitor *monitor)
++{
++ Eio_Monitor_Backend *backend;
++
++ if (_kqueue_fd < 0)
++ eio_monitor_fallback_del(monitor);
++
++ backend = monitor->backend;
++ monitor->backend = NULL;
++
++ eina_hash_del(_kevent_monitors, &backend->fd, backend);
++}
++
++
++/*============================================================================*
++ * API *
++ *============================================================================*/
--- /dev/null 2015-06-26 21:55:00.000000000 +0300
+++ files/patch-src-lib-eio-eio_monitor_poll.c 2015-03-29 18:08:13.331360266 +0300
@@ -0,0 +1,11 @@
+--- src/lib/eio/eio_monitor_poll.c.orig 2013-12-11 18:34:32.000000000 +0400
++++ src/lib/eio/eio_monitor_poll.c 2015-03-29 18:07:19.968360186 +0300
+@@ -270,7 +270,7 @@
+ * @cond LOCAL
+ */
+
+-#if !defined HAVE_SYS_INOTIFY_H && !defined HAVE_NOTIFY_WIN32
++#if !defined HAVE_SYS_INOTIFY_H && !defined HAVE_NOTIFY_WIN32 && !defined HAVE_NOTIFY_KEVENT
+ void eio_monitor_backend_init(void)
+ {
+ }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CALH631k-ucWYMS1j4-Gm=HQAb7v_QPf1HYmf%2BzWDpccOjHYsQw>
