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

Unified Diff: base/threading/platform_thread.h

Issue 12741012: base: Support setting thread priorities generically. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: base/threading/platform_thread.h
diff --git a/base/threading/platform_thread.h b/base/threading/platform_thread.h
index 576695a4e7b5f8028f47cc5e02921b551ffb0a39..88ea0d18bdb09d1ef8e7e8b13b9daf3d8c89e564 100644
--- a/base/threading/platform_thread.h
+++ b/base/threading/platform_thread.h
@@ -23,27 +23,69 @@
namespace base {
-// PlatformThreadHandle should not be assumed to be a numeric type, since the
-// standard intends to allow pthread_t to be a structure. This means you
-// should not initialize it to a value, like 0. If it's a member variable, the
-// constructor can safely "value initialize" using () in the initializer list.
#if defined(OS_WIN)
typedef DWORD PlatformThreadId;
-typedef void* PlatformThreadHandle; // HANDLE
-const PlatformThreadHandle kNullThreadHandle = NULL;
#elif defined(OS_POSIX)
-typedef pthread_t PlatformThreadHandle;
-const PlatformThreadHandle kNullThreadHandle = 0;
typedef pid_t PlatformThreadId;
#endif
+class PlatformThreadHandle {
+ public:
+#if defined(OS_WIN)
+ typedef void* Handle;
+#elif defined(OS_POSIX)
+ typedef pthread_t Handle;
+#endif
+
+ PlatformThreadHandle()
+ : handle_(0),
jar (doing other things) 2013/05/17 22:51:48 nit: colon should be indented by 4 (same on lines
epenner 2013/05/17 23:46:35 Done.
+ id_(0) {
+ }
+
+ explicit PlatformThreadHandle(Handle handle)
+ : handle_(handle),
+ id_(0) {
+ }
+
+ PlatformThreadHandle(Handle handle,
+ PlatformThreadId id)
+ : handle_(handle),
+ id_(id) {
+ }
+
+ bool equals(const PlatformThreadHandle& other) {
jar (doing other things) 2013/05/17 22:51:48 nit: probably better is is_equal or IsEqual
epenner 2013/05/17 23:46:35 Done.
+ return handle_ == other.handle_;
+ }
+
+ bool isNull() {
jar (doing other things) 2013/05/17 22:51:48 nit: bouncy caps, or hacker style... but this was
epenner 2013/05/17 23:46:35 Done.
+ return !handle_;
+ }
+
+ Handle platform_handle() {
+ return handle_;
+ }
+
+ public:
jar (doing other things) 2013/05/17 22:51:48 typo: private
epenner 2013/05/17 23:46:35 Thanks! I must have switched it back temporarily a
+ friend class PlatformThread;
+ friend void* ThreadFunc(void* params);
+
+ Handle handle_;
+ PlatformThreadId id_;
+};
+
+const PlatformThreadHandle kNullThreadHandle(0);
const PlatformThreadId kInvalidThreadId = 0;
jar (doing other things) 2013/05/17 22:51:48 nit: probably should use the same initializer styl
epenner 2013/05/17 23:46:35 Done.
+
// Valid values for SetThreadPriority()
enum ThreadPriority{
kThreadPriority_Normal,
// Suitable for low-latency, glitch-resistant audio.
- kThreadPriority_RealtimeAudio
+ kThreadPriority_RealtimeAudio,
+ // Suitable for threads which generate data for the display (at ~60Hz).
+ kThreadPriority_Display,
+ // Suitable for threads that shouldn't disrupt high priority work.
+ kThreadPriority_Background
};
// A namespace for low-level thread functions.
@@ -62,6 +104,9 @@ class BASE_EXPORT PlatformThread {
// Gets the current thread id, which may be useful for logging purposes.
static PlatformThreadId CurrentId();
+ // Get the current handle.
+ static PlatformThreadHandle CurrentHandle();
+
// Yield the current thread so another thread can be scheduled.
static void YieldCurrentThread();
@@ -106,8 +151,6 @@ class BASE_EXPORT PlatformThread {
// |thread_handle|.
static void Join(PlatformThreadHandle thread_handle);
- // Sets the priority of the thread specified in |handle| to |priority|.
- // This does not work on Linux, use CreateWithPriority() instead.
static void SetThreadPriority(PlatformThreadHandle handle,
ThreadPriority priority);

Powered by Google App Engine
This is Rietveld 408576698