From b0d301dead41f7de35e24d77edc2c0a410eafb48 Mon Sep 17 00:00:00 2001 From: Jeesun Kim Date: Wed, 5 Aug 2015 10:48:10 +0900 Subject: [PATCH] set mutex on gmt handle Change-Id: I016ab62595f8051b7b928d49c762e1d6ea5db692 --- common/cal_time.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common/cal_time.cpp b/common/cal_time.cpp index a475916..80e7a97 100644 --- a/common/cal_time.cpp +++ b/common/cal_time.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include "calendar.h" #include "cal_internal.h" @@ -46,6 +47,7 @@ #define ms2sec(ms) (long long int)(ms / 1000.0) #define sec2ms(s) (s * 1000.0) +static pthread_mutex_t cal_mutex_gmt = PTHREAD_MUTEX_INITIALIZER; static UCalendar *_g_ucal_gmt = NULL; void cal_time_get_registered_tzid_with_offset(int offset, char *registered_tzid, int tzid_size) @@ -269,27 +271,33 @@ int cal_time_init(void) { UCalendar *ucal = NULL; + pthread_mutex_lock(&cal_mutex_gmt); if (NULL == _g_ucal_gmt) { ucal = cal_time_open_ucal(-1, NULL, -1); RETVM_IF(NULL == ucal, CALENDAR_ERROR_SYSTEM, "cal_time_open_ucal() Fail"); _g_ucal_gmt = ucal; } + pthread_mutex_unlock(&cal_mutex_gmt); return CALENDAR_ERROR_NONE; } void cal_time_fini(void) { + pthread_mutex_lock(&cal_mutex_gmt); if (_g_ucal_gmt) { ucal_close(_g_ucal_gmt); _g_ucal_gmt = NULL; } + pthread_mutex_unlock(&cal_mutex_gmt); } static UCalendar* __get_gmt_ucal(void) { + pthread_mutex_lock(&cal_mutex_gmt); if (NULL == _g_ucal_gmt) { cal_time_init(); } + pthread_mutex_unlock(&cal_mutex_gmt); return _g_ucal_gmt; } -- 2.7.4