emulator: removed dead code & added lock to touchscreen 61/11361/1
authorGiWoong Kim <giwoong.kim@samsung.com>
Thu, 24 Oct 2013 03:07:34 +0000 (12:07 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Thu, 24 Oct 2013 05:43:20 +0000 (14:43 +0900)
Change-Id: I8eb4df360822a1e6d0752c99833befe4d732796c
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/hw/maru_virtio_touchscreen.c
tizen/src/skin/client/src/org/tizen/emulator/skin/comm/sock/SocketCommunicator.java
tizen/src/skin/maruskin_server.c

index 9f7d74cfe9dde169e666aed260d91571ba747b27..e19731943645c46163ddb434e3e855ece70a80b7 100644 (file)
@@ -318,10 +318,15 @@ static int virtio_touchscreen_device_init(VirtIODevice *vdev)
     ts->qdev = qdev;
 
     /* reset the counters */
+    pthread_mutex_lock(&event_mutex);
     event_queue_cnt = event_ringbuf_cnt = 0;
+    pthread_mutex_unlock(&event_mutex);
+
+    pthread_mutex_lock(&elem_mutex);
     elem_queue_cnt = elem_ringbuf_cnt = 0;
 
     ts->waitBuf = false;
+    pthread_mutex_unlock(&elem_mutex);
 
     /* bottom halves */
     ts->bh = qemu_bh_new(maru_touchscreen_bh, ts);
index 8d806d0de73d220f27dd52cf231d93dab83619cf..2ead9b2ab4748d65692e1283bf808bd43436d370 100755 (executable)
@@ -265,7 +265,7 @@ public class SocketCommunicator implements ICommunicator {
                                        increaseHeartbeatCount();
 
                                        if (isHeartbeatExpired()) {
-                                               logger.info("heartbeat was expired");
+                                               logger.info("heartbeat was expired!");
                                                terminate();
                                        }
                                }
index bf38df492b1f25fbe9509d0f086d7db8c9480c9c..2a816fe2bbf1c08f394bcd39230d694bede800c5 100644 (file)
 #include <ws2tcpip.h>
 
 #define socket_error() WSAGetLastError()
-
 #else
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <sys/socket.h>
 
 #define socket_error() errno
-
 #endif
 
 #include "debug_ch.h"
 
 MULTI_DEBUG_CHANNEL(qemu, skin_server);
 
+
 #define MAX_REQ_ID 0x7fffffff
 #define RECV_BUF_SIZE 32
 #define RECV_HEADER_SIZE 12
@@ -84,12 +83,6 @@ MULTI_DEBUG_CHANNEL(qemu, skin_server);
 #define HEART_BEAT_FAIL_COUNT 10
 #define HEART_BEAT_EXPIRE_COUNT 10
 
-#if 0 // do not restarting skin process ( prevent from abnormal behavior killing a skin process in Windows )
-#define RESTART_CLIENT_MAX_COUNT 1
-#else
-#define RESTART_CLIENT_MAX_COUNT 0
-#endif
-
 #define PORT_RETRY_COUNT 50
 
 #define HB_IGNORE "hb.ignore"
@@ -628,11 +621,16 @@ static void* run_skin_server(void* args)
     }
 
     memset(&server_addr, '\0', sizeof(server_addr));
-    getsockname(server_sock, (struct sockaddr *) &server_addr, &server_len);
-    svr_port = ntohs( ((struct sockaddr_in *) &server_addr)->sin_port );
+    if (getsockname(server_sock,
+            (struct sockaddr *) &server_addr, &server_len) != 0) {
+        ERR("failed to obtain the local name for a socket\n");
+    } else {
+        svr_port = ntohs(((struct sockaddr_in *) &server_addr)->sin_port);
 
-    INFO("success to bind port[127.0.0.1:%d/tcp] for skin_server in host\n",
-        svr_port);
+        INFO("success to bind port[%s:%d/tcp] for skin_server in host\n",
+                inet_ntoa(((struct sockaddr_in *) &server_addr)->sin_addr),
+                svr_port);
+    }
 
     if (0 > listen(server_sock, 4)) {
         ERR("skin_server listen error\n");
@@ -1291,14 +1289,12 @@ static void* do_heart_beat(void* args)
     is_started_heartbeat = 1;
 
     int send_fail_count = 0;
-    int restart_client_count = 0;
-    int need_restart_skin_client = 0;
     int shutdown = 0;
 
     unsigned int booting_handicap_cnt = 0;
     unsigned int hb_interval = HEART_BEAT_INTERVAL * 1000;
 
-    while ( 1 ) {
+    while (1) {
         if (booting_handicap_cnt < 5) {
             booting_handicap_cnt++;
 
@@ -1320,9 +1316,10 @@ static void* do_heart_beat(void* args)
             break;
         }
 
-        if ( client_sock ) {
-            TRACE( "send HB\n" );
-            if ( 0 > send_skin_header_only( client_sock, SEND_HEART_BEAT, 0 ) ) {
+        if (client_sock) {
+            TRACE("send HB\n");
+
+            if (0 > send_skin_header_only(client_sock, SEND_HEART_BEAT, 0)) {
                 send_fail_count++;
             } else {
                 send_fail_count = 0;
@@ -1330,87 +1327,53 @@ static void* do_heart_beat(void* args)
         } else {
             /* fail to get socket in accepting or client is not yet accepted */
             send_fail_count++;
-            TRACE( "[HB] client socket is NULL yet.\n" );
+            TRACE("[HB] client socket is NULL yet.\n");
         }
 
-        if ( HEART_BEAT_FAIL_COUNT < send_fail_count ) {
-            ERR( "[HB] fail to send heart beat to skin. fail count:%d\n", HEART_BEAT_FAIL_COUNT );
-            need_restart_skin_client = 1;
+        if ((HEART_BEAT_FAIL_COUNT + 1) < send_fail_count) {
+            ERR("[HB] fail to send heart beat to skin. fail count : %d\n",
+                HEART_BEAT_FAIL_COUNT);
+
+            shutdown = 1;
+            break;
         }
 
-        pthread_mutex_lock( &mutex_recv_heartbeat_count );
+        pthread_mutex_lock(&mutex_recv_heartbeat_count);
         recv_heartbeat_count++;
         if (1 < recv_heartbeat_count) {
-            INFO("[HB] recv_heartbeat_count:%d\n", recv_heartbeat_count);
-        }
-        pthread_mutex_unlock( &mutex_recv_heartbeat_count );
-
-        if ( HEART_BEAT_EXPIRE_COUNT < recv_heartbeat_count ) {
-            ERR( "received heartbeat count is expired.\n" );
-            need_restart_skin_client = 1;
+            INFO("[HB] recv_heartbeat_count : %d\n", recv_heartbeat_count);
         }
+        pthread_mutex_unlock(&mutex_recv_heartbeat_count);
 
-        if ( need_restart_skin_client ) {
-
-            if ( RESTART_CLIENT_MAX_COUNT <= restart_client_count ) {
-                shutdown = 1;
-                break;
-            } else {
-
-                if ( is_requested_shutdown_qemu_gracefully() ) {
-                    INFO( "requested shutdown_qemu_gracefully, do not retry starting skin client process.\n" );
-                    break;
-                } else {
-
-                    send_fail_count = 0;
-                    recv_heartbeat_count = 0;
-                    need_restart_skin_client = 0;
-                    restart_client_count++;
-
-                    INFO( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" );
-                    INFO( "!!! restart skin client process !!!\n" );
-                    INFO( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" );
-
-                    is_force_close_client = 1;
-                    if ( client_sock ) {
-#ifdef CONFIG_WIN32
-                        closesocket( client_sock );
-#else
-                        close( client_sock );
-#endif
-                        client_sock = 0;
-                    }
-
-                    start_skin_client( skin_argc, skin_argv );
-
-                }
-
-            }
+        if (HEART_BEAT_EXPIRE_COUNT < recv_heartbeat_count) {
+            ERR("received heartbeat count is expired.\n");
 
+            shutdown = 1;
+            break;
         }
-
     }
 
-    if ( shutdown ) {
-
-        INFO( "[HB] shutdown skin_server by heartbeat thread.\n" );
+    if (shutdown != 0) {
+        INFO("[HB] shutdown skin_server by heartbeat thread.\n");
 
         is_force_close_client = 1;
-        if ( client_sock ) {
+
+        if (client_sock) {
 #ifdef CONFIG_WIN32
-            closesocket( client_sock );
+            closesocket(client_sock);
 #else
-            close( client_sock );
+            close(client_sock);
 #endif
             client_sock = 0;
         }
 
         stop_server = 1;
-        if ( server_sock ) {
+
+        if (server_sock) {
 #ifdef CONFIG_WIN32
-            closesocket( server_sock );
+            closesocket(server_sock);
 #else
-            close( server_sock );
+            close(server_sock);
 #endif
             server_sock = 0;
         }
@@ -1421,7 +1384,6 @@ static void* do_heart_beat(void* args)
 
         maru_register_exit_msg(MARU_EXIT_HB_TIME_EXPIRED, NULL);
         shutdown_qemu_gracefully();
-
     }
 
     return NULL;