Changeset 91173333 in mainline for uspace/drv/hid


Ignore:
Timestamp:
2018-01-13T21:36:13Z (8 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
edc51615
Parents:
8a0c52a
Message:

usbdev: use centralized joining mechanism, move away from device_removed() callback

Location:
uspace/drv/hid/usbhid
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/hid/usbhid/generic/hiddev.c

    r8a0c52a r91173333  
    220220{
    221221        /* Continue polling until the device is about to be removed. */
    222         return !hid_dev->poll_stop;
     222        return true;
    223223}
    224224
  • uspace/drv/hid/usbhid/kbd/kbddev.c

    r8a0c52a r91173333  
    710710
    711711        /* Continue polling until the device is about to be removed. */
    712         return !hid_dev->poll_stop;
     712        return true;
    713713}
    714714
  • uspace/drv/hid/usbhid/main.c

    r8a0c52a r91173333  
    4040#include <errno.h>
    4141#include <str_error.h>
    42 #include <fibril_synch.h>
    4342
    4443#include <usb/dev/driver.h>
     
    117116}
    118117
     118static int join_and_clean(usb_device_t *dev)
     119{
     120        assert(dev);
     121        usb_hid_dev_t *hid_dev = usb_device_data_get(dev);
     122        assert(hid_dev);
     123
     124        /* Join polling fibril. */
     125        usb_device_poll_join(hid_dev->polling);
     126
     127        /* Clean up. */
     128        usb_hid_deinit(hid_dev);
     129        usb_log_info("%s destruction complete.\n", usb_device_get_name(dev));
     130
     131        return EOK;
     132}
     133
    119134/**
    120135 * Callback for a device about to be removed from the driver.
     
    129144        assert(hid_dev);
    130145
    131         usb_log_info("%s will be removed, setting remove flag.\n", usb_device_get_name(dev));
    132         usb_hid_prepare_deinit(hid_dev);
    133 
    134         return EOK;
    135 }
    136 
    137 static int join_and_clean(usb_device_t *dev)
    138 {
    139         assert(dev);
    140         usb_hid_dev_t *hid_dev = usb_device_data_get(dev);
    141         assert(hid_dev);
    142 
    143         /* Join polling fibril. */
    144         fibril_mutex_lock(&hid_dev->poll_guard);
    145         while (hid_dev->running)
    146                 fibril_condvar_wait(&hid_dev->poll_cv, &hid_dev->poll_guard);
    147         fibril_mutex_unlock(&hid_dev->poll_guard);
    148 
    149         /* Clean up. */
    150         usb_hid_deinit(hid_dev);
    151         usb_log_info("%s destruction complete.\n", usb_device_get_name(dev));
    152 
    153         return EOK;
    154 }
    155 
    156 /**
    157  * Callback for when a device has just been from the driver.
    158  *
    159  * @param dev Structure representing the device.
    160  * @return Error code.
    161  */
    162 static int usb_hid_device_removed(usb_device_t *dev)
    163 {
    164         assert(dev);
    165         usb_hid_dev_t *hid_dev = usb_device_data_get(dev);
    166         assert(hid_dev);
    167 
    168         usb_log_info("%s endpoints unregistered, joining polling fibril.\n", usb_device_get_name(dev));
     146        usb_log_info("Device %s removed.\n", usb_device_get_name(dev));
    169147        return join_and_clean(dev);
    170148}
     
    182160        assert(hid_dev);
    183161
    184         usb_log_info("Device %s gone, joining the polling fibril.\n", usb_device_get_name(dev));
    185         usb_hid_prepare_deinit(hid_dev);
     162        usb_log_info("Device %s gone.\n", usb_device_get_name(dev));
    186163        return join_and_clean(dev);
    187164}
     
    191168        .device_add = usb_hid_device_add,
    192169        .device_remove = usb_hid_device_remove,
    193         .device_removed = usb_hid_device_removed,
    194170        .device_gone = usb_hid_device_gone,
    195171};
  • uspace/drv/hid/usbhid/mouse/mousedev.c

    r8a0c52a r91173333  
    415415
    416416        /* Continue polling until the device is about to be removed. */
    417         return !hid_dev->poll_stop;
     417        return true;
    418418}
    419419
  • uspace/drv/hid/usbhid/multimedia/multimedia.c

    r8a0c52a r91173333  
    246246        usb_hid_report_path_t *path = usb_hid_report_path();
    247247        if (path == NULL)
    248                 return !hid_dev->poll_stop; /* This might be a temporary failure. */
     248                return true; /* This might be a temporary failure. */
    249249
    250250        int ret =
     
    252252        if (ret != EOK) {
    253253                usb_hid_report_path_free(path);
    254                 return !hid_dev->poll_stop; /* This might be a temporary failure. */
     254                return true; /* This might be a temporary failure. */
    255255        }
    256256
     
    284284        usb_hid_report_path_free(path);
    285285
    286         return !hid_dev->poll_stop;
     286        return true;
    287287}
    288288/**
  • uspace/drv/hid/usbhid/usbhid.c

    r8a0c52a r91173333  
    355355        hid_dev->poll_pipe_mapping = NULL;
    356356
    357         hid_dev->poll_stop = false;
    358         fibril_mutex_initialize(&hid_dev->poll_guard);
    359         fibril_condvar_initialize(&hid_dev->poll_cv);
    360 
    361357        int rc = usb_hid_check_pipes(hid_dev, dev);
    362358        if (rc != EOK) {
     
    506502
    507503        /* Continue polling until the device is about to be removed. */
    508         return hid_dev->running && !hid_dev->poll_stop;
     504        return hid_dev->running;
    509505}
    510506
     
    524520
    525521        hid_dev->running = false;
    526 
    527         /* Signal polling end to joining thread. */
    528         fibril_mutex_lock(&hid_dev->poll_guard);
    529         fibril_condvar_signal(&hid_dev->poll_cv);
    530         fibril_mutex_unlock(&hid_dev->poll_guard);
    531522}
    532523
     
    539530{
    540531        return hid_dev->report_nr;
    541 }
    542 
    543 void usb_hid_prepare_deinit(usb_hid_dev_t *hid_dev)
    544 {
    545         assert(hid_dev);
    546         hid_dev->poll_stop = true;
    547532}
    548533
  • uspace/drv/hid/usbhid/usbhid.h

    r8a0c52a r91173333  
    4646#include <usb/hid/hid.h>
    4747#include <stdbool.h>
    48 #include <fibril_synch.h>
    4948
    5049typedef struct usb_hid_dev usb_hid_dev_t;
     
    135134        int report_nr;
    136135        volatile bool running;
    137 
    138         /** True if polling should stop as soon as possible */
    139         volatile bool poll_stop;
    140 
    141         /** Synchronization primitives for joining polling end. */
    142         fibril_mutex_t poll_guard;
    143         fibril_condvar_t poll_cv;
    144136};
    145137
     
    147139
    148140int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev);
    149 
    150 void usb_hid_prepare_deinit(usb_hid_dev_t *hid_dev);
    151141
    152142void usb_hid_deinit(usb_hid_dev_t *hid_dev);
Note: See TracChangeset for help on using the changeset viewer.