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

Unified Diff: base/task_scheduler/scheduler_thread_pool_impl.h

Issue 1876363004: TaskScheduler [11] Support ExecutionMode::SINGLE_THREADED. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@8_delayed
Patch Set: rebase Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: base/task_scheduler/scheduler_thread_pool_impl.h
diff --git a/base/task_scheduler/scheduler_thread_pool_impl.h b/base/task_scheduler/scheduler_thread_pool_impl.h
index b764f2716495438564c0820760ac3cab39969d67..4eb265f7b83b75a442d0992a3bc054c3196e4a94 100644
--- a/base/task_scheduler/scheduler_thread_pool_impl.h
+++ b/base/task_scheduler/scheduler_thread_pool_impl.h
@@ -8,6 +8,7 @@
#include <stddef.h>
#include <memory>
+#include <unordered_map>
#include <vector>
#include "base/base_export.h"
@@ -72,16 +73,17 @@ class BASE_EXPORT SchedulerThreadPoolImpl : public SchedulerThreadPool {
void ReEnqueueSequence(scoped_refptr<Sequence> sequence,
const SequenceSortKey& sequence_sort_key) override;
bool PostTaskWithSequence(std::unique_ptr<Task> task,
- scoped_refptr<Sequence> sequence) override;
+ scoped_refptr<Sequence> sequence,
+ SchedulerWorkerThread* worker_thread) override;
void PostTaskWithSequenceNow(std::unique_ptr<Task> task,
- scoped_refptr<Sequence> sequence) override;
+ scoped_refptr<Sequence> sequence,
+ SchedulerWorkerThread* worker_thread) override;
private:
class SchedulerWorkerThreadDelegateImpl;
- SchedulerThreadPoolImpl(
- TaskTracker* task_tracker,
- DelayedTaskManager* delayed_task_manager);
+ SchedulerThreadPoolImpl(TaskTracker* task_tracker,
+ DelayedTaskManager* delayed_task_manager);
bool Initialize(
ThreadPriority thread_priority,
@@ -94,13 +96,27 @@ class BASE_EXPORT SchedulerThreadPoolImpl : public SchedulerThreadPool {
// Adds |worker_thread| to |idle_worker_threads_stack_|.
void AddToIdleWorkerThreadsStack(SchedulerWorkerThread* worker_thread);
- // PriorityQueue from which all threads of this thread pool get work.
- PriorityQueue shared_priority_queue_;
+ // Removes |worker_thread| from |idle_worker_threads_stack_|.
+ void RemoveFromIdleWorkerThreadsStack(SchedulerWorkerThread* worker_thread);
// All worker threads owned by this thread pool. Only modified during
// initialization of the thread pool.
std::vector<std::unique_ptr<SchedulerWorkerThread>> worker_threads_;
+ // Synchronizes access to |next_worker_thread_index_|.
+ SchedulerLock next_worker_thread_index_lock_;
+
+ // Index of the worker thread that will be assigned to the next single-
+ // threaded TaskRunner returned by this pool.
+ size_t next_worker_thread_index_ = 0;
+
+ // PriorityQueue from which all threads of this thread pool get work.
+ PriorityQueue shared_priority_queue_;
+
+ // Single-threaded PriorityQueues.
+ std::unordered_map<SchedulerWorkerThread*, std::unique_ptr<PriorityQueue>>
gab 2016/04/25 21:00:20 TODO about memory management (if we keep the map,
fdoray 2016/04/25 22:34:44 Removed this map.
+ single_threaded_priority_queues_;
+
// Synchronizes access to |idle_worker_threads_stack_| and
// |idle_worker_threads_stack_cv_for_testing_|. Has |shared_priority_queue_|'s
// lock as its predecessor so that a thread can be pushed to

Powered by Google App Engine
This is Rietveld 408576698