eina_debug_timer: make shutdown perform cleanups and kill the timer thread

this should not remain active after eina has been deactivated, so ensure
that everything stops as expected

ref T7019

Differential Revision: https://phab.enlightenment.org/D6304
This commit is contained in:
Mike Blumenkrantz 2018-06-15 16:51:03 -04:00
parent c043f55a43
commit d4a8856426
1 changed files with 16 additions and 8 deletions

View File

@ -56,7 +56,6 @@ struct _Eina_Debug_Timer
static Eina_List *_timers = NULL; static Eina_List *_timers = NULL;
static Eina_Bool _thread_runs = EINA_FALSE; static Eina_Bool _thread_runs = EINA_FALSE;
static Eina_Bool _exit_required = EINA_FALSE;
static pthread_t _thread; static pthread_t _thread;
static int pipeToThread[2]; static int pipeToThread[2];
@ -103,9 +102,10 @@ _monitor(void *_data EINA_UNUSED)
# endif # endif
(pthread_self(), "Edbg-tim"); (pthread_self(), "Edbg-tim");
#endif #endif
for (;!_exit_required;) while (1)
{ {
int timeout = -1; //in milliseconds int timeout = -1; //in milliseconds
pthread_testcancel();
eina_spinlock_take(&_lock); eina_spinlock_take(&_lock);
if (_timers) if (_timers)
{ {
@ -115,13 +115,13 @@ _monitor(void *_data EINA_UNUSED)
eina_spinlock_release(&_lock); eina_spinlock_release(&_lock);
ret = epoll_wait(epfd, events, MAX_EVENTS, timeout); ret = epoll_wait(epfd, events, MAX_EVENTS, timeout);
if (_exit_required) continue; pthread_testcancel();
/* Some timer has been add/removed or we need to exit */ /* Some timer has been add/removed or we need to exit */
if (ret) if (ret)
{ {
char c; char c;
if (read(pipeToThread[0], &c, 1) != 1) _exit_required = EINA_TRUE; if (read(pipeToThread[0], &c, 1) != 1) break;
} }
else else
{ {
@ -220,11 +220,19 @@ _eina_debug_timer_init(void)
Eina_Bool Eina_Bool
_eina_debug_timer_shutdown(void) _eina_debug_timer_shutdown(void)
{ {
char c = '\0'; Eina_Debug_Timer *t;
_exit_required = EINA_TRUE;
if (write(pipeToThread[1], &c, 1) != 1) eina_spinlock_take(&_lock);
e_debug("Eina debug timer shutdown write failed!"); EINA_LIST_FREE(_timers, t)
free(t);
close(pipeToThread[0]);
close(pipeToThread[1]);
if (_thread_runs)
pthread_cancel(_thread);
_thread_runs = 0;
eina_spinlock_release(&_lock);
eina_spinlock_free(&_lock); eina_spinlock_free(&_lock);
return EINA_TRUE; return EINA_TRUE;
} }