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


Ignore:
Timestamp:
2018-01-09T18:25:56Z (6 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/usbhid.c

    rc386d6d r970f6e1  
    332332 * During initialization, the keyboard is switched into boot protocol, the idle
    333333 * rate is set to 0 (infinity), resulting in the keyboard only reporting event
    334  * when a key is pressed or released. Finally, the LED lights are turned on 
     334 * when a key is pressed or released. Finally, the LED lights are turned on
    335335 * according to the default setup of lock keys.
    336336 *
    337  * @note By default, the keyboards is initialized with Num Lock turned on and 
     337 * @note By default, the keyboards is initialized with Num Lock turned on and
    338338 *       other locks turned off.
    339339 *
     
    354354        hid_dev->usb_dev = dev;
    355355        hid_dev->poll_pipe_mapping = NULL;
     356
     357        hid_dev->will_deinit = false;
     358        fibril_mutex_initialize(&hid_dev->guard);
     359        fibril_condvar_initialize(&hid_dev->poll_end);
    356360
    357361        int rc = usb_hid_check_pipes(hid_dev, dev);
     
    492496}
    493497
     498bool usb_hid_polling_error_callback(usb_device_t *dev, int err_code, void *arg)
     499{
     500        assert(dev);
     501        assert(arg);
     502        usb_hid_dev_t *hid_dev = arg;
     503
     504        usb_log_error("Device %s polling error: %s", usb_device_get_name(dev),
     505            str_error(err_code));
     506
     507        /* Continue polling until the device is about to be removed. */
     508        return hid_dev->running && !hid_dev->will_deinit;
     509}
     510
    494511void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg)
    495512{
     
    507524
    508525        hid_dev->running = false;
     526
     527        /* Signal polling end to joining thread. */
     528        fibril_mutex_lock(&hid_dev->guard);
     529        fibril_condvar_signal(&hid_dev->poll_end);
     530        fibril_mutex_unlock(&hid_dev->guard);
    509531}
    510532
     
    517539{
    518540        return hid_dev->report_nr;
     541}
     542
     543void usb_hid_prepare_deinit(usb_hid_dev_t *hid_dev)
     544{
     545        assert(hid_dev);
     546        hid_dev->will_deinit = true;
    519547}
    520548
     
    524552        assert(hid_dev->subdrivers != NULL || hid_dev->subdriver_count == 0);
    525553
    526 
    527         usb_log_debug("Subdrivers: %p, subdriver count: %d\n",
     554        usb_log_debug("Subdrivers: %p, subdriver count: %d\n",
    528555            hid_dev->subdrivers, hid_dev->subdriver_count);
    529556
     
    541568        /* Destroy the parser */
    542569        usb_hid_report_deinit(&hid_dev->report);
    543 
    544570}
    545571
Note: See TracChangeset for help on using the changeset viewer.