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 25 matching lines...) Expand all Loading... |
36 const PlatformThreadHandle kNullThreadHandle = 0; | 36 const PlatformThreadHandle kNullThreadHandle = 0; |
37 typedef pid_t PlatformThreadId; | 37 typedef pid_t PlatformThreadId; |
38 #endif | 38 #endif |
39 | 39 |
40 const PlatformThreadId kInvalidThreadId = 0; | 40 const PlatformThreadId kInvalidThreadId = 0; |
41 | 41 |
42 // Valid values for SetThreadPriority() | 42 // Valid values for SetThreadPriority() |
43 enum ThreadPriority{ | 43 enum ThreadPriority{ |
44 kThreadPriority_Normal, | 44 kThreadPriority_Normal, |
45 // Suitable for low-latency, glitch-resistant audio. | 45 // Suitable for low-latency, glitch-resistant audio. |
46 kThreadPriority_RealtimeAudio | 46 kThreadPriority_RealtimeAudio, |
| 47 // Suitable for threads which generate data for the display (at ~60Hz). |
| 48 kThreadPriority_Display, |
| 49 // Suitable for threads that shouldn't disrupt high priority work. |
| 50 kThreadPriority_Background |
47 }; | 51 }; |
48 | 52 |
49 // A namespace for low-level thread functions. | 53 // A namespace for low-level thread functions. |
50 class BASE_EXPORT PlatformThread { | 54 class BASE_EXPORT PlatformThread { |
51 public: | 55 public: |
52 // Implement this interface to run code on a background thread. Your | 56 // Implement this interface to run code on a background thread. Your |
53 // ThreadMain method will be called on the newly created thread. | 57 // ThreadMain method will be called on the newly created thread. |
54 class BASE_EXPORT Delegate { | 58 class BASE_EXPORT Delegate { |
55 public: | 59 public: |
56 virtual void ThreadMain() = 0; | 60 virtual void ThreadMain() = 0; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // CreateNonJoinable() does the same thing as Create() except the thread | 103 // CreateNonJoinable() does the same thing as Create() except the thread |
100 // cannot be Join()'d. Therefore, it also does not output a | 104 // cannot be Join()'d. Therefore, it also does not output a |
101 // PlatformThreadHandle. | 105 // PlatformThreadHandle. |
102 static bool CreateNonJoinable(size_t stack_size, Delegate* delegate); | 106 static bool CreateNonJoinable(size_t stack_size, Delegate* delegate); |
103 | 107 |
104 // Joins with a thread created via the Create function. This function blocks | 108 // Joins with a thread created via the Create function. This function blocks |
105 // the caller until the designated thread exits. This will invalidate | 109 // the caller until the designated thread exits. This will invalidate |
106 // |thread_handle|. | 110 // |thread_handle|. |
107 static void Join(PlatformThreadHandle thread_handle); | 111 static void Join(PlatformThreadHandle thread_handle); |
108 | 112 |
109 // Sets the priority of the thread specified in |handle| to |priority|. | 113 // Only one of the handle/id is required depending on the |
110 // This does not work on Linux, use CreateWithPriority() instead. | 114 // platform. However, for cross platform code, pass both. |
111 static void SetThreadPriority(PlatformThreadHandle handle, | 115 static void SetThreadPriority(PlatformThreadHandle handle, |
| 116 PlatformThreadId id, |
112 ThreadPriority priority); | 117 ThreadPriority priority); |
113 | 118 |
114 private: | 119 private: |
115 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); | 120 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); |
116 }; | 121 }; |
117 | 122 |
118 } // namespace base | 123 } // namespace base |
119 | 124 |
120 #endif // BASE_THREADING_PLATFORM_THREAD_H_ | 125 #endif // BASE_THREADING_PLATFORM_THREAD_H_ |
OLD | NEW |