diff options
author | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2016-02-14 12:17:27 -0800 |
---|---|---|
committer | Hoa V. DINH <dinh.viet.hoa@gmail.com> | 2016-02-14 12:17:27 -0800 |
commit | 5c91ce1ff93adf119af67baf34ef19ab025de7f2 (patch) | |
tree | e687ad5edf0486b70536adabf84ff187201fca8f /src/core/renderer | |
parent | 62f5fd44bee8ee3034e23a4ce1c1ffc98b7db737 (diff) |
Fixed thread safety
Diffstat (limited to 'src/core/renderer')
-rw-r--r-- | src/core/renderer/MCHTMLRendererCallback.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/core/renderer/MCHTMLRendererCallback.cpp b/src/core/renderer/MCHTMLRendererCallback.cpp index a3b14341..194416ba 100644 --- a/src/core/renderer/MCHTMLRendererCallback.cpp +++ b/src/core/renderer/MCHTMLRendererCallback.cpp @@ -104,41 +104,50 @@ mailcore::HashMap * HTMLRendererTemplateCallback::templateValuesForHeader(mailco mailcore::String * dateString; static mailcore::DateFormatter * fullFormatter = NULL; + static pthread_mutex_t formatterLock = PTHREAD_MUTEX_INITIALIZER; + pthread_mutex_lock(&formatterLock); if (fullFormatter == NULL) { fullFormatter = new mailcore::DateFormatter(); fullFormatter->setDateStyle(mailcore::DateFormatStyleFull); fullFormatter->setTimeStyle(mailcore::DateFormatStyleFull); } + pthread_mutex_unlock(&formatterLock); dateString = fullFormatter->stringFromDate(header->date()); if (dateString != NULL) { result->setObjectForKey(MCSTR("FULLDATE"), dateString->htmlEncodedString()); } static mailcore::DateFormatter * longFormatter = NULL; + pthread_mutex_lock(&formatterLock); if (longFormatter == NULL) { longFormatter = new mailcore::DateFormatter(); longFormatter->setDateStyle(mailcore::DateFormatStyleLong); longFormatter->setTimeStyle(mailcore::DateFormatStyleLong); } + pthread_mutex_unlock(&formatterLock); dateString = longFormatter->stringFromDate(header->date()); if (dateString != NULL) { result->setObjectForKey(MCSTR("LONGDATE"), dateString->htmlEncodedString()); } static mailcore::DateFormatter * mediumFormatter = NULL; + pthread_mutex_lock(&formatterLock); if (mediumFormatter == NULL) { mediumFormatter = new mailcore::DateFormatter(); mediumFormatter->setDateStyle(mailcore::DateFormatStyleMedium); mediumFormatter->setTimeStyle(mailcore::DateFormatStyleMedium); } + pthread_mutex_unlock(&formatterLock); dateString = mediumFormatter->stringFromDate(header->date()); if (dateString != NULL) { result->setObjectForKey(MCSTR("MEDIUMDATE"), dateString->htmlEncodedString()); } static mailcore::DateFormatter * shortFormatter = NULL; + pthread_mutex_lock(&formatterLock); if (shortFormatter == NULL) { shortFormatter = new mailcore::DateFormatter(); shortFormatter->setDateStyle(mailcore::DateFormatStyleShort); shortFormatter->setTimeStyle(mailcore::DateFormatStyleShort); } + pthread_mutex_unlock(&formatterLock); dateString = shortFormatter->stringFromDate(header->date()); if (dateString != NULL) { result->setObjectForKey(MCSTR("SHORTDATE"), dateString->htmlEncodedString()); |