#define DATA_WORKER_QDATA_MAX_SIZE (3840 * 2160 * 4) /* UHD BGRA8888 */
#define UNLIMITED_INSTANCE -1
+static void _ms_ipc_module_data_ch_cleanup(muse_module_h m);
+static void _ms_ipc_module_msg_ch_cleanup(muse_module_h m);
static void _ms_ipc_module_cleanup(muse_module_h m);
static gboolean _ms_ipc_module_instance_creation_is_allowed(int module_idx);
static gpointer _ms_ipc_dispatch_worker(gpointer data);
static gboolean _ms_ipc_data_processing(int fd, muse_recv_data_head_t *header, muse_channel_info_t *ch);
static gpointer _ms_ipc_data_worker(gpointer data);
-static void _ms_ipc_module_cleanup(muse_module_h m)
+static void _ms_ipc_module_data_ch_cleanup(muse_module_h m)
{
muse_return_if_fail(m);
+ muse_return_if_fail(m->ch[MUSE_CHANNEL_DATA].thread);
+
+ g_thread_join(m->ch[MUSE_CHANNEL_DATA].thread);
+ m->ch[MUSE_CHANNEL_DATA].thread = NULL;
g_mutex_lock(&m->ch[MUSE_CHANNEL_DATA].data_mutex);
g_queue_free(m->ch[MUSE_CHANNEL_DATA].data_queue);
g_cond_broadcast(&m->ch[MUSE_CHANNEL_DATA].data_cond);
g_mutex_unlock(&m->ch[MUSE_CHANNEL_DATA].data_mutex);
- if (m->ch[MUSE_CHANNEL_DATA].thread) {
- g_thread_join(m->ch[MUSE_CHANNEL_DATA].thread);
- m->ch[MUSE_CHANNEL_DATA].thread = NULL;
- }
-
g_mutex_clear(&m->ch[MUSE_CHANNEL_DATA].data_mutex);
g_cond_clear(&m->ch[MUSE_CHANNEL_DATA].data_cond);
- LOGD("worker exit");
+
+ LOGD("[close] [%d] MUSE_CHANNEL_DATA", m->ch[MUSE_CHANNEL_DATA].sock_fd);
+ muse_core_connection_close(m->ch[MUSE_CHANNEL_DATA].sock_fd);
+
+}
+
+static void _ms_ipc_module_msg_ch_cleanup(muse_module_h m)
+{
+ muse_return_if_fail(m);
+ muse_return_if_fail(m->ch[MUSE_CHANNEL_MSG].thread);
+
+ SECURE_LOGD("[close] [%d] MUSE_CHANNEL_MSG %p", m->ch[MUSE_CHANNEL_MSG].sock_fd, m);
+ muse_core_connection_close(m->ch[MUSE_CHANNEL_MSG].sock_fd);
+
+ SECURE_LOGD("%p thread exit", m->ch[MUSE_CHANNEL_MSG].thread);
+ g_thread_unref(m->ch[MUSE_CHANNEL_MSG].thread);
+ m->ch[MUSE_CHANNEL_MSG].thread = NULL;
+}
+
+static void _ms_ipc_module_cleanup(muse_module_h m)
+{
+ muse_return_if_fail(m);
+
+ _ms_ipc_module_data_ch_cleanup(m);
ms_connection_unregister(m);
- ms_exit_worker(m);
+ _ms_ipc_module_msg_ch_cleanup(m);
+
+ g_mutex_clear(&m->dispatch_lock);
+
+ memset(m, 0, sizeof(muse_module_t));
+
+ free(m);
}
static gboolean _ms_ipc_module_instance_creation_is_allowed(int module_idx)
if (!_ms_ipc_module_instance_creation_is_allowed(idx)) {
ms_cmd_dispatch(m, MUSE_MODULE_COMMAND_RESOURCE_NOT_AVAILABLE);
ms_module_dispatch_unlock(m);
- ms_exit_worker(m);
+ attempt_to_dispatch = FALSE;
+ break;
}
if (muse_core_msg_object_get_value(MSG_KEY_PID, jobj, MUSE_TYPE_INT, &pid) && m->pid != pid)
LOGW("connected pid [%d] msg [%d] is different", m->pid, pid);
if (!_ms_ipc_module_instance_creation_is_allowed(idx)) {
ms_cmd_dispatch(m, MUSE_MODULE_COMMAND_RESOURCE_NOT_AVAILABLE);
ms_module_dispatch_unlock(m);
- ms_exit_worker(m);
+ attempt_to_dispatch = FALSE;
+ break;
}
ms_connection_register(m);
_ms_ipc_module_cleanup(m);
- LOGD("Leave");
+ LOGD("worker exit");
+ g_thread_exit(NULL);
+
return NULL;
}
muse_return_val_if_fail(muse_server->watchdog, retval);
muse_return_val_if_fail(muse_server->workqueue, retval);
+ ms_recursive_rmdir(MUSE_DATA_ROOT_PATH);
+
ms_set_state(MUSE_SERVER_STATE_IDLE);
#ifdef MUSE_USE_WATCHDOG
}
}
-void ms_exit_worker(muse_module_h m)
-{
- LOGD("Enter");
-
- muse_return_if_fail(m);
-
- SECURE_LOGD("[close] [%d] MUSE_CHANNEL_MSG %p", m->ch[MUSE_CHANNEL_MSG].sock_fd, m);
- muse_core_connection_close(m->ch[MUSE_CHANNEL_MSG].sock_fd);
-
- LOGD("[close] [%d] MUSE_CHANNEL_DATA", m->ch[MUSE_CHANNEL_DATA].sock_fd);
- muse_core_connection_close(m->ch[MUSE_CHANNEL_DATA].sock_fd);
-
- SECURE_LOGD("%p thread exit", m->ch[MUSE_CHANNEL_MSG].thread);
- if (m->ch[MUSE_CHANNEL_MSG].thread) {
- g_thread_unref(m->ch[MUSE_CHANNEL_MSG].thread);
- m->ch[MUSE_CHANNEL_MSG].thread = NULL;
- }
-
- g_mutex_clear(&m->dispatch_lock);
-
- memset(m, 0, sizeof(muse_module_t));
-
- free(m);
-
- ms_recursive_rmdir(MUSE_DATA_ROOT_PATH);
-
- LOGD("Leave");
-
- g_thread_exit(NULL);
-}
-
void ms_respawn(int signo)
{
pid_t pid = getpid();