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

Side by Side Diff: src/isolate.h

Issue 637263002: Fix data races and leaks related to v8::Lockers (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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 | « include/v8.h ('k') | src/v8threads.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 #ifndef V8_ISOLATE_H_ 5 #ifndef V8_ISOLATE_H_
6 #define V8_ISOLATE_H_ 6 #define V8_ISOLATE_H_
7 7
8 #include "include/v8-debug.h" 8 #include "include/v8-debug.h"
9 #include "src/allocation.h" 9 #include "src/allocation.h"
10 #include "src/assert-scope.h" 10 #include "src/assert-scope.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 C(Context, context) \ 172 C(Context, context) \
173 C(PendingException, pending_exception) \ 173 C(PendingException, pending_exception) \
174 C(ExternalCaughtException, external_caught_exception) \ 174 C(ExternalCaughtException, external_caught_exception) \
175 C(JSEntrySP, js_entry_sp) 175 C(JSEntrySP, js_entry_sp)
176 176
177 177
178 // Platform-independent, reliable thread identifier. 178 // Platform-independent, reliable thread identifier.
179 class ThreadId { 179 class ThreadId {
180 public: 180 public:
181 // Creates an invalid ThreadId. 181 // Creates an invalid ThreadId.
182 ThreadId() : id_(kInvalidId) {} 182 ThreadId() { base::NoBarrier_Store(&id_, kInvalidId); }
183
184 ThreadId& operator=(const ThreadId& other) {
185 base::NoBarrier_Store(&id_, base::NoBarrier_Load(&other.id_));
186 return *this;
187 }
183 188
184 // Returns ThreadId for current thread. 189 // Returns ThreadId for current thread.
185 static ThreadId Current() { return ThreadId(GetCurrentThreadId()); } 190 static ThreadId Current() { return ThreadId(GetCurrentThreadId()); }
186 191
187 // Returns invalid ThreadId (guaranteed not to be equal to any thread). 192 // Returns invalid ThreadId (guaranteed not to be equal to any thread).
188 static ThreadId Invalid() { return ThreadId(kInvalidId); } 193 static ThreadId Invalid() { return ThreadId(kInvalidId); }
189 194
190 // Compares ThreadIds for equality. 195 // Compares ThreadIds for equality.
191 INLINE(bool Equals(const ThreadId& other) const) { 196 INLINE(bool Equals(const ThreadId& other) const) {
192 return id_ == other.id_; 197 return base::NoBarrier_Load(&id_) == base::NoBarrier_Load(&other.id_);
193 } 198 }
194 199
195 // Checks whether this ThreadId refers to any thread. 200 // Checks whether this ThreadId refers to any thread.
196 INLINE(bool IsValid() const) { 201 INLINE(bool IsValid() const) {
197 return id_ != kInvalidId; 202 return base::NoBarrier_Load(&id_) != kInvalidId;
198 } 203 }
199 204
200 // Converts ThreadId to an integer representation 205 // Converts ThreadId to an integer representation
201 // (required for public API: V8::V8::GetCurrentThreadId). 206 // (required for public API: V8::V8::GetCurrentThreadId).
202 int ToInteger() const { return id_; } 207 int ToInteger() const { return static_cast<int>(base::NoBarrier_Load(&id_)); }
203 208
204 // Converts ThreadId to an integer representation 209 // Converts ThreadId to an integer representation
205 // (required for public API: V8::V8::TerminateExecution). 210 // (required for public API: V8::V8::TerminateExecution).
206 static ThreadId FromInteger(int id) { return ThreadId(id); } 211 static ThreadId FromInteger(int id) { return ThreadId(id); }
207 212
208 private: 213 private:
209 static const int kInvalidId = -1; 214 static const int kInvalidId = -1;
210 215
211 explicit ThreadId(int id) : id_(id) {} 216 explicit ThreadId(int id) { base::NoBarrier_Store(&id_, id); }
212 217
213 static int AllocateThreadId(); 218 static int AllocateThreadId();
214 219
215 static int GetCurrentThreadId(); 220 static int GetCurrentThreadId();
216 221
217 int id_; 222 base::Atomic32 id_;
218 223
219 static base::Atomic32 highest_thread_id_; 224 static base::Atomic32 highest_thread_id_;
220 225
221 friend class Isolate; 226 friend class Isolate;
222 }; 227 };
223 228
224 229
225 #define FIELD_ACCESSOR(type, name) \ 230 #define FIELD_ACCESSOR(type, name) \
226 inline void set_##name(type v) { name##_ = v; } \ 231 inline void set_##name(type v) { name##_ = v; } \
227 inline type name() const { return name##_; } 232 inline type name() const { return name##_; }
(...skipping 1324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 } 1557 }
1553 1558
1554 EmbeddedVector<char, 128> filename_; 1559 EmbeddedVector<char, 128> filename_;
1555 FILE* file_; 1560 FILE* file_;
1556 int scope_depth_; 1561 int scope_depth_;
1557 }; 1562 };
1558 1563
1559 } } // namespace v8::internal 1564 } } // namespace v8::internal
1560 1565
1561 #endif // V8_ISOLATE_H_ 1566 #endif // V8_ISOLATE_H_
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/v8threads.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698