wayland-client: cleanup thread specific data when disconnect, leave logs
authorSung-Jin Park <sj76.park@samsung.com>
Mon, 20 Dec 2021 06:40:15 +0000 (15:40 +0900)
committerJunkyeong Kim <jk0430.kim@samsung.com>
Thu, 16 Feb 2023 10:12:31 +0000 (19:12 +0900)
Change-Id: I04e4ed9265bc9b3377c683ec891069060e85143c
Signed-off-by: Sung-Jin Park <sj76.park@samsung.com>
src/wayland-client.c

index 15fb51b..49e646e 100644 (file)
@@ -1220,24 +1220,19 @@ static struct wl_thread_data*
 get_thread_data(struct wl_display *display)
 {
        struct wl_thread_data *thread_data;
-       struct wl_thread_data *th_data, *th_data_next;
+       struct wl_thread_data *th_data = NULL, *tmp = NULL;
 
        int pid = (int)getpid();
        int tid = (int)syscall(SYS_gettid);
 
        thread_data = pthread_getspecific(display->thread_data_key);
-       if (!thread_data) {
-               wl_list_for_each_safe(th_data, th_data_next, &display->threads, link) {
+       if (!thread_data && display->threads_count > 0) {
+               wl_list_for_each_safe(th_data, tmp, &display->threads, link) {
                        if (th_data && th_data->pid == pid && th_data->tid == tid) {
                                wl_log("[pid:%d tid:%d] Failed to pthread_getspecific. errno(%d, %m)\n", pid, tid, errno);
                                thread_data = th_data;
                                break;
                        }
-                       if (!th_data && !th_data_next)
-                       {
-                               wl_log("[pid:%d, tid:%d] Invalid thread data stored in threads ! errno(%d, %m)\n", pid, tid, errno);
-                               break;
-                       }
                }
        }
 
@@ -1519,6 +1514,9 @@ wl_display_connect_to_fd(int fd)
 
        pthread_mutex_unlock(&display->mutex);
 
+       wl_log("display(%p) connected. (pid:%d, tid:%d, threads_cnt=%d, reader_cnt=%d)\n",
+               display, thread_data->pid, thread_data->tid, display->threads_count, display->reader_count);
+
        return display;
 
  err_connection:
@@ -1611,13 +1609,23 @@ wl_display_connect(const char *name)
 WL_EXPORT void
 wl_display_disconnect(struct wl_display *display)
 {
+       int pid = -1;
+       int tid = -1;
+
        struct wl_thread_data *thread_data;
 
        pthread_mutex_lock(&display->mutex);
 
        thread_data = get_thread_data(display);
        if (thread_data)
+       {
+               pid = thread_data->pid;
+               tid = thread_data->tid;
                destroy_thread_data(thread_data);
+               thread_data = NULL;
+       }
+
+       pthread_setspecific(display->thread_data_key, NULL);
        pthread_key_delete(display->thread_data_key);
 
        wl_connection_destroy(display->connection);
@@ -1630,10 +1638,8 @@ wl_display_disconnect(struct wl_display *display)
        pthread_cond_destroy(&display->reader_cond);
        close(display->fd);
 
-#ifdef WL_DEBUG_QUEUE
-       if (debug_client)
-               wl_dlog("display(%p) disconnected", display);
-#endif
+       wl_log("display(%p) disconnected. (pid:%d, tid:%d, threads_cnt=%d, reader_cnt=%d\n",
+               display, pid, tid, display->threads_count, display->reader_count);
 
        if (display->name)
                free(display->name);