Changeset 91173333 in mainline for uspace/drv/bus/usb/usbhub/usbhub.c


Ignore:
Timestamp:
2018-01-13T21:36:13Z (6 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhub/usbhub.c

    r8a0c52a r91173333  
    9999
    100100        /* Continue polling until the device is about to be removed. */
    101         return hub->running && !hub->poll_stop;
     101        return hub->running;
    102102}
    103103
     
    123123        hub_dev->pending_ops_count = 0;
    124124        hub_dev->running = false;
    125         hub_dev->poll_stop = false;
    126125        fibril_mutex_initialize(&hub_dev->pending_ops_mutex);
    127         fibril_mutex_initialize(&hub_dev->poll_guard);
    128126        fibril_condvar_initialize(&hub_dev->pending_ops_cv);
    129         fibril_condvar_initialize(&hub_dev->poll_cv);
    130127
    131128        /* Set hub's first configuration. (There should be only one) */
     
    197194}
    198195
    199 /**
    200  * Turn off power to all ports.
    201  *
    202  * @param usb_dev generic usb device information
    203  * @return error code
    204  */
    205 int usb_hub_device_remove(usb_device_t *usb_dev)
    206 {
    207         assert(usb_dev);
    208         usb_hub_dev_t *hub = usb_device_data_get(usb_dev);
    209         assert(hub);
    210 
    211         usb_log_info("(%p) USB hub will be removed.", hub);
    212 
    213         /* Instruct the hub to stop once endpoints are unregistered. */
    214         hub->poll_stop = true;
    215         return EOK;
    216 }
    217 
    218196static int usb_hub_cleanup(usb_hub_dev_t *hub)
    219197{
     
    241219}
    242220
    243 int usb_hub_device_removed(usb_device_t *usb_dev)
     221/**
     222 * Turn off power to all ports.
     223 *
     224 * @param usb_dev generic usb device information
     225 * @return error code
     226 */
     227int usb_hub_device_remove(usb_device_t *usb_dev)
    244228{
    245229        assert(usb_dev);
     
    247231        assert(hub);
    248232
    249         usb_log_info("(%p) USB hub was removed, joining polling fibril.", hub);
     233        usb_log_info("(%p) USB hub removed, joining polling fibril.", hub);
    250234
    251235        /* Join polling fibril. */
    252         fibril_mutex_lock(&hub->poll_guard);
    253         while (hub->running)
    254                 fibril_condvar_wait(&hub->poll_cv, &hub->poll_guard);
    255         fibril_mutex_unlock(&hub->poll_guard);
    256 
     236        usb_device_poll_join(hub->polling);
    257237        usb_log_info("(%p) USB hub polling stopped, freeing memory.", hub);
    258238
     
    272252        assert(hub);
    273253
    274         hub->poll_stop = true;
    275254        usb_log_info("(%p) USB hub gone, joining polling fibril.", hub);
    276255
    277256        /* Join polling fibril. */
    278         fibril_mutex_lock(&hub->poll_guard);
    279         while (hub->running)
    280                 fibril_condvar_wait(&hub->poll_cv, &hub->poll_guard);
    281         fibril_mutex_unlock(&hub->poll_guard);
     257        usb_device_poll_join(hub->polling);
     258        usb_log_info("(%p) USB hub polling stopped, freeing memory.", hub);
    282259
    283260        /* Destroy hub. */
     
    592569        fibril_mutex_unlock(&hub->pending_ops_mutex);
    593570        hub->running = false;
    594 
    595         /* Signal polling end to joining thread. */
    596         fibril_mutex_lock(&hub->poll_guard);
    597         fibril_condvar_signal(&hub->poll_cv);
    598         fibril_mutex_unlock(&hub->poll_guard);
    599 }
     571}
     572
    600573/**
    601574 * @}
Note: See TracChangeset for help on using the changeset viewer.