Chromium Code Reviews| Index: src/isolate.h |
| diff --git a/src/isolate.h b/src/isolate.h |
| index 856d2cefcd2911fe7aa00a2fb5342e528d1c1186..6b32756e4f9dce9a0f2c2749989f694e41a368f7 100644 |
| --- a/src/isolate.h |
| +++ b/src/isolate.h |
| @@ -135,6 +135,43 @@ typedef ZoneList<Handle<Object> > ZoneObjectList; |
| #define ISOLATE_ADDRESS_LIST_PROF(C) |
| #endif |
|
Vitaly Repeshko
2011/04/11 19:28:52
Style nit: two blank lines between top-level decla
Dmitry Lomov
2011/04/11 21:41:14
Done.
|
| +// Platform-independent, reliable thread identifier |
|
Vitaly Repeshko
2011/04/11 19:28:52
nit: Comments that are full sentences should start
Dmitry Lomov
2011/04/11 21:41:14
Done.
|
| +class ThreadId { |
| + public: |
| + // Creates an invalid ThreadId |
| + ThreadId() : id_(kInvalidId) {} |
| + |
| + // Returns ThreadId for current thread |
| + static ThreadId Current() { return ThreadId(GetCurrentThreadId()); } |
| + |
| + // Returns invalid ThreadId (guaranteed not to be equal to any thread) |
| + static ThreadId Invalid() { return ThreadId(kInvalidId); } |
|
Vitaly Repeshko
2011/04/11 19:28:52
!thread_id.Equals(ThreadId::Invalid()) seems to be
Dmitry Lomov
2011/04/11 21:41:14
Done.
|
| + |
| + // Compares ThreadIds for equality |
| + INLINE(bool Equals(const ThreadId& other) const) { |
| + return id_ == other.id_; |
| + } |
| + |
| + // Converts ThreadId to an integer representation |
| + // (required for public API: V8::V8::GetCurrentThreadId). |
| + int ToInteger() const { return id_; } |
| + |
| + // Converts ThreadId to an integer representation |
| + // (required for public API: V8::V8::TerminateExecution). |
| + static ThreadId FromInteger(int id) { return ThreadId(id); } |
| + |
| + private: |
| + int id_; |
|
Vitaly Repeshko
2011/04/11 19:28:52
Please sort these following the rules in http://go
Dmitry Lomov
2011/04/11 21:41:14
Done.
|
| + static const int kInvalidId = -1; |
| + static Mutex* thread_id_process_wide_mutex_; |
| + static int highest_thread_id_; |
| + |
| + explicit ThreadId(int id) : id_(id) {} |
| + |
| + static int AllocateThreadId(); |
| + static int GetCurrentThreadId(); |
| + friend class Isolate; |
| +}; |
|
Vitaly Repeshko
2011/04/11 19:28:52
Two blank lines.
Dmitry Lomov
2011/04/11 21:41:14
Done.
|
| class ThreadLocalTop BASE_EMBEDDED { |
| public: |
| @@ -176,7 +213,7 @@ class ThreadLocalTop BASE_EMBEDDED { |
| // The context where the current execution method is created and for variable |
| // lookups. |
| Context* context_; |
| - int thread_id_; |
| + ThreadId thread_id_; |
| MaybeObject* pending_exception_; |
| bool has_pending_message_; |
| const char* pending_message_; |
| @@ -333,8 +370,6 @@ class Isolate { |
| public: |
| ~Isolate(); |
| - typedef int ThreadId; |
| - |
| // A thread has a PerIsolateThreadData instance for each isolate that it has |
| // entered. That instance is allocated when the isolate is initially entered |
| // and reused on subsequent entries. |
| @@ -367,7 +402,7 @@ class Isolate { |
| #endif |
| bool Matches(Isolate* isolate, ThreadId thread_id) const { |
| - return isolate_ == isolate && thread_id_ == thread_id; |
| + return isolate_ == isolate && thread_id_.Equals(thread_id); |
| } |
| private: |
| @@ -454,14 +489,10 @@ class Isolate { |
| return isolate_key_; |
| } |
| - // Returns the key used to store process-wide thread IDs. |
| static Thread::LocalStorageKey thread_id_key() { |
|
Vitaly Repeshko
2011/04/11 19:28:52
Restore the comment.
Dmitry Lomov
2011/04/11 21:41:14
Done.
Dmitry Lomov
2011/04/11 21:41:14
Done.
|
| return thread_id_key_; |
| } |
| - // Atomically allocates a new thread ID. |
| - static ThreadId AllocateThreadId(); |
| - |
| // If a client attempts to create a Locker without specifying an isolate, |
| // we assume that the client is using legacy behavior. Set up the current |
| // thread to be inside the implicit isolate (or fail a check if we have |
| @@ -487,8 +518,8 @@ class Isolate { |
| } |
| // Access to current thread id. |
| - int thread_id() { return thread_local_top_.thread_id_; } |
| - void set_thread_id(int id) { thread_local_top_.thread_id_ = id; } |
| + ThreadId thread_id() { return thread_local_top_.thread_id_; } |
| + void set_thread_id(ThreadId id) { thread_local_top_.thread_id_ = id; } |
| // Interface to pending exception. |
| MaybeObject* pending_exception() { |
| @@ -1003,7 +1034,6 @@ class Isolate { |
| static Thread::LocalStorageKey thread_id_key_; |
| static Isolate* default_isolate_; |
| static ThreadDataTable* thread_data_table_; |
| - static ThreadId highest_thread_id_; |
| bool PreInit(); |
| @@ -1163,6 +1193,7 @@ class Isolate { |
| friend class ExecutionAccess; |
| friend class IsolateInitializer; |
| + friend class ThreadId; |
| friend class v8::Isolate; |
| friend class v8::Locker; |