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

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: Add id to handle. 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..c021f1a834c86758c271e1cfdb2b2747ae17521f 100644
--- a/base/threading/platform_thread.h
+++ b/base/threading/platform_thread.h
@@ -19,6 +19,7 @@
#elif defined(OS_POSIX)
#include <pthread.h>
#include <unistd.h>
+#include <ostream>
jar (doing other things) 2013/05/15 02:18:36 nit: probably alphabetize by placing before line 2
epennerAtGoogle 2013/05/15 05:09:08 Done. I actually removed this.
epenner 2013/05/17 19:18:13 I went ahead and removed this.
#endif
namespace base {
@@ -32,9 +33,48 @@ 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;
+struct PlatformThreadHandle {
jar (doing other things) 2013/05/15 02:18:36 nit: this should probably be a class. You'll prob
epennerAtGoogle 2013/05/15 05:09:08 I made it a class to protect members, but default
epenner 2013/05/17 19:18:13 I made it into a class to protect private members,
+ PlatformThreadHandle()
+ : handle(),
+ id(0) {
+ }
+
+ PlatformThreadHandle(pthread_t handle)
jar (doing other things) 2013/05/15 02:18:36 nit: explicit.
epennerAtGoogle 2013/05/15 05:09:08 Done.
epenner 2013/05/17 19:18:13 Done.
+ : handle(handle),
+ id(0) {
+ }
+
+ PlatformThreadHandle(pthread_t handle,
+ PlatformThreadId id)
+ : handle(handle),
+ id(id) {
+ }
+
+ operator bool() const {
+ return !!handle;
+ }
+
+ bool operator!() {
jar (doing other things) 2013/05/15 02:18:36 Instead of operator overload, use method names, li
epennerAtGoogle 2013/05/15 05:09:08 I couldn't do this because the handle on windows w
+ return !handle;
+ }
+
+ bool operator==(const PlatformThreadHandle& other) {
jar (doing other things) 2013/05/15 02:18:36 nit: again, just define a method name.
epennerAtGoogle 2013/05/15 05:09:08 Done.
+ return handle == other.handle;
+ }
+
+ bool operator!=(const PlatformThreadHandle& other) {
+ return handle != other.handle;
+ }
+
+ pthread_t handle;
+ PlatformThreadId id;
+};
+
+const PlatformThreadHandle kNullThreadHandle(0);
+std::ostream& operator<< (std::ostream &out,
jar (doing other things) 2013/05/15 02:18:36 This is pretty uncommon, as use of streams is not
epennerAtGoogle 2013/05/15 05:09:08 Yes, I'm trying to remove it by changing a few cal
+ const PlatformThreadHandle& handle);
+
#endif
const PlatformThreadId kInvalidThreadId = 0;
@@ -43,7 +83,11 @@ const PlatformThreadId kInvalidThreadId = 0;
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 +106,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 +153,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