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

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: tweak 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/threading/task_runner_handle.h"
11 12
12 namespace base { 13 namespace base {
13 14
14 class SingleThreadTaskRunner; 15 class SingleThreadTaskRunner;
15 16
16 // ThreadTaskRunnerHandle stores a reference to a thread's TaskRunner
17 // in thread-local storage. Callers can then retrieve the TaskRunner
18 // for the current thread by calling ThreadTaskRunnerHandle::Get().
19 // At most one TaskRunner may be bound to each thread at a time.
20 // Prefer SequenceTaskRunnerHandle to this unless thread affinity is required.
21 class BASE_EXPORT ThreadTaskRunnerHandle { 17 class BASE_EXPORT ThreadTaskRunnerHandle {
22 public: 18 public:
23 // Gets the SingleThreadTaskRunner for the current thread. 19 // Deprecated, use TaskRunnerHandle::Get.*() instead.
robliao 2016/06/09 15:40:18 Similar deprecated class banner here.
gab 2016/06/14 15:38:59 Done.
24 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 }
25 28
26 // Returns true if the SingleThreadTaskRunner is already created for 29 // Deprecated, use TaskRunnerHandle::HasSingleThreadTaskScope() instead.
27 // the current thread. 30 static bool IsSet() { return TaskRunnerHandle::HasSingleThreadTaskScope(); }
28 static bool IsSet();
29 31
30 // Binds |task_runner| to the current thread. |task_runner| must belong 32 // Binds |task_runner| to the current thread. Deprecated, use
31 // to the current thread for this to succeed. 33 // TaskRunnerHandle::SingleThreadTaskScope instead.
32 explicit ThreadTaskRunnerHandle( 34 explicit ThreadTaskRunnerHandle(
33 scoped_refptr<SingleThreadTaskRunner> task_runner); 35 scoped_refptr<SingleThreadTaskRunner> task_runner);
34 ~ThreadTaskRunnerHandle(); 36 ~ThreadTaskRunnerHandle();
35 37
36 private: 38 private:
37 scoped_refptr<SingleThreadTaskRunner> task_runner_; 39 TaskRunnerHandle::SingleThreadTaskScope task_scope_;
38 40
39 DISALLOW_COPY_AND_ASSIGN(ThreadTaskRunnerHandle); 41 DISALLOW_COPY_AND_ASSIGN(ThreadTaskRunnerHandle);
40 }; 42 };
41 43
42 } // namespace base 44 } // namespace base
43 45
44 #endif // BASE_THREADING_THREAD_TASK_RUNNER_HANDLE_H_ 46 #endif // BASE_THREADING_THREAD_TASK_RUNNER_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698