Changeset d93b3e3 in mainline


Ignore:
Timestamp:
2011-03-25T17:02:08Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1585c7e
Parents:
30718cc2
Message:

Add lock for control transfers (hc can't guarantee their atomicity)

Use one wait condition for multiple waits (rename)

Location:
uspace/lib/usb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/include/usb/host/device_keeper.h

    r30718cc2 rd93b3e3  
    5151        usb_speed_t speed;
    5252        bool occupied;
     53        bool control_used;
    5354        uint16_t toggle_status[2];
    5455        devman_handle_t handle;
     
    6162        struct usb_device_info devices[USB_ADDRESS_COUNT];
    6263        fibril_mutex_t guard;
    63         fibril_condvar_t default_address_occupied;
     64        fibril_condvar_t change;
    6465        usb_address_t last_address;
    6566} usb_device_keeper_t;
     
    9798    usb_address_t address);
    9899
     100void usb_device_keeper_use_control(usb_device_keeper_t *instance,
     101    usb_address_t address);
     102
     103void usb_device_keeper_release_control(usb_device_keeper_t *instance,
     104    usb_address_t address);
     105
    99106#endif
    100107/**
  • uspace/lib/usb/src/host/device_keeper.c

    r30718cc2 rd93b3e3  
    4949        assert(instance);
    5050        fibril_mutex_initialize(&instance->guard);
    51         fibril_condvar_initialize(&instance->default_address_occupied);
     51        fibril_condvar_initialize(&instance->change);
    5252        instance->last_address = 0;
    5353        unsigned i = 0;
    5454        for (; i < USB_ADDRESS_COUNT; ++i) {
    5555                instance->devices[i].occupied = false;
     56                instance->devices[i].control_used = false;
    5657                instance->devices[i].handle = 0;
    5758                instance->devices[i].toggle_status[0] = 0;
     
    7172        fibril_mutex_lock(&instance->guard);
    7273        while (instance->devices[USB_ADDRESS_DEFAULT].occupied) {
    73                 fibril_condvar_wait(&instance->default_address_occupied,
    74                     &instance->guard);
     74                fibril_condvar_wait(&instance->change, &instance->guard);
    7575        }
    7676        instance->devices[USB_ADDRESS_DEFAULT].occupied = true;
     
    9090        instance->devices[USB_ADDRESS_DEFAULT].occupied = false;
    9191        fibril_mutex_unlock(&instance->guard);
    92         fibril_condvar_signal(&instance->default_address_occupied);
     92        fibril_condvar_signal(&instance->change);
    9393}
    9494/*----------------------------------------------------------------------------*/
     
    309309        return instance->devices[address].speed;
    310310}
    311 
     311/*----------------------------------------------------------------------------*/
     312void usb_device_keeper_use_control(usb_device_keeper_t *instance,
     313    usb_address_t address)
     314{
     315        assert(instance);
     316        fibril_mutex_lock(&instance->guard);
     317        while (instance->devices[address].control_used) {
     318                fibril_condvar_wait(&instance->change, &instance->guard);
     319        }
     320        instance->devices[address].control_used = true;
     321        fibril_mutex_unlock(&instance->guard);
     322}
     323/*----------------------------------------------------------------------------*/
     324void usb_device_keeper_release_control(usb_device_keeper_t *instance,
     325    usb_address_t address)
     326{
     327        assert(instance);
     328        fibril_mutex_lock(&instance->guard);
     329        instance->devices[address].control_used = false;
     330        fibril_mutex_unlock(&instance->guard);
     331        fibril_condvar_signal(&instance->change);
     332}
    312333/**
    313334 * @}
Note: See TracChangeset for help on using the changeset viewer.