Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 25 matching lines...) Expand all Loading... | |
| 36 public: | 36 public: |
| 37 // Returns NULL after the last one. | 37 // Returns NULL after the last one. |
| 38 ThreadState* Next(); | 38 ThreadState* Next(); |
| 39 | 39 |
| 40 enum List {FREE_LIST, IN_USE_LIST}; | 40 enum List {FREE_LIST, IN_USE_LIST}; |
| 41 | 41 |
| 42 void LinkInto(List list); | 42 void LinkInto(List list); |
| 43 void Unlink(); | 43 void Unlink(); |
| 44 | 44 |
| 45 // Id of thread. | 45 // Id of thread. |
| 46 void set_id(int id) { id_ = id; } | 46 void set_id(ThreadId id) { id_ = id; } |
| 47 int id() { return id_; } | 47 ThreadId id() { return id_; } |
| 48 | 48 |
| 49 // Should the thread be terminated when it is restored? | 49 // Should the thread be terminated when it is restored? |
| 50 bool terminate_on_restore() { return terminate_on_restore_; } | 50 bool terminate_on_restore() { return terminate_on_restore_; } |
| 51 void set_terminate_on_restore(bool terminate_on_restore) { | 51 void set_terminate_on_restore(bool terminate_on_restore) { |
| 52 terminate_on_restore_ = terminate_on_restore; | 52 terminate_on_restore_ = terminate_on_restore; |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Get data area for archiving a thread. | 55 // Get data area for archiving a thread. |
| 56 char* data() { return data_; } | 56 char* data() { return data_; } |
| 57 private: | 57 private: |
| 58 explicit ThreadState(ThreadManager* thread_manager); | 58 explicit ThreadState(ThreadManager* thread_manager); |
| 59 | 59 |
| 60 void AllocateSpace(); | 60 void AllocateSpace(); |
| 61 | 61 |
| 62 int id_; | 62 ThreadId id_; |
| 63 bool terminate_on_restore_; | 63 bool terminate_on_restore_; |
| 64 char* data_; | 64 char* data_; |
| 65 ThreadState* next_; | 65 ThreadState* next_; |
| 66 ThreadState* previous_; | 66 ThreadState* previous_; |
| 67 | 67 |
| 68 ThreadManager* thread_manager_; | 68 ThreadManager* thread_manager_; |
| 69 | 69 |
| 70 friend class ThreadManager; | 70 friend class ThreadManager; |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 | 73 |
| 74 // Defined in top.h | 74 // Defined in top.h |
| 75 class ThreadLocalTop; | 75 class ThreadLocalTop; |
| 76 | 76 |
| 77 | 77 |
| 78 class ThreadVisitor { | 78 class ThreadVisitor { |
| 79 public: | 79 public: |
| 80 // ThreadLocalTop may be only available during this call. | 80 // ThreadLocalTop may be only available during this call. |
| 81 virtual void VisitThread(Isolate* isolate, ThreadLocalTop* top) = 0; | 81 virtual void VisitThread(Isolate* isolate, ThreadLocalTop* top) = 0; |
| 82 | 82 |
| 83 protected: | 83 protected: |
| 84 virtual ~ThreadVisitor() {} | 84 virtual ~ThreadVisitor() {} |
| 85 }; | 85 }; |
| 86 | 86 |
|
Vitaly Repeshko
2011/04/11 19:28:52
Only two-blank lines are needed here.
| |
| 87 | 87 |
| 88 | |
| 88 class ThreadManager { | 89 class ThreadManager { |
| 89 public: | 90 public: |
| 90 void Lock(); | 91 void Lock(); |
| 91 void Unlock(); | 92 void Unlock(); |
| 92 | 93 |
| 93 void ArchiveThread(); | 94 void ArchiveThread(); |
| 94 bool RestoreThread(); | 95 bool RestoreThread(); |
| 95 void FreeThreadResources(); | 96 void FreeThreadResources(); |
| 96 bool IsArchived(); | 97 bool IsArchived(); |
| 97 | 98 |
| 98 void Iterate(ObjectVisitor* v); | 99 void Iterate(ObjectVisitor* v); |
| 99 void IterateArchivedThreads(ThreadVisitor* v); | 100 void IterateArchivedThreads(ThreadVisitor* v); |
| 100 bool IsLockedByCurrentThread() { return mutex_owner_.IsSelf(); } | 101 bool IsLockedByCurrentThread() { |
| 102 return mutex_owner_.Equals(ThreadId::Current()); | |
| 103 } | |
| 101 | 104 |
| 102 int CurrentId(); | 105 ThreadId CurrentId(); |
| 103 | 106 |
| 104 void TerminateExecution(int thread_id); | 107 void TerminateExecution(ThreadId thread_id); |
| 105 | 108 |
| 106 // Iterate over in-use states. | 109 // Iterate over in-use states. |
| 107 ThreadState* FirstThreadStateInUse(); | 110 ThreadState* FirstThreadStateInUse(); |
| 108 ThreadState* GetFreeThreadState(); | 111 ThreadState* GetFreeThreadState(); |
| 109 | 112 |
| 110 static const int kInvalidId = -1; | |
| 111 private: | 113 private: |
| 112 ThreadManager(); | 114 ThreadManager(); |
| 113 ~ThreadManager(); | 115 ~ThreadManager(); |
| 114 | 116 |
| 115 void EagerlyArchiveThread(); | 117 void EagerlyArchiveThread(); |
| 116 | 118 |
| 117 Mutex* mutex_; | 119 Mutex* mutex_; |
| 118 ThreadHandle mutex_owner_; | 120 ThreadId mutex_owner_; |
| 119 ThreadHandle lazily_archived_thread_; | 121 ThreadId lazily_archived_thread_; |
| 120 ThreadState* lazily_archived_thread_state_; | 122 ThreadState* lazily_archived_thread_state_; |
| 121 | 123 |
| 122 // In the following two lists there is always at least one object on the list. | 124 // In the following two lists there is always at least one object on the list. |
| 123 // The first object is a flying anchor that is only there to simplify linking | 125 // The first object is a flying anchor that is only there to simplify linking |
| 124 // and unlinking. | 126 // and unlinking. |
| 125 // Head of linked list of free states. | 127 // Head of linked list of free states. |
| 126 ThreadState* free_anchor_; | 128 ThreadState* free_anchor_; |
| 127 // Head of linked list of states in use. | 129 // Head of linked list of states in use. |
| 128 ThreadState* in_use_anchor_; | 130 ThreadState* in_use_anchor_; |
| 129 | 131 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 155 | 157 |
| 156 void Run(); | 158 void Run(); |
| 157 | 159 |
| 158 bool keep_going_; | 160 bool keep_going_; |
| 159 int sleep_ms_; | 161 int sleep_ms_; |
| 160 }; | 162 }; |
| 161 | 163 |
| 162 } } // namespace v8::internal | 164 } } // namespace v8::internal |
| 163 | 165 |
| 164 #endif // V8_V8THREADS_H_ | 166 #endif // V8_V8THREADS_H_ |
| OLD | NEW |