Use gmtime_r if available, fallback to gmtime with mutex