FS#13836 - Remove the pcm sink_mutex to unbreak usb_dac mode

The purpose of the mutex is to make it possible to switch pcm sinks
safely, but pcm_play_lock/unlock and pcm_set_frequency need to be
called from IRQ context which is fundamentally incompatible with
our mutex implementation.

The proper path forward will be to promote the counter-based per-sink
lock/unlock implementation to the pcm core, and only allowing sink
switching when the counter is 0.

In the mean time, just remove sink_mutex entirely as the sink switching
code has yet to be committed.

Change-Id: I029459d7ec6ea47c6e2b8fce52d203129a282832
This commit is contained in:
Solomon Peachy 2026-03-21 07:59:11 -04:00
parent db849f5f8a
commit e923b354a6

View file

@ -83,7 +83,6 @@ static struct pcm_sink* sinks[1] = {
[PCM_SINK_BUILTIN] = &builtin_pcm_sink,
};
static enum pcm_sink_ids cur_sink = PCM_SINK_BUILTIN;
static struct mutex sink_mutex; /* protects sinks and cur_sink */
/* The registered callback function to ask for more mp3 data */
volatile pcm_play_callback_type
@ -238,14 +237,11 @@ bool pcm_is_playing(void)
*/
void pcm_play_lock(void) {
mutex_lock(&sink_mutex);
sinks[cur_sink]->ops.lock();
/* hold sink_mutex until pcm_play_unlock() */
}
void pcm_play_unlock(void) {
sinks[cur_sink]->ops.unlock();
mutex_unlock(&sink_mutex);
}
/* This should only be called at startup before any audio playback or
@ -254,7 +250,6 @@ void pcm_init(void)
{
logf("pcm_init");
mutex_init(&sink_mutex);
for(size_t i = 0; i < ARRAYLEN(sinks); i += 1) {
sinks[i]->pending_freq = sinks[i]->caps.default_freq;
sinks[i]->configured_freq = -1UL;
@ -359,7 +354,6 @@ void pcm_set_frequency(unsigned int samplerate)
samplerate = pcm_sampr_to_hw_sampr(samplerate, type);
#endif /* CONFIG_SAMPR_TYPES */
mutex_lock(&sink_mutex);
struct pcm_sink* sink = sinks[cur_sink];
index = round_value_to_list32(samplerate, sink->caps.samprs, sink->caps.num_samprs, false);
@ -367,7 +361,6 @@ void pcm_set_frequency(unsigned int samplerate)
index = sink->caps.default_freq; /* Invalid = default */
sink->pending_freq = index;
mutex_unlock(&sink_mutex);
}
/* return last-set frequency */
@ -384,14 +377,12 @@ void pcm_apply_settings(void)
pcm_wait_for_init();
mutex_lock(&sink_mutex);
struct pcm_sink* sink = sinks[cur_sink];
if(sink->pending_freq != sink->configured_freq) {
logf(" sink->set_freq");
sink->ops.set_freq(sink->pending_freq);
sink->configured_freq = sink->pending_freq;
}
mutex_unlock(&sink_mutex);
}
#ifdef HAVE_RECORDING