Changeset 599034e in mainline


Ignore:
Timestamp:
2013-04-06T13:11:44Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
eca79ff
Parents:
5c98bb28
Message:

hound: user mutex to protect stream list

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

Legend:

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

    r5c98bb28 r599034e  
    5656                link_initialize(&ctx->link);
    5757                list_initialize(&ctx->streams);
     58                fibril_mutex_initialize(&ctx->guard);
    5859                ctx->sink = NULL;
    5960                ctx->source = malloc(sizeof(audio_source_t));
     
    117118}
    118119
     120static inline void stream_append(hound_ctx_t *ctx, hound_ctx_stream_t *stream)
     121{
     122        assert(ctx);
     123        assert(stream);
     124        fibril_mutex_lock(&ctx->guard);
     125        list_append(&stream->link, &ctx->streams);
     126        fibril_mutex_unlock(&ctx->guard);
     127}
     128
     129static inline void stream_remove(hound_ctx_t *ctx, hound_ctx_stream_t *stream)
     130{
     131        assert(ctx);
     132        assert(stream);
     133        fibril_mutex_lock(&ctx->guard);
     134        list_remove(&stream->link);
     135        fibril_mutex_unlock(&ctx->guard);
     136}
     137
    119138hound_ctx_stream_t *hound_ctx_create_stream(hound_ctx_t *ctx, int flags,
    120139        pcm_format_t format, size_t buffer_size)
     
    129148                stream->format = format;
    130149                stream->allowed_size = buffer_size;
    131                 list_append(&stream->link, &ctx->streams);
     150                stream_append(ctx, stream);
    132151                log_verbose("CTX: %p added stream; flags:%#x ch: %u r:%u f:%s",
    133152                    ctx, flags, format.channels, format.sampling_rate,
     
    140159{
    141160        if (stream) {
    142                 //TODO consider DRAIN FLAG
    143                 list_remove(&stream->link);
     161                stream_remove(stream->ctx, stream);
    144162                if (audio_pipe_bytes(&stream->fifo))
    145163                        log_warning("Destroying stream with non empty buffer");
     
    177195}
    178196
    179 int hound_ctx_stream_add_self(hound_ctx_stream_t *stream, void *data,
     197ssize_t hound_ctx_stream_add_self(hound_ctx_stream_t *stream, void *data,
    180198    size_t size, const pcm_format_t *f)
    181199{
     
    185203        if (copied_size != (ssize_t)size)
    186204                log_warning("Not enough data in stream buffer");
    187         return copied_size > 0 ? EOK : copied_size;
     205        return copied_size;
    188206}
    189207
     
    195213                async_usleep(10000);
    196214}
    197 
    198 int hound_ctx_stream_add(hound_ctx_stream_t *stream, void *buffer, size_t size,
    199     pcm_format_t format)
    200 {
    201         return ENOTSUP;
    202 }
    203 
    204215
    205216int update_data(audio_source_t *source, size_t size)
     
    219230            list_count(&ctx->streams));
    220231        pcm_format_silence(buffer, size, &source->format);
     232        fibril_mutex_lock(&ctx->guard);
    221233        list_foreach(ctx->streams, it) {
    222234                hound_ctx_stream_t *stream = hound_ctx_stream_from_link(it);
     
    229241                connection_push_data(conn, adata);
    230242        }
     243        fibril_mutex_unlock(&ctx->guard);
    231244        return EOK;
    232245}
  • uspace/srv/audio/hound/hound_ctx.h

    r5c98bb28 r599034e  
    3939#include <adt/list.h>
    4040#include <hound/protocol.h>
     41#include <fibril_synch.h>
     42
    4143#include "audio_source.h"
    4244#include "audio_sink.h"
     
    4749        audio_source_t *source;
    4850        audio_sink_t *sink;
     51        fibril_mutex_t guard;
    4952} hound_ctx_t;
    5053
     
    7174    size_t size);
    7275int hound_ctx_stream_read(hound_ctx_stream_t *stream, void *buffer, size_t size);
    73 int hound_ctx_stream_add_self(hound_ctx_stream_t *stream, void *data,
     76ssize_t hound_ctx_stream_add_self(hound_ctx_stream_t *stream, void *data,
    7477    size_t size, const pcm_format_t *f);
    7578void hound_ctx_stream_drain(hound_ctx_stream_t *stream);
    76 int hound_ctx_stream_add(hound_ctx_stream_t *stream, void *buffer, size_t size,
    77     pcm_format_t format);
    7879
    7980#endif
Note: See TracChangeset for help on using the changeset viewer.