fix the codes for thread safety 01/61701/1 accepted/tizen/common/20160315.220508 accepted/tizen/ivi/20160311.053923 accepted/tizen/mobile/20160311.053800 accepted/tizen/tv/20160311.053833 accepted/tizen/wearable/20160311.053857 submit/tizen/20160310.051213
authorWonnam Jang <wn.jang@samsung.com>
Thu, 10 Mar 2016 02:44:04 +0000 (11:44 +0900)
committerWonnam Jang <wn.jang@samsung.com>
Thu, 10 Mar 2016 02:44:04 +0000 (11:44 +0900)
Change-Id: Icff1631b05f0ad6172c7824834e09b2ddd722c30
Signed-off-by: Wonnam Jang <wn.jang@samsung.com>
server/ttsd_engine_agent.c
server/ttsd_player.c

index 77f7a95..3fffd78 100644 (file)
@@ -464,34 +464,44 @@ int __internal_update_engine_list()
        }
 
        /* get file name from engine directory and get engine information from each filename */
-       DIR *dp;
-       struct dirent *dirp;
+       DIR *dp = NULL;
+       int ret = -1;
+       struct dirent entry;
+       struct dirent *dirp = NULL;
        dp = opendir(TTS_DEFAULT_ENGINE);
 
        if (dp != NULL) {
-               while ((dirp = readdir(dp)) != NULL) {
-                       ttsengine_info_s* info;
-                       char* filepath = NULL;
-                       int file_size;
+               do {
+                       ret = readdir_r(dp, &entry, &dirp);
+                       if (0 != ret) {
+                               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to read directory");
+                               break;
+                       }
 
-                       file_size = strlen(TTS_DEFAULT_ENGINE) + strlen(dirp->d_name) + 5;
-                       filepath = (char*)calloc(file_size, sizeof(char));
+                       if (NULL != dirp) {
+                               ttsengine_info_s* info;
+                               char* filepath = NULL;
+                               int file_size;
 
-                       if (NULL != filepath) {
-                               snprintf(filepath, file_size, "%s/%s", TTS_DEFAULT_ENGINE, dirp->d_name);
-                       } else {
-                               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not enough memory!!");
-                               continue;
-                       }
+                               file_size = strlen(TTS_DEFAULT_ENGINE) + strlen(dirp->d_name) + 5;
+                               filepath = (char*)calloc(file_size, sizeof(char));
 
-                       /* get its info and update engine list */
-                       if (0 == __internal_get_engine_info(filepath, &info)) {
-                               /* add engine info to g_engine_list */
-                               g_engine_list = g_list_append(g_engine_list, info);
-                       }
+                               if (NULL != filepath) {
+                                       snprintf(filepath, file_size, "%s/%s", TTS_DEFAULT_ENGINE, dirp->d_name);
+                               } else {
+                                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not enough memory!!" );
+                                       continue;
+                               }
 
-                       if (NULL != filepath)   free(filepath);
-               }
+                               /* get its info and update engine list */
+                               if (0 == __internal_get_engine_info(filepath, &info)) {
+                                       /* add engine info to g_engine_list */
+                                       g_engine_list = g_list_append(g_engine_list, info);
+                               }
+
+                               if (NULL != filepath)   free(filepath);
+                       }
+               } while (NULL != dirp);
 
                closedir(dp);
        }
@@ -499,29 +509,37 @@ int __internal_update_engine_list()
        dp = opendir(TTS_DOWNLOAD_ENGINE);
 
        if (dp != NULL) {
-               while ((dirp = readdir(dp)) != NULL) {
-                       ttsengine_info_s* info;
-                       char* filepath = NULL;
-                       int file_size;
+               do {
+                       ret = readdir_r(dp, &entry, &dirp);
+                       if (0 != ret) {
+                               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Fail to read directory");
+                               break;
+                       }
 
-                       file_size = strlen(TTS_DOWNLOAD_ENGINE) + strlen(dirp->d_name) + 5;
-                       filepath = (char*)calloc(file_size, sizeof(char));
+                       if (NULL != dirp) {
+                               ttsengine_info_s* info;
+                               char* filepath = NULL;
+                               int file_size;
 
-                       if (NULL != filepath) {
-                               snprintf(filepath, file_size, "%s/%s", TTS_DOWNLOAD_ENGINE, dirp->d_name);
-                       } else {
-                               SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not enough memory!!");
-                               continue;
-                       }
+                               file_size = strlen(TTS_DOWNLOAD_ENGINE) + strlen(dirp->d_name) + 5;
+                               filepath = (char*)calloc(file_size, sizeof(char));
 
-                       /* get its info and update engine list */
-                       if (0 == __internal_get_engine_info(filepath, &info)) {
-                               /* add engine info to g_engine_list */
-                               g_engine_list = g_list_append(g_engine_list, info);
-                       }
+                               if (NULL != filepath) {
+                                       snprintf(filepath, file_size, "%s/%s", TTS_DOWNLOAD_ENGINE, dirp->d_name);
+                               } else {
+                                       SLOG(LOG_ERROR, get_tag(), "[Engine Agent ERROR] Not enough memory!!" );
+                                       continue;
+                               }
 
-                       if (NULL != filepath)   free(filepath);
-               }
+                               /* get its info and update engine list */
+                               if (0 == __internal_get_engine_info(filepath, &info)) {
+                                       /* add engine info to g_engine_list */
+                                       g_engine_list = g_list_append(g_engine_list, info);
+                               }
+
+                               if (NULL != filepath)   free(filepath);
+                       }
+               } while (NULL != dirp);
 
                closedir(dp);
        }
index 0839fbc..de4762f 100644 (file)
@@ -459,7 +459,7 @@ int ttsd_player_release(void)
        int thread_count = ecore_thread_active_get();
        int count = 0;
        while (0 < thread_count) {
-               usleep(10);
+               usleep(10000);
 
                count++;
                if (100 == count) {