diff options
author | Nobuhiko Tanibata <nobuhiko_tanibata@xddp.denso.co.jp> | 2015-08-04 17:09:12 +0900 |
---|---|---|
committer | Nobuhiko Tanibata <nobuhiko_tanibata@xddp.denso.co.jp> | 2015-08-05 16:14:49 +0900 |
commit | 2f71d26d8b62503366dd43b5b7490e86cac97d46 (patch) | |
tree | 88fc204a5f74ec133027a6d5b3075a53e3360e5c /ivi-layermanagement-api/ilmCommon | |
parent | 01b21a122bb3bf680bf073b58f6e0c73b1b5d32a (diff) | |
download | wayland-ivi-extension-2f71d26d8b62503366dd43b5b7490e86cac97d46.tar.gz |
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.
Diffstat (limited to 'ivi-layermanagement-api/ilmCommon')
-rw-r--r-- | ivi-layermanagement-api/ilmCommon/src/ilm_common.c | 49 |
1 files 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 |