Changeset d48fcc0 in mainline


Ignore:
Timestamp:
2011-04-09T09:45:14Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e9ce696
Parents:
a546687
Message:

Fine grain locking of USB pipes

Location:
uspace/lib/usb
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/include/usb/pipes.h

    ra546687 rd48fcc0  
    6060 * This endpoint must be bound with existing usb_device_connection_t
    6161 * (i.e. the wire to send data over).
     62 *
     63 * Locking order: if you want to lock both mutexes
     64 * (@c guard and @c hc_phone_mutex), lock @c guard first.
     65 * It is not necessary to lock @c guard if you want to lock @c hc_phone_mutex
     66 * only.
    6267 */
    6368typedef struct {
     69        /** Guard of the whole pipe. */
     70        fibril_mutex_t guard;
     71
    6472        /** The connection used for sending the data. */
    6573        usb_device_connection_t *wire;
     
    7987        /** Phone to the host controller.
    8088         * Negative when no session is active.
     89         * It is an error to access this member without @c hc_phone_mutex
     90         * being locked.
     91         * If call over the phone is to be made, it must be preceeded by
     92         * call to pipe_add_ref() [internal libusb function].
    8193         */
    8294        int hc_phone;
  • uspace/lib/usb/src/pipepriv.c

    ra546687 rd48fcc0  
    4242 * @param pipe Pipe to be exclusively accessed.
    4343 */
    44 void pipe_acquire(usb_pipe_t *pipe)
     44void pipe_start_transaction(usb_pipe_t *pipe)
    4545{
    4646        fibril_mutex_lock(&pipe->hc_phone_mutex);
     
    5151 * @param pipe Pipe to be released from exclusive usage.
    5252 */
     53void pipe_end_transaction(usb_pipe_t *pipe)
     54{
     55        fibril_mutex_unlock(&pipe->hc_phone_mutex);
     56}
     57
     58/** Ensure exclusive access to the pipe as a whole.
     59 *
     60 * @param pipe Pipe to be exclusively accessed.
     61 */
     62void pipe_acquire(usb_pipe_t *pipe)
     63{
     64        fibril_mutex_lock(&pipe->guard);
     65}
     66
     67/** Terminate exclusive access to the pipe as a whole.
     68 *
     69 * @param pipe Pipe to be released from exclusive usage.
     70 */
    5371void pipe_release(usb_pipe_t *pipe)
    5472{
    55         fibril_mutex_unlock(&pipe->hc_phone_mutex);
     73        fibril_mutex_unlock(&pipe->guard);
    5674}
    5775
     
    7694                        goto another_try;
    7795                }
     96                /*
     97                 * No locking is needed, refcount is zero and whole pipe
     98                 * mutex is locked.
     99                 */
    78100                pipe->hc_phone = phone;
    79101        }
  • uspace/lib/usb/src/pipepriv.h

    ra546687 rd48fcc0  
    4141void pipe_release(usb_pipe_t *);
    4242
     43void pipe_start_transaction(usb_pipe_t *);
     44void pipe_end_transaction(usb_pipe_t *);
     45
    4346int pipe_add_ref(usb_pipe_t *);
    4447void pipe_drop_ref(usb_pipe_t *);
  • uspace/lib/usb/src/pipesinit.c

    ra546687 rd48fcc0  
    356356        assert(connection);
    357357
     358        fibril_mutex_initialize(&pipe->guard);
    358359        pipe->wire = connection;
    359360        pipe->hc_phone = -1;
  • uspace/lib/usb/src/pipesio.c

    ra546687 rd48fcc0  
    8080
    8181        /* Ensure serialization over the phone. */
    82         pipe_acquire(pipe);
     82        pipe_start_transaction(pipe);
    8383
    8484        /*
     
    9191            NULL);
    9292        if (opening_request == 0) {
    93                 pipe_release(pipe);
     93                pipe_end_transaction(pipe);
    9494                return ENOMEM;
    9595        }
     
    106106         * without breaking the transfer IPC protocol.
    107107         */
    108         pipe_release(pipe);
     108        pipe_end_transaction(pipe);
    109109
    110110        if (data_request == 0) {
     
    227227
    228228        /* Ensure serialization over the phone. */
    229         pipe_acquire(pipe);
     229        pipe_start_transaction(pipe);
    230230
    231231        /*
     
    238238            NULL);
    239239        if (opening_request == 0) {
    240                 pipe_release(pipe);
     240                pipe_end_transaction(pipe);
    241241                return ENOMEM;
    242242        }
     
    251251         * without breaking the transfer IPC protocol.
    252252         */
    253         pipe_release(pipe);
     253        pipe_end_transaction(pipe);
    254254
    255255        if (rc != EOK) {
     
    326326{
    327327        /* Ensure serialization over the phone. */
    328         pipe_acquire(pipe);
     328        pipe_start_transaction(pipe);
    329329
    330330        /*
     
    346346            setup_buffer, setup_buffer_size);
    347347        if (rc != EOK) {
    348                 pipe_release(pipe);
     348                pipe_end_transaction(pipe);
    349349                async_wait_for(opening_request, NULL);
    350350                return rc;
     
    363363         * without breaking the transfer IPC protocol.
    364364         */
    365         pipe_release(pipe);
     365        pipe_end_transaction(pipe);
    366366
    367367
     
    468468{
    469469        /* Ensure serialization over the phone. */
    470         pipe_acquire(pipe);
     470        pipe_start_transaction(pipe);
    471471
    472472        /*
     
    480480            NULL);
    481481        if (opening_request == 0) {
    482                 pipe_release(pipe);
     482                pipe_end_transaction(pipe);
    483483                return ENOMEM;
    484484        }
     
    490490            setup_buffer, setup_buffer_size);
    491491        if (rc != EOK) {
    492                 pipe_release(pipe);
     492                pipe_end_transaction(pipe);
    493493                async_wait_for(opening_request, NULL);
    494494                return rc;
     
    503503
    504504                /* All data sent, pipe can be released. */
    505                 pipe_release(pipe);
     505                pipe_end_transaction(pipe);
    506506
    507507                if (rc != EOK) {
     
    511511        } else {
    512512                /* No data to send, we can release the pipe for others. */
    513                 pipe_release(pipe);
     513                pipe_end_transaction(pipe);
    514514        }
    515515
Note: See TracChangeset for help on using the changeset viewer.