Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Unified Diff: base/time/time_posix.cc

Issue 444473002: Add lock to prevent race on SysTimeFromTimeStruct (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time_posix.cc
diff --git a/base/time/time_posix.cc b/base/time/time_posix.cc
index b5b8213846dbbd282b7aab63c681dc15f6a9ae33..27438144376eb139d90555247cc433a981f5ad02 100644
--- a/base/time/time_posix.cc
+++ b/base/time/time_posix.cc
@@ -16,8 +16,10 @@
#include <ostream>
#include "base/basictypes.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/port.h"
+#include "base/synchronization/lock.h"
#include "build/build_config.h"
#if defined(OS_ANDROID)
@@ -28,6 +30,11 @@
namespace {
+// This prevents a crash on traversing the environment global and looking up
+// the 'TZ' variable in libc.
willchan no longer on Chromium 2014/08/06 20:43:24 Please update this to reference the bug so people
bengr 2014/08/07 18:28:30 Done.
+base::LazyInstance<base::Lock>::Leaky
+ g_sys_time_to_time_struct_lock = LAZY_INSTANCE_INITIALIZER;
+
#if !defined(OS_MACOSX)
// Define a system-specific SysTime that wraps either to a time_t or
// a time64_t depending on the host system, and associated convertion.
@@ -36,6 +43,7 @@ namespace {
typedef time64_t SysTime;
SysTime SysTimeFromTimeStruct(struct tm* timestruct, bool is_local) {
+ base::AutoLock locked(g_sys_time_to_time_struct_lock.Get());
if (is_local)
return mktime64(timestruct);
else
@@ -43,6 +51,7 @@ SysTime SysTimeFromTimeStruct(struct tm* timestruct, bool is_local) {
}
void SysTimeToTimeStruct(SysTime t, struct tm* timestruct, bool is_local) {
+ base::AutoLock locked(g_sys_time_to_time_struct_lock.Get());
if (is_local)
localtime64_r(&t, timestruct);
else
@@ -53,6 +62,7 @@ void SysTimeToTimeStruct(SysTime t, struct tm* timestruct, bool is_local) {
typedef time_t SysTime;
SysTime SysTimeFromTimeStruct(struct tm* timestruct, bool is_local) {
+ base::AutoLock locked(g_sys_time_to_time_struct_lock.Get());
if (is_local)
return mktime(timestruct);
else
@@ -60,6 +70,7 @@ SysTime SysTimeFromTimeStruct(struct tm* timestruct, bool is_local) {
}
void SysTimeToTimeStruct(SysTime t, struct tm* timestruct, bool is_local) {
+ base::AutoLock locked(g_sys_time_to_time_struct_lock.Get());
if (is_local)
localtime_r(&t, timestruct);
else
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698