[libdispatch-dev] [PATCH 3/4] remove last mention of struct kevent from "generic" code

Paolo Bonzini bonzini at gnu.org
Tue Nov 10 03:23:12 PST 2009


---
 src/internal.h        |    1 -
 src/source_internal.h |    2 +-
 src/source_kevent.c   |  116 +++++++++++++++++++++++++++++--------------------
 3 files changed, 70 insertions(+), 49 deletions(-)

diff --git a/src/internal.h b/src/internal.h
index 56fa9c4..e34a42b 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -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>
diff --git a/src/source_internal.h b/src/source_internal.h
index 222a85d..3ea8d8d 100644
--- a/src/source_internal.h
+++ b/src/source_internal.h
@@ -116,7 +116,7 @@ struct kevent {};
 #endif
 
 struct dispatch_source_type_s {
-        struct kevent ke;
+        void *opaque;
         uint64_t mask;
         bool (*init) (dispatch_source_t ds,
                       dispatch_source_type_t type,
diff --git a/src/source_kevent.c b/src/source_kevent.c
index 0e1d34f..db54768 100644
--- a/src/source_kevent.c
+++ b/src/source_kevent.c
@@ -572,10 +572,10 @@ dispatch_source_merge_data(dispatch_source_t ds, unsigned long val)
 
 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;
@@ -629,35 +629,43 @@ static bool dispatch_source_type_timer_init (dispatch_source_t ds, dispatch_sour
 	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
@@ -669,18 +677,22 @@ const struct dispatch_source_type_s _dispatch_source_type_proc = {
 	.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
@@ -690,11 +702,13 @@ const struct dispatch_source_type_s _dispatch_source_type_vnode = {
 	.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
@@ -722,12 +736,14 @@ dispatch_source_type_mach_send_init(dispatch_source_t ds, dispatch_source_type_t
 	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,
 };
@@ -742,30 +758,36 @@ dispatch_source_type_mach_recv_init(dispatch_source_t ds, dispatch_source_type_t
 	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,
-	},
-	.init = dispatch_source_type_kevent_init
+	.opaque = (void *) &_dispatch_source_type_data_or_ke,
+	.init = dispatch_source_type_kevent_init,
 };
 
 // Updates the ordered list of timers based on next fire date for changes to ds.
-- 
1.6.2.5




More information about the libdispatch-dev mailing list