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

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

Issue 2628313004: Add TaskScheduler::JoinForTesting(). (Closed)
Patch Set: self-review Created 3 years, 11 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
« no previous file with comments | « no previous file | base/task_scheduler/scheduler_worker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_H_ 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_H_
6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_H_ 6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // GetWork() returned nullptr. 69 // GetWork() returned nullptr.
70 // 70 //
71 // It is the responsibility of the delegate to determine if detachment is 71 // It is the responsibility of the delegate to determine if detachment is
72 // safe. If the delegate is responsible for thread-affine work, detachment 72 // safe. If the delegate is responsible for thread-affine work, detachment
73 // is generally not safe. 73 // is generally not safe.
74 // 74 //
75 // When true is returned: 75 // When true is returned:
76 // - The next WakeUp() could be more costly due to new thread creation. 76 // - The next WakeUp() could be more costly due to new thread creation.
77 // - The worker will take this as a signal that it can detach, but it is not 77 // - The worker will take this as a signal that it can detach, but it is not
78 // obligated to do so. 78 // obligated to do so.
79 // This MUST return false if SchedulerWorker::JoinForTesting() is in
80 // progress.
81 virtual bool CanDetach(SchedulerWorker* worker) = 0; 79 virtual bool CanDetach(SchedulerWorker* worker) = 0;
82 80
83 // Called by a thread before it detaches. This method is not allowed to 81 // Called by a thread before it detaches. This method is not allowed to
84 // acquire a SchedulerLock because it is called within the scope of another 82 // acquire a SchedulerLock because it is called within the scope of another
85 // SchedulerLock. 83 // SchedulerLock.
86 virtual void OnDetach() = 0; 84 virtual void OnDetach() = 0;
87 }; 85 };
88 86
89 enum class InitialState { ALIVE, DETACHED }; 87 enum class InitialState { ALIVE, DETACHED };
90 88
(...skipping 19 matching lines...) Expand all
110 // is called, this SchedulerWorker will run Tasks from Sequences 108 // is called, this SchedulerWorker will run Tasks from Sequences
111 // returned by the GetWork() method of its delegate until it returns nullptr. 109 // returned by the GetWork() method of its delegate until it returns nullptr.
112 // WakeUp() may fail if the worker is detached and it fails to allocate a new 110 // WakeUp() may fail if the worker is detached and it fails to allocate a new
113 // worker. If this happens, there will be no call to GetWork(). 111 // worker. If this happens, there will be no call to GetWork().
114 void WakeUp(); 112 void WakeUp();
115 113
116 SchedulerWorker::Delegate* delegate() { return delegate_.get(); } 114 SchedulerWorker::Delegate* delegate() { return delegate_.get(); }
117 115
118 // Joins this SchedulerWorker. If a Task is already running, it will be 116 // Joins this SchedulerWorker. If a Task is already running, it will be
119 // allowed to complete its execution. This can only be called once. 117 // allowed to complete its execution. This can only be called once.
118 //
119 // Note: A thread that detaches before JoinForTesting() is called may still be
120 // running after JoinForTesting() returns. However, it can't run tasks after
121 // JoinForTesting() returns.
120 void JoinForTesting(); 122 void JoinForTesting();
121 123
122 // Returns true if the worker is alive. 124 // Returns true if the worker is alive.
123 bool ThreadAliveForTesting() const; 125 bool ThreadAliveForTesting() const;
124 126
125 private: 127 private:
126 class Thread; 128 class Thread;
127 129
128 SchedulerWorker(ThreadPriority thread_priority, 130 SchedulerWorker(ThreadPriority thread_priority,
129 std::unique_ptr<Delegate> delegate, 131 std::unique_ptr<Delegate> delegate,
(...skipping 21 matching lines...) Expand all
151 // Set once JoinForTesting() has been called. 153 // Set once JoinForTesting() has been called.
152 AtomicFlag should_exit_for_testing_; 154 AtomicFlag should_exit_for_testing_;
153 155
154 DISALLOW_COPY_AND_ASSIGN(SchedulerWorker); 156 DISALLOW_COPY_AND_ASSIGN(SchedulerWorker);
155 }; 157 };
156 158
157 } // namespace internal 159 } // namespace internal
158 } // namespace base 160 } // namespace base
159 161
160 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_H_ 162 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_H_
OLDNEW
« no previous file with comments | « no previous file | base/task_scheduler/scheduler_worker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698