From 0bb42dc235ae822ebb55965e130249d1177e0660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Thu, 26 Dec 2013 03:20:47 +0100 Subject: [PATCH] Have iomux_update_events be a no-op if the events didn't change --- include/ucore/iomux.h | 20 +++++--------------- src/iomux_impl.c | 12 ++++++++++-- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/include/ucore/iomux.h b/include/ucore/iomux.h index ad78687..f5604fb 100644 --- a/include/ucore/iomux.h +++ b/include/ucore/iomux.h @@ -105,20 +105,11 @@ int iomux_register_fd(struct IOMux *mux, struct IOMuxFD *fd); */ int iomux_unregister_fd(struct IOMux *mux, struct IOMuxFD *fd); -/** Updates the events to watch for in fd->what +/** Updates the events to watch for + * * @return 0 on success, an errno value on error */ -int iomux_update_events(struct IOMux *mux, struct IOMuxFD *fd); - - -/** - * Convenience macro for setting the new event - */ -#define iomux_set_event(mux, fd, what_)\ -({\ - (fd)->what = (what_);\ - iomux_update_events((mux), (fd));\ -}) +int iomux_update_events(struct IOMux *mux, struct IOMuxFD *fd, unsigned int what); /** * Convenience macro for clearing the new event @@ -126,15 +117,14 @@ int iomux_update_events(struct IOMux *mux, struct IOMuxFD *fd); #define iomux_clear_event(mux, fd, what_)\ ({\ (fd)->what &= ~(what_);\ - iomux_update_events((mux), (fd));\ + iomux_update_events((mux), (fd), (fd)->what & ~(what_));\ }) /** * Convenience macro for adding the new event to the existing events */ #define iomux_add_event(mux, fd, what_)\ ({\ - (fd)->what &= (what_);\ - iomux_update_events((mux), (fd));\ + iomux_update_events((mux), (fd), (fd)->what | (what_));\ }) /** @return a UCTimer instance tied to this mux. diff --git a/src/iomux_impl.c b/src/iomux_impl.c index 421fd91..2902e92 100644 --- a/src/iomux_impl.c +++ b/src/iomux_impl.c @@ -130,13 +130,21 @@ int iomux_unregister_fd(struct IOMux *mux, struct IOMuxFD *fd) return mux->unregister_fd_impl(mux, fd); } -int iomux_update_events(struct IOMux *mux, struct IOMuxFD *fd) +int iomux_update_events(struct IOMux *mux, struct IOMuxFD *fd, unsigned int what) { + int rc; assert(mux != NULL); assert(fd != NULL); assert(fd->callback != NULL); assert(fd->fd >= 0); - return mux->update_events_impl(mux, fd); + + if (fd->what != what) { + mux->update_events_impl(mux, fd); + } else { + rc = 0; + } + + return rc; } struct UCoreClock *iomux_get_clock(struct IOMux *mux)