X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Ffdev.c;h=c2fe5c64ad52bae422a9903d7977d6f3f3044f23;hb=65353dce81a629e042800bb7b86fcd869a76727e;hp=5c31d31b638022b553b06be613794497323da09e;hpb=ca820c65c2b03a24e8936218171c6c1d138fd1f7;p=src%2Fapp-framework-binder.git diff --git a/src/fdev.c b/src/fdev.c index 5c31d31b..c2fe5c64 100644 --- a/src/fdev.c +++ b/src/fdev.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 "IoT.bzh" + * Copyright (C) 2015-2020 "IoT.bzh" * Author José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,7 +27,6 @@ struct fdev { int fd; uint32_t events; - int repeat; unsigned refcount; struct fdev_itf *itf; void *closure_itf; @@ -45,7 +44,6 @@ struct fdev *fdev_create(int fd) else { fdev->fd = fd; fdev->refcount = 3; /* set autoclose by default */ - fdev->repeat = -1; } return fdev; } @@ -58,8 +56,6 @@ void fdev_set_itf(struct fdev *fdev, struct fdev_itf *itf, void *closure_itf) void fdev_dispatch(struct fdev *fdev, uint32_t events) { - if (fdev->repeat > 0 && !--fdev->repeat && fdev->itf) - fdev->itf->disable(fdev->closure_itf, fdev); if (fdev->callback) fdev->callback(fdev->closure_callback, events, fdev); } @@ -76,7 +72,8 @@ void fdev_unref(struct fdev *fdev) if (fdev && __atomic_sub_fetch(&fdev->refcount, 2, __ATOMIC_RELAXED) <= 1) { if (fdev->itf) { fdev->itf->disable(fdev->closure_itf, fdev); - fdev->itf->unref(fdev->closure_itf); + if (fdev->itf->unref) + fdev->itf->unref(fdev->closure_itf); } if (fdev->refcount) close(fdev->fd); @@ -94,11 +91,6 @@ uint32_t fdev_events(const struct fdev *fdev) return fdev->events; } -int fdev_repeat(const struct fdev *fdev) -{ - return fdev->repeat; -} - int fdev_autoclose(const struct fdev *fdev) { return 1 & fdev->refcount; @@ -106,7 +98,7 @@ int fdev_autoclose(const struct fdev *fdev) static inline int is_active(struct fdev *fdev) { - return fdev->repeat && fdev->callback; + return !!fdev->callback; } static inline void update_activity(struct fdev *fdev, int old_active) @@ -135,24 +127,15 @@ void fdev_set_events(struct fdev *fdev, uint32_t events) if (events != fdev->events) { fdev->events = events; if (is_active(fdev)) - fdev->itf->enable(fdev->closure_itf, fdev); + fdev->itf->update(fdev->closure_itf, fdev); } } -void fdev_set_repeat(struct fdev *fdev, int count) -{ - int oa; - - oa = is_active(fdev); - fdev->repeat = count; - update_activity(fdev, oa); -} - void fdev_set_autoclose(struct fdev *fdev, int autoclose) { if (autoclose) - fdev->refcount |= 1; + fdev->refcount |= (unsigned)1; else - fdev->refcount &= -2; + fdev->refcount &= ~(unsigned)1; }