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

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: Remove static initializers. 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
« no previous file with comments | « base/synchronization/lock_unittest.cc ('k') | base/threading/platform_thread_android.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/platform_thread.h
diff --git a/base/threading/platform_thread.h b/base/threading/platform_thread.h
index 576695a4e7b5f8028f47cc5e02921b551ffb0a39..c5975000016cd54d573549f3ef36bc4255c29c8b 100644
--- a/base/threading/platform_thread.h
+++ b/base/threading/platform_thread.h
@@ -23,27 +23,66 @@
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
-const PlatformThreadId kInvalidThreadId = 0;
+class PlatformThreadHandle {
+ public:
+#if defined(OS_WIN)
+ typedef void* Handle;
+#elif defined(OS_POSIX)
+ typedef pthread_t Handle;
+#endif
+
+ PlatformThreadHandle()
+ : handle_(0),
+ id_(0) {
+ }
+
+ explicit PlatformThreadHandle(Handle handle)
+ : handle_(handle),
+ id_(0) {
+ }
+
+ PlatformThreadHandle(Handle handle,
+ PlatformThreadId id)
+ : handle_(handle),
+ id_(id) {
+ }
+
+ bool is_equal(const PlatformThreadHandle& other) {
+ return handle_ == other.handle_;
+ }
+
+ bool is_null() {
+ return !handle_;
+ }
+
+ Handle platform_handle() {
+ return handle_;
+ }
+
+ private:
+ friend class PlatformThread;
+
+ Handle handle_;
+ PlatformThreadId id_;
+};
+
+const PlatformThreadId kInvalidThreadId(0);
// 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 +101,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 +148,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);
« no previous file with comments | « base/synchronization/lock_unittest.cc ('k') | base/threading/platform_thread_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698