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

Side by Side Diff: base/task_scheduler/scheduler_worker_thread.h

Issue 1903103007: TaskScheduler: Make SchedulerWorkerThread own its delegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sched_2b_remove_utils
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 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_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_H_ 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_H_
6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_H_ 6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 // Called when |sequence| isn't empty after the SchedulerWorkerThread pops a 47 // Called when |sequence| isn't empty after the SchedulerWorkerThread pops a
48 // Task from it. |sequence| is the last Sequence returned by GetWork(). 48 // Task from it. |sequence| is the last Sequence returned by GetWork().
49 virtual void ReEnqueueSequence(scoped_refptr<Sequence> sequence) = 0; 49 virtual void ReEnqueueSequence(scoped_refptr<Sequence> sequence) = 0;
50 }; 50 };
51 51
52 // Creates a SchedulerWorkerThread with priority |thread_priority| that runs 52 // Creates a SchedulerWorkerThread with priority |thread_priority| that runs
53 // Tasks from Sequences returned by |delegate|. |task_tracker| is used to 53 // Tasks from Sequences returned by |delegate|. |task_tracker| is used to
54 // handle shutdown behavior of Tasks. Returns nullptr if creating the 54 // handle shutdown behavior of Tasks. Returns nullptr if creating the
55 // underlying platform thread fails. 55 // underlying platform thread fails.
56 static std::unique_ptr<SchedulerWorkerThread> CreateSchedulerWorkerThread( 56 static std::unique_ptr<SchedulerWorkerThread> Create(
57 ThreadPriority thread_priority, 57 ThreadPriority thread_priority,
58 Delegate* delegate, 58 std::unique_ptr<Delegate> delegate,
59 TaskTracker* task_tracker); 59 TaskTracker* task_tracker);
60 60
61 // Destroying a SchedulerWorkerThread in production is not allowed; it is 61 // Destroying a SchedulerWorkerThread in production is not allowed; it is
62 // always leaked. In tests, it can only be destroyed after JoinForTesting() 62 // always leaked. In tests, it can only be destroyed after JoinForTesting()
63 // has returned. 63 // has returned.
64 ~SchedulerWorkerThread() override; 64 ~SchedulerWorkerThread() override;
65 65
66 // Wakes up this SchedulerWorkerThread if it wasn't already awake. After this 66 // Wakes up this SchedulerWorkerThread if it wasn't already awake. After this
67 // is called, this SchedulerWorkerThread will run Tasks from Sequences 67 // is called, this SchedulerWorkerThread will run Tasks from Sequences
68 // returned by the GetWork() method of its delegate until it returns nullptr. 68 // returned by the GetWork() method of its delegate until it returns nullptr.
69 void WakeUp(); 69 void WakeUp();
70 70
71 // Joins this SchedulerWorkerThread. If a Task is already running, it will be 71 // Joins this SchedulerWorkerThread. If a Task is already running, it will be
72 // allowed to complete its execution. This can only be called once. 72 // allowed to complete its execution. This can only be called once.
73 void JoinForTesting(); 73 void JoinForTesting();
74 74
75 private: 75 private:
76 SchedulerWorkerThread(ThreadPriority thread_priority, 76 SchedulerWorkerThread(ThreadPriority thread_priority,
77 Delegate* delegate, 77 std::unique_ptr<Delegate> delegate,
78 TaskTracker* task_tracker); 78 TaskTracker* task_tracker);
79 79
80 // PlatformThread::Delegate: 80 // PlatformThread::Delegate:
81 void ThreadMain() override; 81 void ThreadMain() override;
82 82
83 bool ShouldExitForTesting() const; 83 bool ShouldExitForTesting() const;
84 84
85 // Platform thread managed by this SchedulerWorkerThread. 85 // Platform thread managed by this SchedulerWorkerThread.
86 PlatformThreadHandle thread_handle_; 86 PlatformThreadHandle thread_handle_;
87 87
88 // Event signaled to wake up this SchedulerWorkerThread. 88 // Event signaled to wake up this SchedulerWorkerThread.
89 WaitableEvent wake_up_event_; 89 WaitableEvent wake_up_event_;
90 90
91 Delegate* const delegate_; 91 const std::unique_ptr<Delegate> delegate_;
92 TaskTracker* const task_tracker_; 92 TaskTracker* const task_tracker_;
93 93
94 // Synchronizes access to |should_exit_for_testing_|. 94 // Synchronizes access to |should_exit_for_testing_|.
95 mutable SchedulerLock should_exit_for_testing_lock_; 95 mutable SchedulerLock should_exit_for_testing_lock_;
96 96
97 // True once JoinForTesting() has been called. 97 // True once JoinForTesting() has been called.
98 bool should_exit_for_testing_ = false; 98 bool should_exit_for_testing_ = false;
99 99
100 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerThread); 100 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerThread);
101 }; 101 };
102 102
103 } // namespace internal 103 } // namespace internal
104 } // namespace base 104 } // namespace base
105 105
106 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_H_ 106 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_THREAD_H_
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_thread_pool_impl_unittest.cc ('k') | base/task_scheduler/scheduler_worker_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698