Revision: 158 http://trac.macosforge.org/projects/libdispatch/changeset/158 Author: robert@fledge.watson.org Date: 2009-11-15 04:26:16 -0800 (Sun, 15 Nov 2009) Log Message: ----------- Remove embedded struct kevent from struct dispatch_source_type_s, and replace with an opaque pointer, which source_kevent.c populates with statically allocated struct kevents. This removes the last remaining kqueue dependency from the generic source code. Minor differences from the submitted patch due to merge conflicts and slight style tweaks (no space between cast and pointer). Submitted by: Paolo Bonzini <bonzini@gnu.org> Modified Paths: -------------- trunk/src/internal.h trunk/src/source_internal.h trunk/src/source_kevent.c Modified: trunk/src/internal.h =================================================================== --- trunk/src/internal.h 2009-11-15 01:05:48 UTC (rev 157) +++ trunk/src/internal.h 2009-11-15 12:26:16 UTC (rev 158) @@ -85,7 +85,6 @@ #if HAVE_MALLOC_MALLOC_H #include <malloc/malloc.h> #endif -#include <sys/event.h> #include <sys/mount.h> #include <sys/queue.h> #include <sys/stat.h> Modified: trunk/src/source_internal.h =================================================================== --- trunk/src/source_internal.h 2009-11-15 01:05:48 UTC (rev 157) +++ trunk/src/source_internal.h 2009-11-15 12:26:16 UTC (rev 158) @@ -110,7 +110,7 @@ void _dispatch_timer_list_update(dispatch_source_t ds); struct dispatch_source_type_s { - struct kevent ke; + void *opaque; uint64_t mask; bool (*init) (dispatch_source_t ds, dispatch_source_type_t type, Modified: trunk/src/source_kevent.c =================================================================== --- trunk/src/source_kevent.c 2009-11-15 01:05:48 UTC (rev 157) +++ trunk/src/source_kevent.c 2009-11-15 12:26:16 UTC (rev 158) @@ -567,10 +567,10 @@ static bool dispatch_source_type_kevent_init(dispatch_source_t ds, dispatch_source_type_t type, uintptr_t handle, unsigned long mask, dispatch_queue_t q) { - const struct kevent *proto_kev = &type->ke; + const struct kevent *proto_kev = type->opaque; dispatch_kevent_t dk = NULL; - switch (type->ke.filter) { + switch (proto_kev->filter) { case EVFILT_SIGNAL: if (handle >= NSIG) { return false; @@ -625,35 +625,43 @@ return true; } +static const struct kevent _dispatch_source_type_timer_ke = { + .filter = DISPATCH_EVFILT_TIMER, +}; + const struct dispatch_source_type_s _dispatch_source_type_timer = { - .ke = { - .filter = DISPATCH_EVFILT_TIMER, - }, + .opaque = (void *)&_dispatch_source_type_timer_ke, .mask = DISPATCH_TIMER_INTERVAL|DISPATCH_TIMER_ONESHOT|DISPATCH_TIMER_ABSOLUTE|DISPATCH_TIMER_WALL_CLOCK, .init = dispatch_source_type_timer_init, }; +static const struct kevent _dispatch_source_type_read_ke = { + .filter = EVFILT_READ, + .flags = EV_DISPATCH, +}; + const struct dispatch_source_type_s _dispatch_source_type_read = { - .ke = { - .filter = EVFILT_READ, - .flags = EV_DISPATCH, - }, + .opaque = (void *)&_dispatch_source_type_read_ke, .init = dispatch_source_type_kevent_init, }; +static const struct kevent _dispatch_source_type_write_ke = { + .filter = EVFILT_WRITE, + .flags = EV_DISPATCH, +}; + const struct dispatch_source_type_s _dispatch_source_type_write = { - .ke = { - .filter = EVFILT_WRITE, - .flags = EV_DISPATCH, - }, + .opaque = (void *)&_dispatch_source_type_write_ke, .init = dispatch_source_type_kevent_init, }; +static const struct kevent _dispatch_source_type_proc_ke = { + .filter = EVFILT_PROC, + .flags = EV_CLEAR, +}; + const struct dispatch_source_type_s _dispatch_source_type_proc = { - .ke = { - .filter = EVFILT_PROC, - .flags = EV_CLEAR, - }, + .opaque = (void *)&_dispatch_source_type_proc_ke, .mask = NOTE_EXIT|NOTE_FORK|NOTE_EXEC #if HAVE_DECL_NOTE_SIGNAL |NOTE_SIGNAL @@ -665,18 +673,22 @@ .init = dispatch_source_type_kevent_init, }; +static const struct kevent _dispatch_source_type_signal_ke = { + .filter = EVFILT_SIGNAL, +}; + const struct dispatch_source_type_s _dispatch_source_type_signal = { - .ke = { - .filter = EVFILT_SIGNAL, - }, + .opaque = (void *)&_dispatch_source_type_signal_ke, .init = dispatch_source_type_kevent_init, }; +static const struct kevent _dispatch_source_type_vnode_ke = { + .filter = EVFILT_VNODE, + .flags = EV_CLEAR, +}; + const struct dispatch_source_type_s _dispatch_source_type_vnode = { - .ke = { - .filter = EVFILT_VNODE, - .flags = EV_CLEAR, - }, + .opaque = (void *)&_dispatch_source_type_vnode_ke, .mask = NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK| NOTE_RENAME|NOTE_REVOKE #if HAVE_DECL_NOTE_NONE @@ -686,11 +698,13 @@ .init = dispatch_source_type_kevent_init, }; +static const struct kevent _dispatch_source_type_vfs_ke = { + .filter = EVFILT_FS, + .flags = EV_CLEAR, +}; + const struct dispatch_source_type_s _dispatch_source_type_vfs = { - .ke = { - .filter = EVFILT_FS, - .flags = EV_CLEAR, - }, + .opaque = (void *)&_dispatch_source_type_vfs_ke, .mask = VQ_NOTRESP|VQ_NEEDAUTH|VQ_LOWDISK|VQ_MOUNT|VQ_UNMOUNT|VQ_DEAD| VQ_ASSIST|VQ_NOTRESPLOCK #if HAVE_DECL_VQ_UPDATE @@ -718,12 +732,14 @@ return true; } +static const struct kevent _dispatch_source_type_mach_send_ke = { + .filter = EVFILT_MACHPORT, + .flags = EV_DISPATCH, + .fflags = DISPATCH_MACHPORT_DEAD, +}; + const struct dispatch_source_type_s _dispatch_source_type_mach_send = { - .ke = { - .filter = EVFILT_MACHPORT, - .flags = EV_DISPATCH, - .fflags = DISPATCH_MACHPORT_DEAD, - }, + .opaque = (void *)&_dispatch_source_type_mach_send_ke, .mask = DISPATCH_MACH_SEND_DEAD, .init = dispatch_source_type_mach_send_init, }; @@ -738,29 +754,35 @@ return true; } +static const struct kevent _dispatch_source_type_mach_recv_ke = { + .filter = EVFILT_MACHPORT, + .flags = EV_DISPATCH, + .fflags = DISPATCH_MACHPORT_RECV, +}; + const struct dispatch_source_type_s _dispatch_source_type_mach_recv = { - .ke = { - .filter = EVFILT_MACHPORT, - .flags = EV_DISPATCH, - .fflags = DISPATCH_MACHPORT_RECV, - }, + .opaque = (void *)&_dispatch_source_type_mach_recv_ke, .init = dispatch_source_type_mach_recv_init, }; #endif +static const struct kevent _dispatch_source_type_data_add_ke = { + .filter = DISPATCH_EVFILT_CUSTOM_ADD, +}; + const struct dispatch_source_type_s _dispatch_source_type_data_add = { - .ke = { - .filter = DISPATCH_EVFILT_CUSTOM_ADD, - }, + .opaque = (void *)&_dispatch_source_type_data_add_ke, .init = dispatch_source_type_kevent_init, }; +static const struct kevent _dispatch_source_type_data_or_ke = { + .filter = DISPATCH_EVFILT_CUSTOM_OR, + .flags = EV_CLEAR, + .fflags = ~0, +}; + const struct dispatch_source_type_s _dispatch_source_type_data_or = { - .ke = { - .filter = DISPATCH_EVFILT_CUSTOM_OR, - .flags = EV_CLEAR, - .fflags = ~0, - }, + .opaque = (void *)&_dispatch_source_type_data_or_ke, .init = dispatch_source_type_kevent_init, };
participants (1)
-
source_changes@macosforge.org