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

Side by Side Diff: src/base/platform/platform-linux.cc

Issue 2184673002: [base] Use thread safe localtime_r() instead of localtime(). (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « src/base/platform/platform-freebsd.cc ('k') | src/base/platform/platform-macos.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Platform-specific code for Linux goes here. For the POSIX-compatible 5 // Platform-specific code for Linux goes here. For the POSIX-compatible
6 // parts, the implementation is in platform-posix.cc. 6 // parts, the implementation is in platform-posix.cc.
7 7
8 #include <pthread.h> 8 #include <pthread.h>
9 #include <semaphore.h> 9 #include <semaphore.h>
10 #include <signal.h> 10 #include <signal.h>
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 #endif // def __arm__ 101 #endif // def __arm__
102 102
103 103
104 const char* OS::LocalTimezone(double time, TimezoneCache* cache) { 104 const char* OS::LocalTimezone(double time, TimezoneCache* cache) {
105 #if V8_OS_NACL 105 #if V8_OS_NACL
106 // Missing support for tm_zone field. 106 // Missing support for tm_zone field.
107 return ""; 107 return "";
108 #else 108 #else
109 if (std::isnan(time)) return ""; 109 if (std::isnan(time)) return "";
110 time_t tv = static_cast<time_t>(std::floor(time/msPerSecond)); 110 time_t tv = static_cast<time_t>(std::floor(time/msPerSecond));
111 struct tm* t = localtime(&tv); // NOLINT(runtime/threadsafe_fn) 111 struct tm tm;
112 struct tm* t = localtime_r(&tv, &tm);
112 if (!t || !t->tm_zone) return ""; 113 if (!t || !t->tm_zone) return "";
113 return t->tm_zone; 114 return t->tm_zone;
114 #endif 115 #endif
115 } 116 }
116 117
117 118
118 double OS::LocalTimeOffset(TimezoneCache* cache) { 119 double OS::LocalTimeOffset(TimezoneCache* cache) {
119 #if V8_OS_NACL 120 #if V8_OS_NACL
120 // Missing support for tm_zone field. 121 // Missing support for tm_zone field.
121 return 0; 122 return 0;
122 #else 123 #else
123 time_t tv = time(NULL); 124 time_t tv = time(NULL);
124 struct tm* t = localtime(&tv); // NOLINT(runtime/threadsafe_fn) 125 struct tm tm;
126 struct tm* t = localtime_r(&tv, &tm);
125 // tm_gmtoff includes any daylight savings offset, so subtract it. 127 // tm_gmtoff includes any daylight savings offset, so subtract it.
126 return static_cast<double>(t->tm_gmtoff * msPerSecond - 128 return static_cast<double>(t->tm_gmtoff * msPerSecond -
127 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); 129 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
128 #endif 130 #endif
129 } 131 }
130 132
131 133
132 void* OS::Allocate(const size_t requested, 134 void* OS::Allocate(const size_t requested,
133 size_t* allocated, 135 size_t* allocated,
134 bool is_executable) { 136 bool is_executable) {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 return munmap(base, size) == 0; 393 return munmap(base, size) == 0;
392 } 394 }
393 395
394 396
395 bool VirtualMemory::HasLazyCommits() { 397 bool VirtualMemory::HasLazyCommits() {
396 return true; 398 return true;
397 } 399 }
398 400
399 } // namespace base 401 } // namespace base
400 } // namespace v8 402 } // namespace v8
OLDNEW
« no previous file with comments | « src/base/platform/platform-freebsd.cc ('k') | src/base/platform/platform-macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698