communication: added mutex
authorgiwoong.kim <giwoong.kim@samsung.com>
Fri, 25 Jan 2013 12:33:25 +0000 (21:33 +0900)
committergiwoong.kim <giwoong.kim@samsung.com>
Fri, 25 Jan 2013 13:23:34 +0000 (22:23 +0900)
added mutex for send data

Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/skin/maruskin_server.c

index 66d1ce2..4186b57 100644 (file)
@@ -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;