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

Side by Side Diff: base/threading/thread_task_runner_handle.h

Issue 2042383004: Introduce TaskRunnerHandle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update comments Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_THREADING_THREAD_TASK_RUNNER_HANDLE_H_ 5 #ifndef BASE_THREADING_THREAD_TASK_RUNNER_HANDLE_H_
6 #define BASE_THREADING_THREAD_TASK_RUNNER_HANDLE_H_ 6 #define BASE_THREADING_THREAD_TASK_RUNNER_HANDLE_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/threading/task_runner_handle.h"
12 13
13 namespace base { 14 namespace base {
14 15
15 // ThreadTaskRunnerHandle stores a reference to a thread's TaskRunner 16 // Deprecated, see below for specifics.
16 // in thread-local storage. Callers can then retrieve the TaskRunner
17 // for the current thread by calling ThreadTaskRunnerHandle::Get().
18 // At most one TaskRunner may be bound to each thread at a time.
19 // Prefer SequenceTaskRunnerHandle to this unless thread affinity is required.
20 class BASE_EXPORT ThreadTaskRunnerHandle { 17 class BASE_EXPORT ThreadTaskRunnerHandle {
21 public: 18 public:
22 // Gets the SingleThreadTaskRunner for the current thread. 19 // Deprecated, use TaskRunnerHandle::Get.*() instead.
23 static scoped_refptr<SingleThreadTaskRunner> Get(); 20 // Note: There will not be an automated ThreadTaskRunnerHandle::Get() =>
21 // TaskRunnerHandle::GetSingleThreaded() change. ThreadTaskRunnerHandle::Get()
22 // callsites should instead be examined one-by-one and given the right
23 // semantics for their use case (i.e. don't use GetSingleThreaded() unless
24 // truly thread-affine).
25 static scoped_refptr<SingleThreadTaskRunner> Get() {
26 return TaskRunnerHandle::GetSingleThreaded();
27 }
24 28
25 // Returns true if the SingleThreadTaskRunner is already created for 29 // Deprecated, use TaskRunnerHandle::HasSingleThreadTaskScope() instead.
26 // the current thread. 30 static bool IsSet() { return TaskRunnerHandle::HasSingleThreadTaskScope(); }
27 static bool IsSet();
28 31
29 // Binds |task_runner| to the current thread. |task_runner| must belong 32 // Binds |task_runner| to the current thread. Deprecated, use
30 // to the current thread for this to succeed. 33 // TaskRunnerHandle::SingleThreadTaskScope instead.
31 explicit ThreadTaskRunnerHandle( 34 explicit ThreadTaskRunnerHandle(
32 scoped_refptr<SingleThreadTaskRunner> task_runner); 35 scoped_refptr<SingleThreadTaskRunner> task_runner);
33 ~ThreadTaskRunnerHandle(); 36 ~ThreadTaskRunnerHandle();
34 37
35 private: 38 private:
36 scoped_refptr<SingleThreadTaskRunner> task_runner_; 39 TaskRunnerHandle::SingleThreadTaskScope task_scope_;
37 40
38 DISALLOW_COPY_AND_ASSIGN(ThreadTaskRunnerHandle); 41 DISALLOW_COPY_AND_ASSIGN(ThreadTaskRunnerHandle);
39 }; 42 };
40 43
41 } // namespace base 44 } // namespace base
42 45
43 #endif // BASE_THREADING_THREAD_TASK_RUNNER_HANDLE_H_ 46 #endif // BASE_THREADING_THREAD_TASK_RUNNER_HANDLE_H_
OLDNEW
« no previous file with comments | « base/threading/task_runner_handle_unittest.cc ('k') | base/threading/thread_task_runner_handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698