diff options
Diffstat (limited to 'src/cmsplugin.c')
-rw-r--r-- | src/cmsplugin.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/cmsplugin.c b/src/cmsplugin.c index 2b86b64..a52817a 100644 --- a/src/cmsplugin.c +++ b/src/cmsplugin.c @@ -989,3 +989,30 @@ void* CMSEXPORT cmsGetContextUserData(cmsContext ContextID) } +// Use context mutex to provide thread-safe time +cmsBool _cmsGetTime(struct tm* ptr_time) +{ + struct tm* t; +#if defined(HAVE_GMTIME_R) || defined(HAVE__GMTIME64_S) + struct tm tm; +#endif + + time_t now = time(NULL); + +#ifdef HAVE_GMTIME_R + t = gmtime_r(&now, &tm); +#elif defined(HAVE__GMTIME64_S) + t = _gmtime64_s(&tm, &now) == 0 ? &tm : NULL; +#else + _cmsEnterCriticalSectionPrimitive(&_cmsContextPoolHeadMutex); + t = gmtime(&now); + _cmsLeaveCriticalSectionPrimitive(&_cmsContextPoolHeadMutex); +#endif + + if (t == NULL) + return FALSE; + else { + *ptr_time = *t; + return TRUE; + } +} |