Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 2fbd49c in mainline


Ignore:
Timestamp:
2022-09-22T09:01:32Z (11 days ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
0636455, 2134bc2, 5c9fbf8, 707f0e72, ccf1d79, d4f18b8f
Parents:
a76e76b
git-author:
Jiri Svoboda <jiri@…> (2022-09-21 18:01:20)
git-committer:
Jiri Svoboda <jiri@…> (2022-09-22 09:01:32)
Message:

Audio synk needs locking

Without locking the list of sink connections, we are exposed
to a race between removing a connection at the end of playback
(typically while destroying a hound context) and audio device
event PCM_EVENT_FRAMES_PLAYED which causes audio mixing to occur
via audio_sink_mix_inputs(), causing hound to crash often at
the end of playback.

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

Legend:

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

    ra76e76b r2fbd49c  
    3636#include <assert.h>
    3737#include <errno.h>
     38#include <fibril_synch.h>
    3839#include <stdlib.h>
    3940#include <str.h>
     
    6465                return EINVAL;
    6566        link_initialize(&sink->link);
     67        fibril_mutex_initialize(&sink->lock);
    6668        list_initialize(&sink->connections);
    6769        sink->name = str_dup(name);
     
    139141
    140142        pcm_format_silence(dest, size, &sink->format);
     143        fibril_mutex_lock(&sink->lock);
    141144        list_foreach(sink->connections, sink_link, connection_t, conn) {
    142145                const errno_t ret = connection_add_source_data(
     
    147150                }
    148151        }
     152        fibril_mutex_unlock(&sink->lock);
    149153}
    150154
  • uspace/srv/audio/hound/audio_sink.h

    ra76e76b r2fbd49c  
    4141#include <stdbool.h>
    4242#include <fibril.h>
     43#include <fibril_synch.h>
    4344#include <pcm/format.h>
    4445
     
    5152        /** Link in hound's sink list */
    5253        link_t link;
     54        /** Protect sink including list of connections */
     55        fibril_mutex_t lock;
    5356        /** List of all related connections */
    5457        list_t connections;
  • uspace/srv/audio/hound/connection.c

    ra76e76b r2fbd49c  
    6161                conn->source = source;
    6262                list_append(&conn->source_link, &source->connections);
     63                fibril_mutex_lock(&sink->lock);
    6364                list_append(&conn->sink_link, &sink->connections);
     65                fibril_mutex_unlock(&sink->lock);
    6466                audio_sink_set_format(sink, audio_source_format(source));
    6567                if (source->connection_change)
     
    8385        assert(!link_in_use(&connection->hound_link));
    8486        list_remove(&connection->source_link);
     87        fibril_mutex_lock(&connection->sink->lock);
    8588        list_remove(&connection->sink_link);
     89        fibril_mutex_unlock(&connection->sink->lock);
    8690        if (connection->sink && connection->sink->connection_change)
    8791                connection->sink->connection_change(connection->sink, false);
  • uspace/srv/audio/hound/hound.c

    ra76e76b r2fbd49c  
    126126        assert(fibril_mutex_is_locked(&hound->list_guard));
    127127        log_verbose("Removing sink '%s'.", sink->name);
     128        fibril_mutex_lock(&sink->lock);
    128129        if (!list_empty(&sink->connections))
    129130                log_warning("Removing sink '%s' while still connected.", sink->name);
     
    135136        }
    136137        list_remove(&sink->link);
     138        fibril_mutex_unlock(&sink->lock);
    137139}
    138140
Note: See TracChangeset for help on using the changeset viewer.