Have iomux_update_events be a no-op if the events didn't change

This commit is contained in:
Nils O. Selåsdal
2013-12-26 03:20:47 +01:00
parent 9756ca0aeb
commit 0bb42dc235
2 changed files with 15 additions and 17 deletions
+5 -15
View File
@@ -105,20 +105,11 @@ int iomux_register_fd(struct IOMux *mux, struct IOMuxFD *fd);
*/ */
int iomux_unregister_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 * @return 0 on success, an errno value on error
*/ */
int iomux_update_events(struct IOMux *mux, struct IOMuxFD *fd); int iomux_update_events(struct IOMux *mux, struct IOMuxFD *fd, unsigned int what);
/**
* Convenience macro for setting the new event
*/
#define iomux_set_event(mux, fd, what_)\
({\
(fd)->what = (what_);\
iomux_update_events((mux), (fd));\
})
/** /**
* Convenience macro for clearing the new event * 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_)\ #define iomux_clear_event(mux, fd, what_)\
({\ ({\
(fd)->what &= ~(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 * Convenience macro for adding the new event to the existing events
*/ */
#define iomux_add_event(mux, fd, what_)\ #define iomux_add_event(mux, fd, what_)\
({\ ({\
(fd)->what &= (what_);\ iomux_update_events((mux), (fd), (fd)->what | (what_));\
iomux_update_events((mux), (fd));\
}) })
/** @return a UCTimer instance tied to this mux. /** @return a UCTimer instance tied to this mux.
+10 -2
View File
@@ -130,13 +130,21 @@ int iomux_unregister_fd(struct IOMux *mux, struct IOMuxFD *fd)
return mux->unregister_fd_impl(mux, 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(mux != NULL);
assert(fd != NULL); assert(fd != NULL);
assert(fd->callback != NULL); assert(fd->callback != NULL);
assert(fd->fd >= 0); 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) struct UCoreClock *iomux_get_clock(struct IOMux *mux)