| 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 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 90 void Lock(); | 90 void Lock(); |
| 91 void Unlock(); | 91 void Unlock(); |
| 92 | 92 |
| 93 void ArchiveThread(); | 93 void ArchiveThread(); |
| 94 bool RestoreThread(); | 94 bool RestoreThread(); |
| 95 void FreeThreadResources(); | 95 void FreeThreadResources(); |
| 96 bool IsArchived(); | 96 bool IsArchived(); |
| 97 | 97 |
| 98 void Iterate(ObjectVisitor* v); | 98 void Iterate(ObjectVisitor* v); |
| 99 void IterateArchivedThreads(ThreadVisitor* v); | 99 void IterateArchivedThreads(ThreadVisitor* v); |
| 100 bool IsLockedByCurrentThread() { return mutex_owner_.IsSelf(); } | 100 bool IsLockedByCurrentThread() { |
| 101 return mutex_owner_.Equals(ThreadId::Current()); |
| 102 } |
| 101 | 103 |
| 102 int CurrentId(); | 104 ThreadId CurrentId(); |
| 103 | 105 |
| 104 void TerminateExecution(int thread_id); | 106 void TerminateExecution(ThreadId thread_id); |
| 105 | 107 |
| 106 // Iterate over in-use states. | 108 // Iterate over in-use states. |
| 107 ThreadState* FirstThreadStateInUse(); | 109 ThreadState* FirstThreadStateInUse(); |
| 108 ThreadState* GetFreeThreadState(); | 110 ThreadState* GetFreeThreadState(); |
| 109 | 111 |
| 110 static const int kInvalidId = -1; | |
| 111 private: | 112 private: |
| 112 ThreadManager(); | 113 ThreadManager(); |
| 113 ~ThreadManager(); | 114 ~ThreadManager(); |
| 114 | 115 |
| 115 void EagerlyArchiveThread(); | 116 void EagerlyArchiveThread(); |
| 116 | 117 |
| 117 Mutex* mutex_; | 118 Mutex* mutex_; |
| 118 ThreadHandle mutex_owner_; | 119 ThreadId mutex_owner_; |
| 119 ThreadHandle lazily_archived_thread_; | 120 ThreadId lazily_archived_thread_; |
| 120 ThreadState* lazily_archived_thread_state_; | 121 ThreadState* lazily_archived_thread_state_; |
| 121 | 122 |
| 122 // In the following two lists there is always at least one object on the list. | 123 // 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 | 124 // The first object is a flying anchor that is only there to simplify linking |
| 124 // and unlinking. | 125 // and unlinking. |
| 125 // Head of linked list of free states. | 126 // Head of linked list of free states. |
| 126 ThreadState* free_anchor_; | 127 ThreadState* free_anchor_; |
| 127 // Head of linked list of states in use. | 128 // Head of linked list of states in use. |
| 128 ThreadState* in_use_anchor_; | 129 ThreadState* in_use_anchor_; |
| 129 | 130 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 155 | 156 |
| 156 void Run(); | 157 void Run(); |
| 157 | 158 |
| 158 bool keep_going_; | 159 bool keep_going_; |
| 159 int sleep_ms_; | 160 int sleep_ms_; |
| 160 }; | 161 }; |
| 161 | 162 |
| 162 } } // namespace v8::internal | 163 } } // namespace v8::internal |
| 163 | 164 |
| 164 #endif // V8_V8THREADS_H_ | 165 #endif // V8_V8THREADS_H_ |
| OLD | NEW |