focus-server: wait for callback completion before removing focus pipe 87/324587/1 accepted/tizen_7.0_unified tizen_7.0 accepted/tizen/7.0/unified/20250522.130252
authorSeungbae Shin <seungbae.shin@samsung.com>
Mon, 23 Sep 2024 08:57:09 +0000 (17:57 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Wed, 21 May 2025 05:27:22 +0000 (14:27 +0900)
The wait timeout is set same as other callback timeout (2500ms)

[Version] 0.14.4
[Issue Type] Robustness

Change-Id: I3ea6b397e026fcada087abdf55172f389a8fead1

focus_server/mm_sound_mgr_focus.c
packaging/libmm-sound.spec

index 5d7fbbefdf765d22141dac6e3be14c4bb8329caf..0f9e417f4f9ac717bd6c0d309052831c4a900cd4 100644 (file)
 #include <sys/time.h>
 
 #define CALLBACK_TIMEOUT          2500 /* millisecond */
+#define INVOKE_CHECK_INTERVAL_MS  30
 
 static GList *g_focus_node_list = NULL;
 static pthread_mutex_t g_focus_node_list_mutex = PTHREAD_MUTEX_INITIALIZER;
 static stream_list_t g_stream_list;
 
+static gint g_on_invoke_ref;
+
 static const char* focus_status_str[] = {
        "DEACTIVATED",
        "P ACTIVATED",
@@ -111,10 +114,34 @@ static void __remove_focus_pipe(focus_node_t *node, bool is_return)
        debug_log("focus-pipe(%s) removed", filename);
 }
 
+static void __wait_for_callback_completion(void)
+{
+       unsigned int retry_count = 0;
+
+       debug_fenter();
+
+       /* wait for watch invoke completion or timeout(2500ms) */
+       while (g_atomic_int_get(&g_on_invoke_ref) > 0) {
+               usleep(INVOKE_CHECK_INTERVAL_MS * 1000);
+
+               if (INVOKE_CHECK_INTERVAL_MS * retry_count++ > CALLBACK_TIMEOUT) {
+                       debug_warning("timeout for callback completion, still remaining of %d", g_atomic_int_get(&g_on_invoke_ref));
+                       return;
+               }
+       }
+
+       debug_msg("wait done, retry_count[%d]", retry_count);
+
+       debug_fleave();
+}
+
+
 static void __clear_focus_pipe(focus_node_t *node)
 {
        debug_fenter();
 
+       __wait_for_callback_completion();
+
        __remove_focus_pipe(node, false);
        __remove_focus_pipe(node, true);
 
@@ -320,6 +347,8 @@ static int _mm_sound_mgr_focus_do_watch_callback(focus_type_e focus_type, focus_
                return MM_ERROR_INVALID_ARGUMENT;
        }
 
+       g_atomic_int_inc(&g_on_invoke_ref);
+
        for (list = g_focus_node_list; list != NULL; list = list->next) {
                SET_NODE_FROM_LIST_DATA(node, list);
                if (node == my_node)
@@ -334,6 +363,12 @@ static int _mm_sound_mgr_focus_do_watch_callback(focus_type_e focus_type, focus_
                _invoke_watch_callback(node, my_node->stream_type, focus_type, command, param);
        }
 
+       if (g_atomic_int_dec_and_test(&g_on_invoke_ref)) {
+               debug_msg("no remaining watch invoke");
+       } else {
+               debug_warning("still watch invoke remains in other place");
+       }
+
        debug_fleave();
 
        return MM_ERROR_NONE;
index 2e53a75cc915c70874336518b2c96c72f7eac385..a265a8efc2b0e8dcb326a86c9c090b8b8f8d7c8b 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-sound
 Summary:    MMSound Package contains client lib and focus server binary
-Version:    0.14.3
+Version:    0.14.4
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0