From f1d38458b4b4f187b0fcde737be81f1941f244e0 Mon Sep 17 00:00:00 2001 From: "giwoong.kim" Date: Fri, 25 Jan 2013 21:33:25 +0900 Subject: [PATCH] communication: added mutex added mutex for send data Signed-off-by: GiWoong Kim --- tizen/src/skin/maruskin_server.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/tizen/src/skin/maruskin_server.c b/tizen/src/skin/maruskin_server.c index 66d1ce2..4186b57 100644 --- a/tizen/src/skin/maruskin_server.c +++ b/tizen/src/skin/maruskin_server.c @@ -127,9 +127,6 @@ enum { SEND_SHUTDOWN = 999, }; -pthread_mutex_t mutex_screenshot = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t cond_screenshot = PTHREAD_COND_INITIALIZER; - static int seq_req_id = 0; static uint16_t svr_port = 0; @@ -145,7 +142,11 @@ static int is_started_heartbeat = 0; static int stop_heartbeat = 0; static int recv_heartbeat_count = 0; static pthread_t thread_id_heartbeat; + +static pthread_mutex_t mutex_send_data = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t mutex_recv_heartbeat_count = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t mutex_screenshot = PTHREAD_MUTEX_INITIALIZER; +pthread_cond_t cond_screenshot = PTHREAD_COND_INITIALIZER; static int skin_argc = 0; static char** skin_argv = NULL; @@ -267,6 +268,8 @@ void shutdown_skin_server(void) } } + pthread_mutex_destroy(&mutex_send_data); + pthread_mutex_destroy(&mutex_recv_heartbeat_count); } void notify_sensor_daemon_start(void) @@ -1094,8 +1097,13 @@ static int send_skin_header_only(int sockfd, short send_cmd, int print_log) make_header(sockfd, send_cmd, 0, headerbuf, print_log); + /* send */ + pthread_mutex_lock(&mutex_send_data); + int send_count = send(sockfd, headerbuf, SEND_HEADER_SIZE, 0); + pthread_mutex_unlock(&mutex_send_data); + return send_count; } @@ -1105,21 +1113,28 @@ static int send_skin_data(int sockfd, char headerbuf[SEND_HEADER_SIZE] = { 0, }; + if (data == NULL) { + ERR("send data is NULL.\n"); + return -1; + } + make_header(sockfd, send_cmd, length, headerbuf, 1); - int header_cnt = send(sockfd, headerbuf, SEND_HEADER_SIZE, 0); + /* send */ + pthread_mutex_lock(&mutex_send_data); + int header_cnt = send(sockfd, headerbuf, SEND_HEADER_SIZE, 0); if (0 > header_cnt) { ERR("send header for data is NULL.\n"); - return header_cnt; - } + pthread_mutex_unlock(&mutex_send_data); - if (!data) { - ERR("send data is NULL.\n"); - return -1; + return header_cnt; } int send_cnt = send_n(sockfd, data, length, big_data); + + pthread_mutex_unlock(&mutex_send_data); + TRACE("send_n result:%d\n", send_cnt); return send_cnt; -- 2.7.4