| OLD | NEW |
| 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 <memory> | 8 #include <memory> |
| 9 #include <queue> | 9 #include <queue> |
| 10 | 10 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 for (; limit_check && loop_var < for_with_handle_limit; increment) { \ | 215 for (; limit_check && loop_var < for_with_handle_limit; increment) { \ |
| 216 body \ | 216 body \ |
| 217 } \ | 217 } \ |
| 218 } \ | 218 } \ |
| 219 } while (false) | 219 } while (false) |
| 220 | 220 |
| 221 // Platform-independent, reliable thread identifier. | 221 // Platform-independent, reliable thread identifier. |
| 222 class ThreadId { | 222 class ThreadId { |
| 223 public: | 223 public: |
| 224 // Creates an invalid ThreadId. | 224 // Creates an invalid ThreadId. |
| 225 ThreadId() { base::NoBarrier_Store(&id_, kInvalidId); } | 225 ThreadId() { base::Relaxed_Store(&id_, kInvalidId); } |
| 226 | 226 |
| 227 ThreadId& operator=(const ThreadId& other) { | 227 ThreadId& operator=(const ThreadId& other) { |
| 228 base::NoBarrier_Store(&id_, base::NoBarrier_Load(&other.id_)); | 228 base::Relaxed_Store(&id_, base::Relaxed_Load(&other.id_)); |
| 229 return *this; | 229 return *this; |
| 230 } | 230 } |
| 231 | 231 |
| 232 // Returns ThreadId for current thread. | 232 // Returns ThreadId for current thread. |
| 233 static ThreadId Current() { return ThreadId(GetCurrentThreadId()); } | 233 static ThreadId Current() { return ThreadId(GetCurrentThreadId()); } |
| 234 | 234 |
| 235 // Returns invalid ThreadId (guaranteed not to be equal to any thread). | 235 // Returns invalid ThreadId (guaranteed not to be equal to any thread). |
| 236 static ThreadId Invalid() { return ThreadId(kInvalidId); } | 236 static ThreadId Invalid() { return ThreadId(kInvalidId); } |
| 237 | 237 |
| 238 // Compares ThreadIds for equality. | 238 // Compares ThreadIds for equality. |
| 239 INLINE(bool Equals(const ThreadId& other) const) { | 239 INLINE(bool Equals(const ThreadId& other) const) { |
| 240 return base::NoBarrier_Load(&id_) == base::NoBarrier_Load(&other.id_); | 240 return base::Relaxed_Load(&id_) == base::Relaxed_Load(&other.id_); |
| 241 } | 241 } |
| 242 | 242 |
| 243 // Checks whether this ThreadId refers to any thread. | 243 // Checks whether this ThreadId refers to any thread. |
| 244 INLINE(bool IsValid() const) { | 244 INLINE(bool IsValid() const) { |
| 245 return base::NoBarrier_Load(&id_) != kInvalidId; | 245 return base::Relaxed_Load(&id_) != kInvalidId; |
| 246 } | 246 } |
| 247 | 247 |
| 248 // Converts ThreadId to an integer representation | 248 // Converts ThreadId to an integer representation |
| 249 // (required for public API: V8::V8::GetCurrentThreadId). | 249 // (required for public API: V8::V8::GetCurrentThreadId). |
| 250 int ToInteger() const { return static_cast<int>(base::NoBarrier_Load(&id_)); } | 250 int ToInteger() const { return static_cast<int>(base::Relaxed_Load(&id_)); } |
| 251 | 251 |
| 252 // Converts ThreadId to an integer representation | 252 // Converts ThreadId to an integer representation |
| 253 // (required for public API: V8::V8::TerminateExecution). | 253 // (required for public API: V8::V8::TerminateExecution). |
| 254 static ThreadId FromInteger(int id) { return ThreadId(id); } | 254 static ThreadId FromInteger(int id) { return ThreadId(id); } |
| 255 | 255 |
| 256 private: | 256 private: |
| 257 static const int kInvalidId = -1; | 257 static const int kInvalidId = -1; |
| 258 | 258 |
| 259 explicit ThreadId(int id) { base::NoBarrier_Store(&id_, id); } | 259 explicit ThreadId(int id) { base::Relaxed_Store(&id_, id); } |
| 260 | 260 |
| 261 static int AllocateThreadId(); | 261 static int AllocateThreadId(); |
| 262 | 262 |
| 263 V8_EXPORT_PRIVATE static int GetCurrentThreadId(); | 263 V8_EXPORT_PRIVATE static int GetCurrentThreadId(); |
| 264 | 264 |
| 265 base::Atomic32 id_; | 265 base::Atomic32 id_; |
| 266 | 266 |
| 267 static base::Atomic32 highest_thread_id_; | 267 static base::Atomic32 highest_thread_id_; |
| 268 | 268 |
| 269 friend class Isolate; | 269 friend class Isolate; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 | 516 |
| 517 // Returns the PerIsolateThreadData for the current thread (or NULL if one is | 517 // Returns the PerIsolateThreadData for the current thread (or NULL if one is |
| 518 // not currently set). | 518 // not currently set). |
| 519 static PerIsolateThreadData* CurrentPerIsolateThreadData() { | 519 static PerIsolateThreadData* CurrentPerIsolateThreadData() { |
| 520 return reinterpret_cast<PerIsolateThreadData*>( | 520 return reinterpret_cast<PerIsolateThreadData*>( |
| 521 base::Thread::GetThreadLocal(per_isolate_thread_data_key_)); | 521 base::Thread::GetThreadLocal(per_isolate_thread_data_key_)); |
| 522 } | 522 } |
| 523 | 523 |
| 524 // Returns the isolate inside which the current thread is running. | 524 // Returns the isolate inside which the current thread is running. |
| 525 INLINE(static Isolate* Current()) { | 525 INLINE(static Isolate* Current()) { |
| 526 DCHECK(base::NoBarrier_Load(&isolate_key_created_) == 1); | 526 DCHECK(base::Relaxed_Load(&isolate_key_created_) == 1); |
| 527 Isolate* isolate = reinterpret_cast<Isolate*>( | 527 Isolate* isolate = reinterpret_cast<Isolate*>( |
| 528 base::Thread::GetExistingThreadLocal(isolate_key_)); | 528 base::Thread::GetExistingThreadLocal(isolate_key_)); |
| 529 DCHECK(isolate != NULL); | 529 DCHECK(isolate != NULL); |
| 530 return isolate; | 530 return isolate; |
| 531 } | 531 } |
| 532 | 532 |
| 533 // Usually called by Init(), but can be called early e.g. to allow | 533 // Usually called by Init(), but can be called early e.g. to allow |
| 534 // testing components that require logging but not the whole | 534 // testing components that require logging but not the whole |
| 535 // isolate. | 535 // isolate. |
| 536 // | 536 // |
| (...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1817 | 1817 |
| 1818 EmbeddedVector<char, 128> filename_; | 1818 EmbeddedVector<char, 128> filename_; |
| 1819 FILE* file_; | 1819 FILE* file_; |
| 1820 int scope_depth_; | 1820 int scope_depth_; |
| 1821 }; | 1821 }; |
| 1822 | 1822 |
| 1823 } // namespace internal | 1823 } // namespace internal |
| 1824 } // namespace v8 | 1824 } // namespace v8 |
| 1825 | 1825 |
| 1826 #endif // V8_ISOLATE_H_ | 1826 #endif // V8_ISOLATE_H_ |
| OLD | NEW |