Chromium Code Reviews| 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); |