summaryrefslogtreecommitdiff
path: root/base/threading/platform_thread.h
diff options
context:
space:
mode:
Diffstat (limited to 'base/threading/platform_thread.h')
-rw-r--r--base/threading/platform_thread.h56
1 files changed, 22 insertions, 34 deletions
diff --git a/base/threading/platform_thread.h b/base/threading/platform_thread.h
index 3468f45f91..e2b09bcb5b 100644
--- a/base/threading/platform_thread.h
+++ b/base/threading/platform_thread.h
@@ -9,8 +9,10 @@
#ifndef BASE_THREADING_PLATFORM_THREAD_H_
#define BASE_THREADING_PLATFORM_THREAD_H_
+#include <stddef.h>
+
#include "base/base_export.h"
-#include "base/basictypes.h"
+#include "base/macros.h"
#include "base/time/time.h"
#include "build/build_config.h"
@@ -73,25 +75,9 @@ class PlatformThreadHandle {
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) {
- }
+ PlatformThreadHandle() : handle_(0) {}
- PlatformThreadId id() const {
- return id_;
- }
+ explicit PlatformThreadHandle(Handle handle) : handle_(handle) {}
bool is_equal(const PlatformThreadHandle& other) const {
return handle_ == other.handle_;
@@ -107,13 +93,12 @@ class PlatformThreadHandle {
private:
Handle handle_;
- PlatformThreadId id_;
};
const PlatformThreadId kInvalidThreadId(0);
-// Valid values for SetThreadPriority(), listed in increasing order of
-// importance.
+// Valid values for priority of Thread::Options and SimpleThread::Options, and
+// SetCurrentThreadPriority(), listed in increasing order of importance.
enum class ThreadPriority {
// Suitable for threads that shouldn't disrupt high priority work.
BACKGROUND,
@@ -172,12 +157,15 @@ class BASE_EXPORT PlatformThread {
// NOTE: When you are done with the thread handle, you must call Join to
// release system resources associated with the thread. You must ensure that
// the Delegate object outlives the thread.
- static bool Create(size_t stack_size, Delegate* delegate,
- PlatformThreadHandle* thread_handle);
+ static bool Create(size_t stack_size,
+ Delegate* delegate,
+ PlatformThreadHandle* thread_handle) {
+ return CreateWithPriority(stack_size, delegate, thread_handle,
+ ThreadPriority::NORMAL);
+ }
// CreateWithPriority() does the same thing as Create() except the priority of
- // the thread is set based on |priority|. Can be used in place of Create()
- // followed by SetThreadPriority().
+ // the thread is set based on |priority|.
static bool CreateWithPriority(size_t stack_size, Delegate* delegate,
PlatformThreadHandle* thread_handle,
ThreadPriority priority);
@@ -192,15 +180,15 @@ class BASE_EXPORT PlatformThread {
// |thread_handle|.
static void Join(PlatformThreadHandle thread_handle);
- // Toggles the target thread's priority at runtime. Prefer
- // CreateWithPriority() to set the thread's initial priority.
- // NOTE: The call may fail if the caller thread is not the same as the
- // target thread on POSIX. For example, seccomp-bpf blocks it by default
- // in the sandbox.
- static void SetThreadPriority(PlatformThreadHandle handle,
- ThreadPriority priority);
+ // Toggles the current thread's priority at runtime. A thread may not be able
+ // to raise its priority back up after lowering it if the process does not
+ // have a proper permission, e.g. CAP_SYS_NICE on Linux.
+ // Since changing other threads' priority is not permitted in favor of
+ // security, this interface is restricted to change only the current thread
+ // priority (https://crbug.com/399473).
+ static void SetCurrentThreadPriority(ThreadPriority priority);
- static ThreadPriority GetThreadPriority(PlatformThreadHandle handle);
+ static ThreadPriority GetCurrentThreadPriority();
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread);