Changeset 970f6e1 in mainline for uspace/drv/hid/usbhid/main.c


Ignore:
Timestamp:
2018-01-09T18:25:56Z (7 years ago)
Author:
Petr Manek <petr.manek@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4793023
Parents:
c386d6d
Message:

usbhid: join polling fibrils in device_remove()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/hid/usbhid/main.c

    rc386d6d r970f6e1  
    4040#include <errno.h>
    4141#include <str_error.h>
     42#include <fibril_synch.h>
    4243
    4344#include <usb/dev/driver.h>
     
    9899           /* Delay */
    99100           -1,
     101           /* Callback when the polling fails. */
     102           usb_hid_polling_error_callback,
    100103           /* Callback when the polling ends. */
    101104           usb_hid_polling_ended_callback,
     
    128131        assert(hid_dev);
    129132
    130         /* TODO: Stop device polling prior to deinit. Now it fails on endpoint error. */
    131 
     133        usb_log_debug2("%s will be removed, setting remove flag.\n", usb_device_get_name(dev));
     134        usb_hid_prepare_deinit(hid_dev);
     135
     136        return EOK;
     137}
     138
     139/**
     140 * Callback for when a device has just been from the driver.
     141 *
     142 * @param dev Structure representing the device.
     143 * @return Error code.
     144 */
     145static int usb_hid_device_removed(usb_device_t *dev)
     146{
     147        assert(dev);
     148        usb_hid_dev_t *hid_dev = usb_device_data_get(dev);
     149        assert(hid_dev);
     150
     151        /* Join polling fibril. */
     152        fibril_mutex_lock(&hid_dev->guard);
     153        while (hid_dev->running)
     154                fibril_condvar_wait(&hid_dev->poll_end, &hid_dev->guard);
     155        fibril_mutex_unlock(&hid_dev->guard);
     156
     157        /* Clean up. */
    132158        usb_hid_deinit(hid_dev);
    133159        usb_log_debug2("%s destruction complete.\n", usb_device_get_name(dev));
     160
    134161        return EOK;
    135162}
     
    165192        .device_add = usb_hid_device_add,
    166193        .device_remove = usb_hid_device_remove,
     194        .device_removed = usb_hid_device_removed,
    167195        .device_gone = usb_hid_device_gone,
    168196};
Note: See TracChangeset for help on using the changeset viewer.