Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 4688350b in mainline


Ignore:
Timestamp:
2017-10-01T22:54:09Z (4 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master
Children:
370a1c8
Parents:
4d28d86
Message:

xhci commands: waiting for commands completion uses fibril condvar

Location:
uspace/drv/bus/usb/xhci
Files:
2 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) {
  • uspace/drv/bus/usb/xhci/commands.h

    r4d28d86 r4688350b  
    3939#include <adt/list.h>
    4040#include <stdbool.h>
     41#include <fibril_synch.h>
    4142#include "hw_struct/trb.h"
    4243
     
    5657        bool has_owner;
    5758        bool owns_trb;
     59
     60        /* Will be unlocked after command completes */
     61        fibril_mutex_t completed_mtx;
     62        fibril_condvar_t completed_cv;
    5863} xhci_cmd_t;
    5964
     
    6267int xhci_wait_for_command(xhci_cmd_t *, uint32_t);
    6368xhci_cmd_t *xhci_alloc_command(void);
     69void xhci_cmd_init(xhci_cmd_t *);
    6470void xhci_free_command(xhci_cmd_t *);
    6571
Note: See TracChangeset for help on using the changeset viewer.