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_Bool _thread_runs = EINA_FALSE;
static Eina_Bool _exit_required = EINA_FALSE;
static pthread_t _thread;
static int pipeToThread[2];
@ -103,9 +102,10 @@ _monitor(void *_data EINA_UNUSED)
# endif
(pthread_self(), "Edbg-tim");
#endif
for (;!_exit_required;)
while (1)
{
int timeout = -1; //in milliseconds
pthread_testcancel();
eina_spinlock_take(&_lock);
if (_timers)
{
@ -115,13 +115,13 @@ _monitor(void *_data EINA_UNUSED)
eina_spinlock_release(&_lock);
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 */
if (ret)
{
char c;
if (read(pipeToThread[0], &c, 1) != 1) _exit_required = EINA_TRUE;
if (read(pipeToThread[0], &c, 1) != 1) break;
}
else
{
@ -220,11 +220,19 @@ _eina_debug_timer_init(void)
Eina_Bool
_eina_debug_timer_shutdown(void)
{
char c = '\0';
_exit_required = EINA_TRUE;
if (write(pipeToThread[1], &c, 1) != 1)
e_debug("Eina debug timer shutdown write failed!");
Eina_Debug_Timer *t;
eina_spinlock_take(&_lock);
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);
return EINA_TRUE;
}