Changeset c657bd7 in mainline for uspace/drv/char/i8042/buffer.h


Ignore:
Timestamp:
2017-11-20T10:06:59Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
19ea61d
Parents:
5d50c419
git-author:
Jiri Svoboda <jiri@…> (2017-11-19 22:05:26)
git-committer:
Jiri Svoboda <jiri@…> (2017-11-20 10:06:59)
Message:

Less is sometimes more. Need chardev_read to be able to return less bytes than requested if less is available. Otherwise cannot read variable-sized packets except yte-by-byte.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/char/i8042/buffer.h

    r5d50c419 rc657bd7  
    113113 *
    114114 * @param buffer Cyclic buffer to read from.
     115 * @param rb Place to store byte read
     116 * @param wait @c True to wait until byte is available
    115117 *
    116  * @return Byte read.
     118 * @return EOK on success, EAGAIN if @c wait is false and no data is available
    117119 *
    118120 */
    119 static inline uint8_t buffer_read(buffer_t *buffer)
     121static inline int buffer_read(buffer_t *buffer, uint8_t *rb, bool wait)
    120122{
    121123        fibril_mutex_lock(&buffer->guard);
    122124       
    123125        /* Buffer is empty. */
    124         while (buffer->write_head == buffer->read_head)
     126        while (wait && buffer->write_head == buffer->read_head)
    125127                fibril_condvar_wait(&buffer->change, &buffer->guard);
     128       
     129        if (buffer->write_head == buffer->read_head) {
     130                fibril_mutex_unlock(&buffer->guard);
     131                return EAGAIN;
     132        }
    126133       
    127134        /* Next position. */
     
    144151       
    145152        fibril_mutex_unlock(&buffer->guard);
    146         return data;
     153        *rb = data;
     154        return EOK;
    147155}
    148156
Note: See TracChangeset for help on using the changeset viewer.