afb-export: Monitor calls to API initialisation
[src/app-framework-binder.git] / src / fdev.c
index 5c31d31..a8f3695 100644 (file)
@@ -45,7 +45,7 @@ struct fdev *fdev_create(int fd)
        else {
                fdev->fd = fd;
                fdev->refcount = 3; /* set autoclose by default */
-               fdev->repeat = -1;
+               fdev->repeat = -1; /* always repeat by default */
        }
        return fdev;
 }
@@ -76,7 +76,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);
@@ -135,7 +136,7 @@ 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);
        }
 }
 
@@ -151,8 +152,8 @@ void fdev_set_repeat(struct fdev *fdev, int count)
 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;
 }