Add audio data transmission mileage in thread safe way 35/266335/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Wed, 10 Nov 2021 14:59:06 +0000 (23:59 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Wed, 10 Nov 2021 14:59:06 +0000 (23:59 +0900)
Change-Id: I6de9199e4c70ec3f04682a52add02a2164e2eb5c

src/service_ipc_dbus.cpp

index a832279..d9038a5 100644 (file)
 #include <message_port.h>
 
 #include <chrono>
+#include <atomic>
 
 #include "service_common.h"
 #include "service_main.h"
 #include "service_ipc_dbus.h"
 
-size_t gAudioDataMileage{0};
+std::atomic_size_t gAudioDataMileage{0};
 
 int CServiceIpcDbus::reconnect()
 {
@@ -269,6 +270,7 @@ int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data,
                MAS_LOGE("Buffer overflow : %zu %zu", new_size, total_size);
                return -1;
        }
+       gAudioDataMileage.fetch_add(data_size);
 
        const long long minimum_flush_interval = 20;
        static long long last_flush_time = get_current_milliseconds_after_epoch();
@@ -278,7 +280,7 @@ int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data,
        if (0 == header.streaming_data_serial % 50 || MAS_SPEECH_STREAMING_EVENT_CONTINUE != event) {
                last_serial_waiting_for_flush = header.streaming_data_serial;
                MAS_LOGE("queueing streaming data, serial : %d %d %zu",
-                       last_serial_waiting_for_flush, event, gAudioDataMileage);
+                       last_serial_waiting_for_flush, event, gAudioDataMileage.load());
        }
        if (pending_buffer_size + total_size > STREAMING_BUFFER_SIZE ||
                MAS_SPEECH_STREAMING_EVENT_FINISH == event ||
@@ -308,13 +310,13 @@ int CServiceIpcDbus::send_streaming_audio_data(pid_t pid, int event, void* data,
 
                if (-1 != last_serial_waiting_for_flush) {
                        MAS_LOGE("flushing streaming data, serial : %d %zu",
-                               last_serial_waiting_for_flush, gAudioDataMileage);
+                               last_serial_waiting_for_flush, gAudioDataMileage.load());
                        last_serial_waiting_for_flush =  -1;
                }
        }
 
        if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) {
-               MAS_LOGE("Sending FINISH event : %zu", gAudioDataMileage);
+               MAS_LOGE("Sending FINISH event : %zu", gAudioDataMileage.load());
                bundle *b = bundle_create();
                if (b) {
                        bundle_add_byte(b, "content", buffer, total_size);
@@ -1158,7 +1160,7 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
 
                } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_START_STREAMING_AUDIO_DATA)) {
                        /* Reset mileage data for logging */
-                       gAudioDataMileage = 0;
+                       gAudioDataMileage.store(0);
                        dispatcher->on_start_streaming_audio_data(mConnectionListener, msg);
 
                } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_STOP_STREAMING_AUDIO_DATA)) {