From 2f71d26d8b62503366dd43b5b7490e86cac97d46 Mon Sep 17 00:00:00 2001 From: Nobuhiko Tanibata Date: Tue, 4 Aug 2015 17:09:12 +0900 Subject: ilmCommon: ilm_init() to be thread-safe. If ilm_init() is called from another thread it will wait until the first of the initialization is complete. Then, when the initialization is complete, and then exits with a ILM_SUCCESS without anything. Also print the following message. --- ivi-layermanagement-api/ilmCommon/src/ilm_common.c | 49 ++++++++++++++++------ 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/ivi-layermanagement-api/ilmCommon/src/ilm_common.c b/ivi-layermanagement-api/ilmCommon/src/ilm_common.c index b669c66..8152968 100644 --- a/ivi-layermanagement-api/ilmCommon/src/ilm_common.c +++ b/ivi-layermanagement-api/ilmCommon/src/ilm_common.c @@ -35,6 +35,8 @@ ILM_EXPORT ilmErrorTypes ilmControl_init(t_ilm_nativedisplay); ILM_EXPORT void ilmControl_destroy(void); +static pthread_mutex_t g_initialize_lock = PTHREAD_MUTEX_INITIALIZER; + ILM_EXPORT ilmErrorTypes ilm_init(void) { @@ -45,26 +47,47 @@ ILM_EXPORT ilmErrorTypes ilm_initWithNativedisplay(t_ilm_nativedisplay nativedisplay) { ilmErrorTypes err = ILM_SUCCESS; + ilmErrorTypes ret = ILM_FAILED; t_ilm_nativedisplay display = 0; - init_ilmCommonPlatformTable(); + pthread_mutex_lock(&g_initialize_lock); - err = gIlmCommonPlatformFunc.init(nativedisplay); - if (ILM_SUCCESS != err) + do { - return err; - } + init_ilmCommonPlatformTable(); - display = gIlmCommonPlatformFunc.getNativedisplay(); + if (ilm_isInitialized()) + { + fprintf(stderr, "[Warning] ilm_init or ilm_initWithNativedisplay is called,\n" + " but ilmClientLib has been already initialized.\n" + " Returning success and initialization is skipped\n" + " at this time.\n"); + ret = ILM_SUCCESS; + break; + } - err = ilmControl_init(display); - if (ILM_SUCCESS != err) - { - gIlmCommonPlatformFunc.destroy(); - return err; - } + err = gIlmCommonPlatformFunc.init(nativedisplay); + if (ILM_SUCCESS != err) + { + break; + } + + display = gIlmCommonPlatformFunc.getNativedisplay(); + + err = ilmControl_init(display); + if (ILM_SUCCESS != err) + { + gIlmCommonPlatformFunc.destroy(); + break; + } + + ret = ILM_SUCCESS; + + } while (0); + + pthread_mutex_unlock(&g_initialize_lock); - return ILM_SUCCESS; + return ret; } ILM_EXPORT t_ilm_bool -- cgit v1.2.1