eina_debug: add function to reset debug subsystem after fork

fork() kills this entire subsystem and leaves its internals
in an inactive but allocated state, so it's necessary to explicitly restart
everything in order to guarantee behavior

@feature

Differential Revision: https://phab.enlightenment.org/D6307
This commit is contained in:
Mike Blumenkrantz 2018-06-15 16:56:06 -04:00
parent bd9edfad00
commit 1de5c251d1
4 changed files with 24 additions and 0 deletions

View File

@ -762,3 +762,14 @@ eina_debug_shutdown(void)
eina_threads_shutdown();
return EINA_TRUE;
}
EAPI void
eina_debug_fork_reset(void)
{
extern Eina_Bool fork_resetting;
fork_resetting = EINA_TRUE;
eina_debug_shutdown();
eina_debug_init();
fork_resetting = EINA_FALSE;
}

View File

@ -299,6 +299,13 @@ EAPI Eina_Debug_Timer *eina_debug_timer_add(unsigned int timeout_ms, Eina_Debug_
*/
EAPI void eina_debug_timer_del(Eina_Debug_Timer *timer);
/**
* @brief Reset the eina debug system after forking
*
* Call this any time the application forks
* @since 1.21
* */
EAPI void eina_debug_fork_reset(void);
/**
* @}
*/

View File

@ -337,9 +337,12 @@ _eina_debug_cpu_init(void)
Eina_Bool
_eina_debug_cpu_shutdown(void)
{
extern Eina_Bool fork_resetting;
if (_eina_debug_sysmon_active)
eina_lock_take(&_sysmon_lock);
_eina_debug_cpu_active = 0;
if (!fork_resetting)
eina_condition_wait(&_exit_cond);
eina_condition_free(&_exit_cond);
eina_lock_release(&_sysmon_lock);

View File

@ -52,9 +52,12 @@ _eina_spinlock_macos_release(Eina_Spinlock *spinlock)
#endif /* EINA_HAVE_OSX_SPINLOCK */
Eina_Bool fork_resetting;
EAPI void
_eina_lock_debug_abort(int err, const char *fn, const volatile void *ptr)
{
if (fork_resetting) return;
fprintf(stderr, "EINA ERROR: '%s' on %s %p\n", strerror(err), fn, ptr);
#ifdef EINA_HAVE_DEBUG_THREADS
abort();