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;
- }
}
}
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:
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);
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);