summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2018-07-02 14:14:32 -0400
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2018-07-03 16:10:21 +0200
commite7e1560e18228905d19e9a34b256fa1a8beb6347 (patch)
treeadccc40f47f03ae835463e175be4c00e6b01a109 /src/lib/eina
parent9c6175b3d6fab2f4238976696523d8e039c86303 (diff)
eina/debug: rework session thread destruction to avoid deadlock on shutdown
when debugging was active, this would frequently result in the monitor thread blocking in a read() call for a fd which had already been closed by the main thread. the main thread would be waiting for the monitor thread to fail its read() and destroy itself, but the read() would never end without an interrupt this reworks the monitor thread destruction to stop relying on the thread to remove its session from the session list and instead only access the list from the main thread, allowing sessions to always be immediately destroyed fix T7103
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_debug.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/lib/eina/eina_debug.c b/src/lib/eina/eina_debug.c
index 6420496786..dbce08d04a 100644
--- a/src/lib/eina/eina_debug.c
+++ b/src/lib/eina/eina_debug.c
@@ -132,6 +132,8 @@ struct _Eina_Debug_Session
132 void *data; /* User data */ 132 void *data; /* User data */
133 int cbs_length; /* cbs table size */ 133 int cbs_length; /* cbs table size */
134 int fd; /* File descriptor */ 134 int fd; /* File descriptor */
135 Eina_Lock lock; /* deletion lock */
136 Eina_Bool deleted : 1; /* set if session is dead */
135}; 137};
136 138
137#ifndef _WIN32 139#ifndef _WIN32
@@ -271,6 +273,17 @@ eina_debug_session_terminate(Eina_Debug_Session *session)
271 /* Close fd here so the thread terminates its own session by itself */ 273 /* Close fd here so the thread terminates its own session by itself */
272 if (!session) return; 274 if (!session) return;
273 close(session->fd); 275 close(session->fd);
276 eina_lock_take(&session->lock);
277 if (session->deleted)
278 {
279 eina_lock_release(&session->lock);
280 free(session);
281 }
282 else
283 {
284 session->deleted = 1;
285 eina_lock_release(&session->lock);
286 }
274} 287}
275 288
276EAPI void 289EAPI void
@@ -451,6 +464,7 @@ _session_create(int fd)
451 if (!session) return NULL; 464 if (!session) return NULL;
452 session->dispatch_cb = eina_debug_dispatch; 465 session->dispatch_cb = eina_debug_dispatch;
453 session->fd = fd; 466 session->fd = fd;
467 eina_lock_new(&session->lock);
454 eina_spinlock_take(&_thread_delete_lock); 468 eina_spinlock_take(&_thread_delete_lock);
455 sessions = eina_list_append(sessions, session); 469 sessions = eina_list_append(sessions, session);
456 eina_spinlock_release(&_thread_delete_lock); 470 eina_spinlock_release(&_thread_delete_lock);
@@ -586,12 +600,8 @@ _monitor(void *_data)
586 } 600 }
587 else 601 else
588 { 602 {
589 close(session->fd);
590 _opcodes_unregister_all(session); 603 _opcodes_unregister_all(session);
591 eina_spinlock_take(&_thread_delete_lock); 604 eina_debug_session_terminate(session);
592 sessions = eina_list_remove(sessions, session);
593 free(session);
594 eina_spinlock_release(&_thread_delete_lock);
595 break; 605 break;
596 } 606 }
597 } 607 }
@@ -736,22 +746,13 @@ Eina_Bool
736eina_debug_shutdown(void) 746eina_debug_shutdown(void)
737{ 747{
738 Eina_Debug_Session *session; 748 Eina_Debug_Session *session;
739 Eina_List *l;
740 pthread_t self = pthread_self(); 749 pthread_t self = pthread_self();
741 750
742 eina_spinlock_take(&_thread_delete_lock); 751 eina_spinlock_take(&_thread_delete_lock);
743 EINA_LIST_FOREACH(sessions, l, session) 752 EINA_LIST_FREE(sessions, session)
744 eina_debug_session_terminate(session); 753 eina_debug_session_terminate(session);
745 eina_spinlock_release(&_thread_delete_lock); 754 eina_spinlock_release(&_thread_delete_lock);
746 755
747 while (1)
748 {
749 eina_spinlock_take(&_thread_delete_lock);
750 if (!sessions) break;
751 eina_spinlock_release(&_thread_delete_lock);
752 }
753 eina_spinlock_release(&_thread_delete_lock);
754
755 _eina_debug_timer_shutdown(); 756 _eina_debug_timer_shutdown();
756 _eina_debug_bt_shutdown(); 757 _eina_debug_bt_shutdown();
757 _eina_debug_cpu_shutdown(); 758 _eina_debug_cpu_shutdown();