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

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: add #include <algorithm> 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
« no previous file with comments | « base/task_scheduler/scheduler_thread_pool.h ('k') | base/task_scheduler/scheduler_thread_pool_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..13fba7e52b23063077c4bcefde928eb7ae9829cf 100644
--- a/base/task_scheduler/scheduler_thread_pool_impl.h
+++ b/base/task_scheduler/scheduler_thread_pool_impl.h
@@ -12,6 +12,7 @@
#include "base/base_export.h"
#include "base/callback.h"
+#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/condition_variable.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,23 @@ 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_;
+
// 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
@@ -117,6 +129,11 @@ class BASE_EXPORT SchedulerThreadPoolImpl : public SchedulerThreadPool {
// Signaled once JoinForTesting() has returned.
WaitableEvent join_for_testing_returned_;
+#if DCHECK_IS_ON()
+ // Signaled when all threads have been created.
+ WaitableEvent threads_created_;
+#endif
+
TaskTracker* const task_tracker_;
DelayedTaskManager* const delayed_task_manager_;
« no previous file with comments | « base/task_scheduler/scheduler_thread_pool.h ('k') | base/task_scheduler/scheduler_thread_pool_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698