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

Side by Side Diff: src/base/platform/platform-cygwin.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-aix.cc ('k') | src/base/platform/platform-freebsd.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 Cygwin goes here. For the POSIX-compatible 5 // Platform-specific code for Cygwin 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 <errno.h> 8 #include <errno.h>
9 #include <pthread.h> 9 #include <pthread.h>
10 #include <semaphore.h> 10 #include <semaphore.h>
(...skipping 11 matching lines...) Expand all
22 #include "src/base/platform/platform.h" 22 #include "src/base/platform/platform.h"
23 #include "src/base/win32-headers.h" 23 #include "src/base/win32-headers.h"
24 24
25 namespace v8 { 25 namespace v8 {
26 namespace base { 26 namespace base {
27 27
28 28
29 const char* OS::LocalTimezone(double time, TimezoneCache* cache) { 29 const char* OS::LocalTimezone(double time, TimezoneCache* cache) {
30 if (std::isnan(time)) return ""; 30 if (std::isnan(time)) return "";
31 time_t tv = static_cast<time_t>(std::floor(time/msPerSecond)); 31 time_t tv = static_cast<time_t>(std::floor(time/msPerSecond));
32 struct tm* t = localtime(&tv); // NOLINT(runtime/threadsafe_fn) 32 struct tm tm;
33 struct tm* t = localtime_r(&tv, &tm);
33 if (NULL == t) return ""; 34 if (NULL == t) return "";
34 return tzname[0]; // The location of the timezone string on Cygwin. 35 return tzname[0]; // The location of the timezone string on Cygwin.
35 } 36 }
36 37
37 38
38 double OS::LocalTimeOffset(TimezoneCache* cache) { 39 double OS::LocalTimeOffset(TimezoneCache* cache) {
39 // On Cygwin, struct tm does not contain a tm_gmtoff field. 40 // On Cygwin, struct tm does not contain a tm_gmtoff field.
40 time_t utc = time(NULL); 41 time_t utc = time(NULL);
41 DCHECK(utc != -1); 42 DCHECK(utc != -1);
42 struct tm* loc = localtime(&utc); // NOLINT(runtime/threadsafe_fn) 43 struct tm tm;
44 struct tm* loc = localtime_r(&utc, &tm);
43 DCHECK(loc != NULL); 45 DCHECK(loc != NULL);
44 // time - localtime includes any daylight savings offset, so subtract it. 46 // time - localtime includes any daylight savings offset, so subtract it.
45 return static_cast<double>((mktime(loc) - utc) * msPerSecond - 47 return static_cast<double>((mktime(loc) - utc) * msPerSecond -
46 (loc->tm_isdst > 0 ? 3600 * msPerSecond : 0)); 48 (loc->tm_isdst > 0 ? 3600 * msPerSecond : 0));
47 } 49 }
48 50
49 51
50 void* OS::Allocate(const size_t requested, 52 void* OS::Allocate(const size_t requested,
51 size_t* allocated, 53 size_t* allocated,
52 bool is_executable) { 54 bool is_executable) {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 249 }
248 250
249 251
250 bool VirtualMemory::HasLazyCommits() { 252 bool VirtualMemory::HasLazyCommits() {
251 // TODO(alph): implement for the platform. 253 // TODO(alph): implement for the platform.
252 return false; 254 return false;
253 } 255 }
254 256
255 } // namespace base 257 } // namespace base
256 } // namespace v8 258 } // namespace v8
OLDNEW
« no previous file with comments | « src/base/platform/platform-aix.cc ('k') | src/base/platform/platform-freebsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698