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

Side by Side Diff: src/date.h

Issue 197023002: Fix a race in initialization of timezone cache in platform-win32. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix CE Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/date.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 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // before UTC conversion. 55 // before UTC conversion.
56 static const int64_t kMaxTimeBeforeUTCInMs = 56 static const int64_t kMaxTimeBeforeUTCInMs =
57 kMaxTimeInMs + 10 * kMsPerDay; 57 kMaxTimeInMs + 10 * kMsPerDay;
58 58
59 // Sentinel that denotes an invalid local offset. 59 // Sentinel that denotes an invalid local offset.
60 static const int kInvalidLocalOffsetInMs = kMaxInt; 60 static const int kInvalidLocalOffsetInMs = kMaxInt;
61 // Sentinel that denotes an invalid cache stamp. 61 // Sentinel that denotes an invalid cache stamp.
62 // It is an invariant of DateCache that cache stamp is non-negative. 62 // It is an invariant of DateCache that cache stamp is non-negative.
63 static const int kInvalidStamp = -1; 63 static const int kInvalidStamp = -1;
64 64
65 DateCache() : stamp_(0) { 65 DateCache() : stamp_(0), tz_cache_(OS::CreateTimezoneCache()) {
66 ResetDateCache(); 66 ResetDateCache();
67 } 67 }
68 68
69 virtual ~DateCache() {} 69 virtual ~DateCache() {
70 OS::DisposeTimezoneCache(tz_cache_);
71 tz_cache_ = NULL;
72 }
70 73
71 74
72 // Clears cached timezone information and increments the cache stamp. 75 // Clears cached timezone information and increments the cache stamp.
73 void ResetDateCache(); 76 void ResetDateCache();
74 77
75 78
76 // Computes floor(time_ms / kMsPerDay). 79 // Computes floor(time_ms / kMsPerDay).
77 static int DaysFromTime(int64_t time_ms) { 80 static int DaysFromTime(int64_t time_ms) {
78 if (time_ms < 0) time_ms -= (kMsPerDay - 1); 81 if (time_ms < 0) time_ms -= (kMsPerDay - 1);
79 return static_cast<int>(time_ms / kMsPerDay); 82 return static_cast<int>(time_ms / kMsPerDay);
(...skipping 26 matching lines...) Expand all
106 local_offset_ms_ = GetLocalOffsetFromOS(); 109 local_offset_ms_ = GetLocalOffsetFromOS();
107 } 110 }
108 return local_offset_ms_; 111 return local_offset_ms_;
109 } 112 }
110 113
111 114
112 const char* LocalTimezone(int64_t time_ms) { 115 const char* LocalTimezone(int64_t time_ms) {
113 if (time_ms < 0 || time_ms > kMaxEpochTimeInMs) { 116 if (time_ms < 0 || time_ms > kMaxEpochTimeInMs) {
114 time_ms = EquivalentTime(time_ms); 117 time_ms = EquivalentTime(time_ms);
115 } 118 }
116 return OS::LocalTimezone(static_cast<double>(time_ms)); 119 return OS::LocalTimezone(static_cast<double>(time_ms), tz_cache_);
117 } 120 }
118 121
119 // ECMA 262 - 15.9.5.26 122 // ECMA 262 - 15.9.5.26
120 int TimezoneOffset(int64_t time_ms) { 123 int TimezoneOffset(int64_t time_ms) {
121 int64_t local_ms = ToLocal(time_ms); 124 int64_t local_ms = ToLocal(time_ms);
122 return static_cast<int>((time_ms - local_ms) / kMsPerMin); 125 return static_cast<int>((time_ms - local_ms) / kMsPerMin);
123 } 126 }
124 127
125 // ECMA 262 - 15.9.1.9 128 // ECMA 262 - 15.9.1.9
126 int64_t ToLocal(int64_t time_ms) { 129 int64_t ToLocal(int64_t time_ms) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // Cache stamp is used for invalidating caches in JSDate. 178 // Cache stamp is used for invalidating caches in JSDate.
176 // We increment the stamp each time when the timezone information changes. 179 // We increment the stamp each time when the timezone information changes.
177 // JSDate objects perform stamp check and invalidate their caches if 180 // JSDate objects perform stamp check and invalidate their caches if
178 // their saved stamp is not equal to the current stamp. 181 // their saved stamp is not equal to the current stamp.
179 Smi* stamp() { return stamp_; } 182 Smi* stamp() { return stamp_; }
180 void* stamp_address() { return &stamp_; } 183 void* stamp_address() { return &stamp_; }
181 184
182 // These functions are virtual so that we can override them when testing. 185 // These functions are virtual so that we can override them when testing.
183 virtual int GetDaylightSavingsOffsetFromOS(int64_t time_sec) { 186 virtual int GetDaylightSavingsOffsetFromOS(int64_t time_sec) {
184 double time_ms = static_cast<double>(time_sec * 1000); 187 double time_ms = static_cast<double>(time_sec * 1000);
185 return static_cast<int>(OS::DaylightSavingsOffset(time_ms)); 188 return static_cast<int>(OS::DaylightSavingsOffset(time_ms, tz_cache_));
186 } 189 }
187 190
188 virtual int GetLocalOffsetFromOS() { 191 virtual int GetLocalOffsetFromOS() {
189 double offset = OS::LocalTimeOffset(); 192 double offset = OS::LocalTimeOffset(tz_cache_);
190 ASSERT(offset < kInvalidLocalOffsetInMs); 193 ASSERT(offset < kInvalidLocalOffsetInMs);
191 return static_cast<int>(offset); 194 return static_cast<int>(offset);
192 } 195 }
193 196
194 private: 197 private:
195 // The implementation relies on the fact that no time zones have 198 // The implementation relies on the fact that no time zones have
196 // more than one daylight savings offset change per 19 days. 199 // more than one daylight savings offset change per 19 days.
197 // In Egypt in 2010 they decided to suspend DST during Ramadan. This 200 // In Egypt in 2010 they decided to suspend DST during Ramadan. This
198 // led to a short interval where DST is in effect from September 10 to 201 // led to a short interval where DST is in effect from September 10 to
199 // September 30. 202 // September 30.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 DST* after_; 249 DST* after_;
247 250
248 int local_offset_ms_; 251 int local_offset_ms_;
249 252
250 // Year/Month/Day cache. 253 // Year/Month/Day cache.
251 bool ymd_valid_; 254 bool ymd_valid_;
252 int ymd_days_; 255 int ymd_days_;
253 int ymd_year_; 256 int ymd_year_;
254 int ymd_month_; 257 int ymd_month_;
255 int ymd_day_; 258 int ymd_day_;
259
260 TimezoneCache* tz_cache_;
256 }; 261 };
257 262
258 } } // namespace v8::internal 263 } } // namespace v8::internal
259 264
260 #endif 265 #endif
OLDNEW
« no previous file with comments | « no previous file | src/date.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698