pcm: Pull pcm_is_ready back out of the sink structure

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]> Wed, 10 Jun 2026 11:05:29 -0400
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit 59a42fbf61fd5e6fa978c4f0d0184bff8cb0d7c7
Author: Solomon Peachy <[email protected]>
Date:   Wed Jun 10 08:50:46 2026 -0400

    pcm:  Pull pcm_is_ready back out of the sink structure
    
    It is referenced by multiple threads, and as such needs to be both
    volatile and SHAREDBSS to keep everyone happy.
    
    ...should address hangs on startup observed on nano2g and mini2g when
    voiced menus are enabled
    
    Regression introduced in dfa33c2 and made far worse by 759ef27
    
    Change-Id: I202ec6c0d5825ff3a319b7d95d600b4ce06dd685

diff --git a/firmware/export/pcm_sink.h b/firmware/export/pcm_sink.h
index a4945d3534..522a5aa853 100644
--- a/firmware/export/pcm_sink.h
+++ b/firmware/export/pcm_sink.h
@@ -49,7 +49,6 @@ struct pcm_sink {
     /* runtime states */
     unsigned long pending_freq;
     unsigned long configured_freq;
-    unsigned long pcm_is_ready;
 };
 
 enum pcm_sink_ids {
diff --git a/firmware/pcm.c b/firmware/pcm.c
index 6581c59122..e3f2631dea 100644
--- a/firmware/pcm.c
+++ b/firmware/pcm.c
@@ -76,6 +76,9 @@
  *
  */
 
+/* 'true' when all stages of pcm initialization have completed */
+volatile static bool pcm_is_ready[PCM_SINK_NUM] SHAREDBSS_ATTR = { false };
+
 #ifdef USB_ENABLE_IAP
 extern struct pcm_sink iap_pcm_sink;
 #endif
@@ -86,7 +89,7 @@ static struct pcm_sink* sinks[PCM_SINK_NUM] = {
     [PCM_SINK_IAP] = &iap_pcm_sink,
 #endif
 };
-static enum pcm_sink_ids cur_sink = PCM_SINK_BUILTIN;
+static enum pcm_sink_ids cur_sink SHAREDBSS_ATTR = PCM_SINK_BUILTIN;
 
 /* The registered callback function to ask for more mp3 data */
 volatile pcm_play_callback_type
@@ -146,7 +149,7 @@ void pcm_play_stop_int(void)
 
 static void pcm_wait_for_init(void)
 {
-    while (!sinks[cur_sink]->pcm_is_ready)
+    while (!pcm_is_ready[cur_sink])
         sleep(0);
 }
 
@@ -256,9 +259,9 @@ void pcm_init(void)
 
     for(size_t i = 0; i < PCM_SINK_NUM; i += 1) {
         struct pcm_sink* sink = sinks[i];
+        pcm_is_ready[i] = false;
         sink->pending_freq = sink->caps.default_freq;
         sink->configured_freq = -1U;
-        sink->pcm_is_ready = false;
         sink->ops.init();
     }
 }
@@ -271,7 +274,7 @@ void pcm_postinit(void)
     for(size_t i = 0; i < PCM_SINK_NUM; i += 1) {
         struct pcm_sink* sink = sinks[i];
         sink->ops.postinit();
-        sink->pcm_is_ready = true;
+        pcm_is_ready[i] = true;
     }
 
     /* Ensure mixer is in a sane state */
@@ -280,7 +283,7 @@ void pcm_postinit(void)
 
 bool pcm_is_initialized(void)
 {
-    return sinks[cur_sink]->pcm_is_ready;
+    return pcm_is_ready[cur_sink];
 }
 
 enum pcm_sink_ids pcm_current_sink(void)
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs