GAsyncQueue* ret_queue;
GArray *owner_list;
extern GMutex *scanner_mutex;
+gint cur_running_task;
typedef struct ms_req_owner_data
{
}
-gboolean _ms_process_tcp_message(void *data)
+void _ms_process_tcp_message(gpointer data, gpointer user_data)
{
int ret = MS_MEDIA_ERR_NONE;
int recv_msg_size = -1;
/* Connect Media DB*/
if(media_db_connect(&db_handle) != MS_MEDIA_ERR_NONE) {
MS_DBG_ERR("Failed to connect DB");
- return FALSE;
+ return;
}
MS_DBG_ERR("client sokcet : %d", client_sock);
/* Disconnect DB*/
media_db_disconnect(db_handle);
-
- g_thread_exit(0);
+ MS_DBG_ERR("END");
+ g_atomic_int_dec_and_test(&cur_running_task);
}
gboolean ms_read_db_tcp_batch_socket(GIOChannel *src, GIOCondition condition, gpointer data)
{
+#define MAX_THREAD_NUM 3
+
#ifdef _USE_UDS_SOCKET_
struct sockaddr_un client_addr;
#else
struct sockaddr_in client_addr;
#endif
unsigned int client_addr_len;
+ static GThreadPool *gtp = NULL;
+ GError *error = NULL;
int sock = -1;
int client_sock = -1;
MS_DBG_SLOG("Client[%d] is accepted", client_sock);
- g_thread_new("message_thread", (GThreadFunc)_ms_process_tcp_message, GINT_TO_POINTER(client_sock));
+ if (gtp == NULL) {
+ MS_DBG_SLOG("Create New Thread Pool %d", client_sock);
+ gtp = g_thread_pool_new((GFunc)_ms_process_tcp_message, NULL, MAX_THREAD_NUM, TRUE, &error);
+ }
+
+ /*check number of running thread */
+ if (g_atomic_int_get(&cur_running_task) < MAX_THREAD_NUM) {
+ MS_DBG_SLOG("CURRENT RUNNING TASK %d", cur_running_task);
+ g_atomic_int_inc(&cur_running_task);
+ g_thread_pool_push(gtp, GINT_TO_POINTER(client_sock), &error);
+ }
+
+ if (error != NULL) {
+ MS_DBG_SLOG("g_thread_pool_push failed [%d]", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+
+ /*NEED IMPLEMENT ERROR RETURN TO CLIENT*/
return TRUE;
}
+
org_path_len = strlen(req_msg->org_path) + 1;
dst_path_len = strlen(req_msg->dst_path) + 1;
- MS_DBG("Basic Size : %d, org_path : %s[%d], dst_path : %s[%d]", header_size, req_msg->org_path, org_path_len, req_msg->dst_path, dst_path_len);
+ MS_DBG_SLOG("Basic Size : %d, org_path : %s[%d], dst_path : %s[%d]", header_size, req_msg->org_path, org_path_len, req_msg->dst_path, dst_path_len);
size = header_size + org_path_len + dst_path_len;
*buf = malloc(size);
return FALSE;
}
-gboolean _ms_thumb_check_queued_request(gpointer data)
-{
- if (g_thumb_server_queued_all_extracting_request) {
- MS_DBG_WARN("There is queued request");
-
- /* request all-thumb extraction to thumbnail server */
- thumbMsg msg;
- thumbMsg recv_msg;
- memset((void *)&msg, 0, sizeof(msg));
- memset((void *)&recv_msg, 0, sizeof(recv_msg));
-
- msg.msg_type = 2; // THUMB_REQUEST_ALL_MEDIA
- msg.org_path[0] = '\0';
- msg.origin_path_size = 1;
- msg.dst_path[0] = '\0';
- msg.dest_path_size = 1;
-
- /* Command All-thumb extraction to thumbnail server */
- if (!_ms_thumb_agent_send_msg_to_thumb_server(&msg, &recv_msg)) {
- MS_DBG_ERR("_ms_thumb_agent_send_msg_to_thumb_server is failed");
- }
-
- g_thumb_server_queued_all_extracting_request = FALSE;
- } else {
- MS_DBG("There is no queued request");
- return FALSE;
- }
-
- return FALSE;
-}
-
gboolean _ms_thumb_agent_execute_server()
{
int pid;
return FALSE;
}
- MS_DBG("recv %s from thumb daemon is successful", res_msg->dst_path);
+ MS_DBG_SLOG("recv %s from thumb daemon is successful", res_msg->dst_path);
#ifdef _USE_UDS_SOCKET_
ms_ipc_delete_client_socket(&sock_info);
#else
return TRUE;
}
+gboolean _ms_thumb_check_queued_request(gpointer data)
+{
+ if (g_thumb_server_queued_all_extracting_request) {
+ MS_DBG_WARN("There is queued request");
+
+ /* request all-thumb extraction to thumbnail server */
+ thumbMsg msg;
+ thumbMsg recv_msg;
+ memset((void *)&msg, 0, sizeof(msg));
+ memset((void *)&recv_msg, 0, sizeof(recv_msg));
+
+ msg.msg_type = 2; // THUMB_REQUEST_ALL_MEDIA
+ msg.org_path[0] = '\0';
+ msg.origin_path_size = 1;
+ msg.dst_path[0] = '\0';
+ msg.dest_path_size = 1;
+
+ /* Command All-thumb extraction to thumbnail server */
+ if (!_ms_thumb_agent_send_msg_to_thumb_server(&msg, &recv_msg)) {
+ MS_DBG_ERR("_ms_thumb_agent_send_msg_to_thumb_server is failed");
+ }
+
+ g_thumb_server_queued_all_extracting_request = FALSE;
+ } else {
+ MS_DBG("There is no queued request");
+ return FALSE;
+ }
+
+ return FALSE;
+}
+
gboolean _ms_thumb_agent_timer()
{
if (g_thumb_server_extracting) {
if (send(client_sock, buf, buf_size, 0) != buf_size) {
MS_DBG_ERR("sendto failed : %s", strerror(errno));
} else {
- MS_DBG("Sent %s(%d) from %s \n", res_msg.dst_path, strlen(res_msg.dst_path), res_msg.org_path);
+ MS_DBG_SLOG("Sent %s(%d) from %s \n", res_msg.dst_path, strlen(res_msg.dst_path), res_msg.org_path);
}
close(client_sock);
return TRUE;
}
- MS_DBG("Received [%d] %s(%d) from PID(%d) \n", recv_msg->msg_type, recv_msg->org_path, strlen(recv_msg->org_path), recv_msg->pid);
+ MS_DBG_SLOG("Received [%d] %s(%d) from PID(%d) \n", recv_msg->msg_type, recv_msg->org_path, strlen(recv_msg->org_path), recv_msg->pid);
thumbRequest *thumb_req = NULL;
thumb_req = calloc(1, sizeof(thumbRequest));
return TRUE;
}
- MS_DBG("%s is queued", recv_msg->org_path);
+ MS_DBG_SLOG("%s is queued", recv_msg->org_path);
g_queue_push_tail(g_request_queue, (gpointer)thumb_req);
if (!g_queue_work) {