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

Side by Side Diff: base/threading/sequenced_task_runner_handle.cc

Issue 1414793009: Allow SequencedTaskRunnerHandle::Get() while running unsequenced tasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: x Created 5 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "base/threading/sequenced_task_runner_handle.h" 5 #include "base/threading/sequenced_task_runner_handle.h"
6 6
7 #include "base/sequenced_task_runner.h" 7 #include "base/sequenced_task_runner.h"
8 #include "base/thread_task_runner_handle.h" 8 #include "base/thread_task_runner_handle.h"
9 #include "base/threading/sequenced_worker_pool.h"
gab 2015/11/05 23:29:18 Still being used.
10 9
11 namespace base { 10 namespace base {
12 11
13 // static 12 // static
14 scoped_refptr<SequencedTaskRunner> SequencedTaskRunnerHandle::Get() { 13 scoped_refptr<SequencedTaskRunner> SequencedTaskRunnerHandle::Get() {
15 // If we are on a worker thread for a SequencedBlockingPool that is running a 14 scoped_refptr<base::SequencedTaskRunner> task_runner =
16 // sequenced task, return a SequencedTaskRunner for it. 15 SequencedWorkerPool::GetSequencedTaskRunnerForCurrentThread();
17 scoped_refptr<base::SequencedWorkerPool> pool = 16 if (task_runner)
18 SequencedWorkerPool::GetWorkerPoolForCurrentThread(); 17 return task_runner;
gab 2015/11/05 23:29:18 How about: // Return the SequencedTaskRunner if f
Bernhard Bauer 2015/11/10 17:12:06 Done, although I had to add an additional construc
gab 2015/11/10 19:54:18 Oh interesting, without this the implicit conversi
Bernhard Bauer 2015/11/10 20:31:47 Yes, I think the two alternatives in a conditional
19 if (pool) {
20 SequencedWorkerPool::SequenceToken sequence_token =
21 SequencedWorkerPool::GetSequenceTokenForCurrentThread();
22 DCHECK(sequence_token.IsValid());
23 DCHECK(pool->IsRunningSequenceOnCurrentThread(sequence_token));
24 return pool->GetSequencedTaskRunner(sequence_token);
25 }
26 18
27 // Otherwise, return a SingleThreadTaskRunner for the current thread. 19 // Otherwise, return a SingleThreadTaskRunner for the current thread.
28 return base::ThreadTaskRunnerHandle::Get(); 20 return base::ThreadTaskRunnerHandle::Get();
danakj 2015/11/05 18:52:08 I'm wondering if this is a good idea if we shouldn
gab 2015/11/05 23:29:18 Hmmm? SequencedTaskRunnerHandle::Get() here would
danakj 2015/11/05 23:31:15 Oh I meant, if this isn't a general "always use th
gab 2015/11/05 23:33:10 Oh I see. I don't think so. I think returning a S
29 } 21 }
30 22
31 // static 23 // static
32 bool SequencedTaskRunnerHandle::IsSet() { 24 bool SequencedTaskRunnerHandle::IsSet() {
33 return (SequencedWorkerPool::GetWorkerPoolForCurrentThread() && 25 return SequencedWorkerPool::GetSequencedTaskRunnerForCurrentThread() ||
34 SequencedWorkerPool::GetSequenceTokenForCurrentThread().IsValid()) ||
35 base::ThreadTaskRunnerHandle::IsSet(); 26 base::ThreadTaskRunnerHandle::IsSet();
36 } 27 }
37 28
38 } // namespace base 29 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698