Changeset d5ac90f in mainline


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

Serialization of IPC requests over pipe phone

The pipe phone is now guarded by a fibril mutex.

Location:
uspace/lib/usb
Files:
3 edited

Legend:

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

    r61727bf rd5ac90f  
    4242#include <ipc/devman.h>
    4343#include <ddf/driver.h>
     44#include <fibril_synch.h>
    4445
    4546/** Abstraction of a physical connection to the device.
     
    8081         */
    8182        int hc_phone;
     83
     84        /** Guard for serialization of requests over the phone. */
     85        fibril_mutex_t hc_phone_mutex;
    8286} usb_pipe_t;
    8387
  • uspace/lib/usb/src/pipesinit.c

    r61727bf rd5ac90f  
    358358        pipe->wire = connection;
    359359        pipe->hc_phone = -1;
     360        fibril_mutex_initialize(&pipe->hc_phone_mutex);
    360361        pipe->endpoint_no = endpoint_no;
    361362        pipe->transfer_type = transfer_type;
  • uspace/lib/usb/src/pipesio.c

    r61727bf rd5ac90f  
    5050#include <usbhc_iface.h>
    5151
     52/** Ensure exclusive access to the IPC phone of given pipe.
     53 *
     54 * @param pipe Pipe to be exclusively accessed.
     55 */
     56static void pipe_acquire(usb_pipe_t *pipe)
     57{
     58        fibril_mutex_lock(&pipe->hc_phone_mutex);
     59}
     60
     61/** Terminate exclusive access to the IPC phone of given pipe.
     62 *
     63 * @param pipe Pipe to be released from exclusive usage.
     64 */
     65static void pipe_release(usb_pipe_t *pipe)
     66{
     67        fibril_mutex_unlock(&pipe->hc_phone_mutex);
     68}
     69
     70
     71
    5272/** Request an in transfer, no checking of input parameters.
    5373 *
     
    7898        }
    7999
     100        /* Ensure serialization over the phone. */
     101        pipe_acquire(pipe);
     102
    80103        /*
    81104         * Make call identifying target USB device and type of transfer.
     
    87110            NULL);
    88111        if (opening_request == 0) {
     112                pipe_release(pipe);
    89113                return ENOMEM;
    90114        }
     
    96120        aid_t data_request = async_data_read(pipe->hc_phone, buffer, size,
    97121            &data_request_call);
     122
     123        /*
     124         * Since now on, someone else might access the backing phone
     125         * without breaking the transfer IPC protocol.
     126         */
     127        pipe_release(pipe);
    98128
    99129        if (data_request == 0) {
     
    210240        }
    211241
     242        /* Ensure serialization over the phone. */
     243        pipe_acquire(pipe);
     244
    212245        /*
    213246         * Make call identifying target USB device and type of transfer.
     
    219252            NULL);
    220253        if (opening_request == 0) {
     254                pipe_release(pipe);
    221255                return ENOMEM;
    222256        }
     
    226260         */
    227261        int rc = async_data_write_start(pipe->hc_phone, buffer, size);
     262
     263        /*
     264         * Since now on, someone else might access the backing phone
     265         * without breaking the transfer IPC protocol.
     266         */
     267        pipe_release(pipe);
     268
    228269        if (rc != EOK) {
    229270                async_wait_for(opening_request, NULL);
     
    293334    void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)
    294335{
     336        /* Ensure serialization over the phone. */
     337        pipe_acquire(pipe);
     338
    295339        /*
    296340         * Make call identifying target USB device and control transfer type.
     
    311355            setup_buffer, setup_buffer_size);
    312356        if (rc != EOK) {
     357                pipe_release(pipe);
    313358                async_wait_for(opening_request, NULL);
    314359                return rc;
     
    322367            data_buffer, data_buffer_size,
    323368            &data_request_call);
     369
     370        /*
     371         * Since now on, someone else might access the backing phone
     372         * without breaking the transfer IPC protocol.
     373         */
     374        pipe_release(pipe);
     375
     376
    324377        if (data_request == 0) {
    325378                async_wait_for(opening_request, NULL);
     
    418471    void *data_buffer, size_t data_buffer_size)
    419472{
     473        /* Ensure serialization over the phone. */
     474        pipe_acquire(pipe);
     475
    420476        /*
    421477         * Make call identifying target USB device and control transfer type.
     
    428484            NULL);
    429485        if (opening_request == 0) {
     486                pipe_release(pipe);
    430487                return ENOMEM;
    431488        }
     
    437494            setup_buffer, setup_buffer_size);
    438495        if (rc != EOK) {
     496                pipe_release(pipe);
    439497                async_wait_for(opening_request, NULL);
    440498                return rc;
     
    447505                rc = async_data_write_start(pipe->hc_phone,
    448506                    data_buffer, data_buffer_size);
     507
     508                /* All data sent, pipe can be released. */
     509                pipe_release(pipe);
     510
    449511                if (rc != EOK) {
    450512                        async_wait_for(opening_request, NULL);
    451513                        return rc;
    452514                }
     515        } else {
     516                /* No data to send, we can release the pipe for others. */
     517                pipe_release(pipe);
    453518        }
    454519
Note: See TracChangeset for help on using the changeset viewer.