Changeset 78aca91b in mainline


Ignore:
Timestamp:
2013-04-06T18:02:40Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
98af9cc
Parents:
2c0b348
Message:

hound: Use synchronization primitives instead of sleep waiting

Location:
uspace/srv/audio/hound
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/audio/hound/hound_ctx.c

    r2c0b348 r78aca91b  
    111111        int flags;
    112112        size_t allowed_size;
     113        fibril_mutex_t guard;
     114        fibril_condvar_t change;
    113115} hound_ctx_stream_t;
    114116
     
    144146                audio_pipe_init(&stream->fifo);
    145147                link_initialize(&stream->link);
     148                fibril_mutex_initialize(&stream->guard);
     149                fibril_condvar_initialize(&stream->change);
    146150                stream->ctx = ctx;
    147151                stream->flags = flags;
     
    182186                return EINVAL;
    183187
    184         if (stream->allowed_size &&
    185             (audio_pipe_bytes(&stream->fifo) + size > stream->allowed_size))
    186                 return EBUSY;
    187 
    188         return audio_pipe_push_data(&stream->fifo, data, size, stream->format);
     188        fibril_mutex_lock(&stream->guard);
     189        while (stream->allowed_size &&
     190            (audio_pipe_bytes(&stream->fifo) + size > stream->allowed_size)) {
     191            fibril_condvar_wait(&stream->change, &stream->guard);
     192
     193        }
     194
     195        const int ret =
     196            audio_pipe_push_data(&stream->fifo, data, size, stream->format);
     197        fibril_mutex_unlock(&stream->guard);
     198        return ret;
    189199}
    190200
     
    199209{
    200210        assert(stream);
    201         const ssize_t copied_size =
    202             audio_pipe_mix_data(&stream->fifo, data, size, f);
    203         if (copied_size != (ssize_t)size)
    204                 log_warning("Not enough data in stream buffer");
    205         return copied_size;
     211        fibril_mutex_lock(&stream->guard);
     212        const int ret = audio_pipe_mix_data(&stream->fifo, data, size, f);
     213        fibril_condvar_signal(&stream->change);
     214        fibril_mutex_unlock(&stream->guard);
     215        return ret;
    206216}
    207217
     
    210220        assert(stream);
    211221        log_debug("Draining stream");
     222        fibril_mutex_lock(&stream->guard);
    212223        while (audio_pipe_bytes(&stream->fifo))
    213                 async_usleep(10000);
     224                fibril_condvar_wait(&stream->change, &stream->guard);
     225        fibril_mutex_unlock(&stream->guard);
    214226}
    215227
     
    233245        list_foreach(ctx->streams, it) {
    234246                hound_ctx_stream_t *stream = hound_ctx_stream_from_link(it);
    235                 hound_ctx_stream_add_self(stream, buffer, size, &source->format);
     247                ssize_t copied = hound_ctx_stream_add_self(
     248                    stream, buffer, size, &source->format);
     249                if (copied != (ssize_t)size)
     250                        log_warning("Not enough data in stream buffer");
    236251        }
    237252        log_verbose("CTX: %p. Pushing audio to %zu connections", ctx,
  • uspace/srv/audio/hound/iface.c

    r2c0b348 r78aca91b  
    8383        if (!ctx)
    8484                return false;
    85         log_info("%s: %p, %d", __FUNCTION__, server, id);
    8685        return hound_ctx_is_record(ctx);
    8786}
     
    150149static int iface_stream_data_write(void *stream, const void *buffer, size_t size)
    151150{
    152         int ret = EOK;
    153         do {
    154                 ret = hound_ctx_stream_write(stream, buffer, size);
    155         } while (ret == EBUSY && (async_usleep(100), 1));
    156         return ret;
     151        return hound_ctx_stream_write(stream, buffer, size);
    157152}
    158153
Note: See TracChangeset for help on using the changeset viewer.