Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: base/threading/platform_thread.h

Issue 1207823004: PlatformThreadHandle: remove public id() interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: (upstream master for try) Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/threading/platform_thread_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 // Used to operate on threads. 67 // Used to operate on threads.
68 class PlatformThreadHandle { 68 class PlatformThreadHandle {
69 public: 69 public:
70 #if defined(OS_WIN) 70 #if defined(OS_WIN)
71 typedef void* Handle; 71 typedef void* Handle;
72 #elif defined(OS_POSIX) 72 #elif defined(OS_POSIX)
73 typedef pthread_t Handle; 73 typedef pthread_t Handle;
74 #endif 74 #endif
75 75
76 PlatformThreadHandle() 76 PlatformThreadHandle() : handle_(0) {}
77 : handle_(0),
78 id_(0) {
79 }
80 77
81 explicit PlatformThreadHandle(Handle handle) 78 explicit PlatformThreadHandle(Handle handle) : handle_(handle) {}
82 : handle_(handle),
83 id_(0) {
84 }
85
86 PlatformThreadHandle(Handle handle,
87 PlatformThreadId id)
88 : handle_(handle),
89 id_(id) {
90 }
91
92 PlatformThreadId id() const {
93 return id_;
94 }
95 79
96 bool is_equal(const PlatformThreadHandle& other) const { 80 bool is_equal(const PlatformThreadHandle& other) const {
97 return handle_ == other.handle_; 81 return handle_ == other.handle_;
98 } 82 }
99 83
100 bool is_null() const { 84 bool is_null() const {
101 return !handle_; 85 return !handle_;
102 } 86 }
103 87
104 Handle platform_handle() const { 88 Handle platform_handle() const {
105 return handle_; 89 return handle_;
106 } 90 }
107 91
108 private: 92 private:
109 Handle handle_; 93 Handle handle_;
110 PlatformThreadId id_;
111 }; 94 };
112 95
113 const PlatformThreadId kInvalidThreadId(0); 96 const PlatformThreadId kInvalidThreadId(0);
114 97
115 // Valid values for SetThreadPriority(), listed in increasing order of 98 // Valid values for priority of Thread::Options and SimpleThread::Options, and
116 // importance. 99 // SetCurrentThreadPriority(), listed in increasing order of importance.
117 enum class ThreadPriority { 100 enum class ThreadPriority {
118 // Suitable for threads that shouldn't disrupt high priority work. 101 // Suitable for threads that shouldn't disrupt high priority work.
119 BACKGROUND, 102 BACKGROUND,
120 // Default priority level. 103 // Default priority level.
121 NORMAL, 104 NORMAL,
122 // Suitable for threads which generate data for the display (at ~60Hz). 105 // Suitable for threads which generate data for the display (at ~60Hz).
123 DISPLAY, 106 DISPLAY,
124 // Suitable for low-latency, glitch-resistant audio. 107 // Suitable for low-latency, glitch-resistant audio.
125 REALTIME_AUDIO, 108 REALTIME_AUDIO,
126 }; 109 };
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // |*thread_handle| will be assigned a handle to the newly created thread, 152 // |*thread_handle| will be assigned a handle to the newly created thread,
170 // and |delegate|'s ThreadMain method will be executed on the newly created 153 // and |delegate|'s ThreadMain method will be executed on the newly created
171 // thread. 154 // thread.
172 // NOTE: When you are done with the thread handle, you must call Join to 155 // NOTE: When you are done with the thread handle, you must call Join to
173 // release system resources associated with the thread. You must ensure that 156 // release system resources associated with the thread. You must ensure that
174 // the Delegate object outlives the thread. 157 // the Delegate object outlives the thread.
175 static bool Create(size_t stack_size, Delegate* delegate, 158 static bool Create(size_t stack_size, Delegate* delegate,
176 PlatformThreadHandle* thread_handle); 159 PlatformThreadHandle* thread_handle);
177 160
178 // CreateWithPriority() does the same thing as Create() except the priority of 161 // CreateWithPriority() does the same thing as Create() except the priority of
179 // the thread is set based on |priority|. Can be used in place of Create() 162 // the thread is set based on |priority|.
180 // followed by SetThreadPriority().
181 static bool CreateWithPriority(size_t stack_size, Delegate* delegate, 163 static bool CreateWithPriority(size_t stack_size, Delegate* delegate,
182 PlatformThreadHandle* thread_handle, 164 PlatformThreadHandle* thread_handle,
183 ThreadPriority priority); 165 ThreadPriority priority);
184 166
185 // CreateNonJoinable() does the same thing as Create() except the thread 167 // CreateNonJoinable() does the same thing as Create() except the thread
186 // cannot be Join()'d. Therefore, it also does not output a 168 // cannot be Join()'d. Therefore, it also does not output a
187 // PlatformThreadHandle. 169 // PlatformThreadHandle.
188 static bool CreateNonJoinable(size_t stack_size, Delegate* delegate); 170 static bool CreateNonJoinable(size_t stack_size, Delegate* delegate);
189 171
190 // Joins with a thread created via the Create function. This function blocks 172 // Joins with a thread created via the Create function. This function blocks
191 // the caller until the designated thread exits. This will invalidate 173 // the caller until the designated thread exits. This will invalidate
192 // |thread_handle|. 174 // |thread_handle|.
193 static void Join(PlatformThreadHandle thread_handle); 175 static void Join(PlatformThreadHandle thread_handle);
194 176
195 // Toggles the target thread's priority at runtime. Prefer 177 // Toggles the current thread's priority at runtime. A thread may not be able
196 // CreateWithPriority() to set the thread's initial priority. 178 // to raise its priority back up after lowering it if the process does not
197 // NOTE: The call may fail if the caller thread is not the same as the 179 // have a proper permission, e.g. CAP_SYS_NICE on Linux.
198 // target thread on POSIX. For example, seccomp-bpf blocks it by default 180 // Since changing other threads' priority is not permitted in favor of
199 // in the sandbox. 181 // security, this interface is restricted to change only the current thread
200 static void SetThreadPriority(PlatformThreadHandle handle, 182 // priority (https://crbug.com/399473).
201 ThreadPriority priority); 183 static void SetCurrentThreadPriority(ThreadPriority priority);
gab 2015/07/08 18:35:20 I'm confused, why has the change from SetThreadPri
Takashi Toyoshima 2015/07/09 03:39:22 This patch set 5 contains the CL for SetCurrentThr
202 184
203 static ThreadPriority GetThreadPriority(PlatformThreadHandle handle); 185 static ThreadPriority GetCurrentThreadPriority();
204 186
205 private: 187 private:
206 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); 188 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread);
207 }; 189 };
208 190
209 } // namespace base 191 } // namespace base
210 192
211 #endif // BASE_THREADING_PLATFORM_THREAD_H_ 193 #endif // BASE_THREADING_PLATFORM_THREAD_H_
OLDNEW
« no previous file with comments | « no previous file | base/threading/platform_thread_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698