| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 // WARNING: You should *NOT* be using this class directly. PlatformThread is | 5 // WARNING: You should *NOT* be using this class directly. PlatformThread is |
| 6 // the low-level platform-specific abstraction to the OS's threading interface. | 6 // the low-level platform-specific abstraction to the OS's threading interface. |
| 7 // You should instead be using a message-loop driven Thread, see thread.h. | 7 // You should instead be using a message-loop driven Thread, see thread.h. |
| 8 | 8 |
| 9 #ifndef BASE_THREADING_PLATFORM_THREAD_H_ | 9 #ifndef BASE_THREADING_PLATFORM_THREAD_H_ |
| 10 #define BASE_THREADING_PLATFORM_THREAD_H_ | 10 #define BASE_THREADING_PLATFORM_THREAD_H_ |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 : handle_(handle), | 82 : handle_(handle), |
| 83 id_(0) { | 83 id_(0) { |
| 84 } | 84 } |
| 85 | 85 |
| 86 PlatformThreadHandle(Handle handle, | 86 PlatformThreadHandle(Handle handle, |
| 87 PlatformThreadId id) | 87 PlatformThreadId id) |
| 88 : handle_(handle), | 88 : handle_(handle), |
| 89 id_(id) { | 89 id_(id) { |
| 90 } | 90 } |
| 91 | 91 |
| 92 PlatformThreadId id() const { |
| 93 return id_; |
| 94 } |
| 95 |
| 92 bool is_equal(const PlatformThreadHandle& other) const { | 96 bool is_equal(const PlatformThreadHandle& other) const { |
| 93 return handle_ == other.handle_; | 97 return handle_ == other.handle_; |
| 94 } | 98 } |
| 95 | 99 |
| 96 bool is_null() const { | 100 bool is_null() const { |
| 97 return !handle_; | 101 return !handle_; |
| 98 } | 102 } |
| 99 | 103 |
| 100 Handle platform_handle() const { | 104 Handle platform_handle() const { |
| 101 return handle_; | 105 return handle_; |
| 102 } | 106 } |
| 103 | 107 |
| 104 private: | 108 private: |
| 105 friend class PlatformThread; | |
| 106 | |
| 107 Handle handle_; | 109 Handle handle_; |
| 108 PlatformThreadId id_; | 110 PlatformThreadId id_; |
| 109 }; | 111 }; |
| 110 | 112 |
| 111 const PlatformThreadId kInvalidThreadId(0); | 113 const PlatformThreadId kInvalidThreadId(0); |
| 112 | 114 |
| 113 // Valid values for SetThreadPriority(), listed in increasing order of | 115 // Valid values for SetThreadPriority(), listed in increasing order of |
| 114 // importance. | 116 // importance. |
| 115 enum class ThreadPriority { | 117 enum class ThreadPriority { |
| 116 // Suitable for threads that shouldn't disrupt high priority work. | 118 // Suitable for threads that shouldn't disrupt high priority work. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 // CreateNonJoinable() does the same thing as Create() except the thread | 185 // CreateNonJoinable() does the same thing as Create() except the thread |
| 184 // cannot be Join()'d. Therefore, it also does not output a | 186 // cannot be Join()'d. Therefore, it also does not output a |
| 185 // PlatformThreadHandle. | 187 // PlatformThreadHandle. |
| 186 static bool CreateNonJoinable(size_t stack_size, Delegate* delegate); | 188 static bool CreateNonJoinable(size_t stack_size, Delegate* delegate); |
| 187 | 189 |
| 188 // Joins with a thread created via the Create function. This function blocks | 190 // Joins with a thread created via the Create function. This function blocks |
| 189 // the caller until the designated thread exits. This will invalidate | 191 // the caller until the designated thread exits. This will invalidate |
| 190 // |thread_handle|. | 192 // |thread_handle|. |
| 191 static void Join(PlatformThreadHandle thread_handle); | 193 static void Join(PlatformThreadHandle thread_handle); |
| 192 | 194 |
| 195 // Toggles the target thread's priority at runtime. Prefer |
| 196 // CreateWithPriority() to set the thread's initial priority. |
| 197 // NOTE: The call may fail if the caller thread is not the same as the |
| 198 // target thread on POSIX. For example, seccomp-bpf blocks it by default |
| 199 // in the sandbox. |
| 193 static void SetThreadPriority(PlatformThreadHandle handle, | 200 static void SetThreadPriority(PlatformThreadHandle handle, |
| 194 ThreadPriority priority); | 201 ThreadPriority priority); |
| 195 | 202 |
| 196 static ThreadPriority GetThreadPriority(PlatformThreadHandle handle); | 203 static ThreadPriority GetThreadPriority(PlatformThreadHandle handle); |
| 197 | 204 |
| 198 private: | 205 private: |
| 199 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); | 206 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); |
| 200 }; | 207 }; |
| 201 | 208 |
| 202 } // namespace base | 209 } // namespace base |
| 203 | 210 |
| 204 #endif // BASE_THREADING_PLATFORM_THREAD_H_ | 211 #endif // BASE_THREADING_PLATFORM_THREAD_H_ |
| OLD | NEW |