Changeset 4688350b in mainline for uspace/drv/bus/usb/xhci/commands.c


Ignore:
Timestamp:
2017-10-01T22:54:09Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
370a1c8
Parents:
4d28d86
Message:

xhci commands: waiting for commands completion uses fibril condvar

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/xhci/commands.c

    r4d28d86 r4688350b  
    8181}
    8282
    83 int xhci_wait_for_command(xhci_cmd_t *cmd, uint32_t timeout)
    84 {
    85         uint32_t time = 0;
     83int xhci_wait_for_command(xhci_cmd_t *cmd, suseconds_t timeout)
     84{
     85        int rv = EOK;
     86
     87        fibril_mutex_lock(&cmd->completed_mtx);
    8688        while (!cmd->completed) {
    87                 async_usleep(1000);
    88                 time += 1000;
    89 
    90                 if (time > timeout)
    91                         return ETIMEOUT;
    92         }
    93 
    94         return EOK;
     89                usb_log_debug2("Waiting for event completion: going to sleep.");
     90                rv = fibril_condvar_wait_timeout(&cmd->completed_cv, &cmd->completed_mtx, timeout);
     91
     92                usb_log_debug2("Waiting for event completion: woken: %s", str_error(rv));
     93                if (rv == ETIMEOUT)
     94                        break;
     95        }
     96        fibril_mutex_lock(&cmd->completed_mtx);
     97
     98        return rv;
    9599}
    96100
     
    98102{
    99103        xhci_cmd_t *cmd = malloc32(sizeof(xhci_cmd_t));
    100         memset(cmd, 0, sizeof(xhci_cmd_t));
     104        xhci_cmd_init(cmd);
     105        return cmd;
     106}
     107
     108void xhci_cmd_init(xhci_cmd_t *cmd)
     109{
     110        memset(cmd, 0, sizeof(*cmd));
    101111
    102112        link_initialize(&cmd->link);
     113
     114        fibril_mutex_initialize(&cmd->completed_mtx);
     115        fibril_condvar_initialize(&cmd->completed_cv);
    103116
    104117        /**
     
    108121         */
    109122        cmd->has_owner = true;
    110 
    111         return cmd;
    112123}
    113124
     
    493504        }
    494505
     506        fibril_mutex_lock(&command->completed_mtx);
    495507        command->completed = true;
     508        fibril_condvar_broadcast(&command->completed_cv);
     509        fibril_mutex_unlock(&command->completed_mtx);
     510
    496511
    497512        if (!command->has_owner) {
Note: See TracChangeset for help on using the changeset viewer.