#if defined(OS_MACOSX)
#include "base/mac/scoped_nsautorelease_pool.h"
+#elif defined(OS_WIN)
+#include "base/win/scoped_com_initializer.h"
#endif
#if !defined(OS_NACL)
SequencedWorkerPool::WorkerShutdown shutdown_behavior);
// TaskRunner implementation
- virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
- const Closure& task,
- TimeDelta delay) OVERRIDE;
- virtual bool RunsTasksOnCurrentThread() const OVERRIDE;
+ bool PostDelayedTask(const tracked_objects::Location& from_here,
+ const Closure& task,
+ TimeDelta delay) override;
+ bool RunsTasksOnCurrentThread() const override;
private:
- virtual ~SequencedWorkerPoolTaskRunner();
+ ~SequencedWorkerPoolTaskRunner() override;
const scoped_refptr<SequencedWorkerPool> pool_;
SequencedWorkerPool::WorkerShutdown shutdown_behavior);
// TaskRunner implementation
- virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
- const Closure& task,
- TimeDelta delay) OVERRIDE;
- virtual bool RunsTasksOnCurrentThread() const OVERRIDE;
+ bool PostDelayedTask(const tracked_objects::Location& from_here,
+ const Closure& task,
+ TimeDelta delay) override;
+ bool RunsTasksOnCurrentThread() const override;
// SequencedTaskRunner implementation
- virtual bool PostNonNestableDelayedTask(
- const tracked_objects::Location& from_here,
- const Closure& task,
- TimeDelta delay) OVERRIDE;
+ bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
+ const Closure& task,
+ TimeDelta delay) override;
private:
- virtual ~SequencedWorkerPoolSequencedTaskRunner();
+ ~SequencedWorkerPoolSequencedTaskRunner() override;
const scoped_refptr<SequencedWorkerPool> pool_;
Worker(const scoped_refptr<SequencedWorkerPool>& worker_pool,
int thread_number,
const std::string& thread_name_prefix);
- virtual ~Worker();
+ ~Worker() override;
// SimpleThread implementation. This actually runs the background thread.
- virtual void Run() OVERRIDE;
+ void Run() override;
void set_running_task_info(SequenceToken token,
WorkerShutdown shutdown_behavior) {
const scoped_refptr<SequencedWorkerPool>& worker_pool,
int thread_number,
const std::string& prefix)
- : SimpleThread(
- prefix + StringPrintf("Worker%d", thread_number).c_str()),
+ : SimpleThread(prefix + StringPrintf("Worker%d", thread_number)),
worker_pool_(worker_pool),
running_shutdown_behavior_(CONTINUE_ON_SHUTDOWN) {
Start();
}
void SequencedWorkerPool::Worker::Run() {
+#if defined(OS_WIN)
+ win::ScopedCOMInitializer com_initializer;
+#endif
+
// Store a pointer to the running sequence in thread local storage for
// static function access.
g_lazy_tls_ptr.Get().Set(&running_sequence_);
// The trace_id is used for identifying the task in about:tracing.
sequenced.trace_id = trace_id_++;
- TRACE_EVENT_FLOW_BEGIN0("task", "SequencedWorkerPool::PostTask",
+ TRACE_EVENT_FLOW_BEGIN0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"),
+ "SequencedWorkerPool::PostTask",
TRACE_ID_MANGLE(GetTaskTraceID(sequenced, static_cast<void*>(this))));
sequenced.sequence_task_number = LockedGetNextSequenceTaskNumber();
GetWorkStatus status =
GetWork(&task, &wait_time, &delete_these_outside_lock);
if (status == GET_WORK_FOUND) {
- TRACE_EVENT_FLOW_END0("task", "SequencedWorkerPool::PostTask",
+ TRACE_EVENT_FLOW_END0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"),
+ "SequencedWorkerPool::PostTask",
TRACE_ID_MANGLE(GetTaskTraceID(task, static_cast<void*>(this))));
- TRACE_EVENT2("task", "SequencedWorkerPool::ThreadLoop",
+ TRACE_EVENT2("toplevel", "SequencedWorkerPool::ThreadLoop",
"src_file", task.posted_from.file_name(),
"src_func", task.posted_from.function_name());
int new_thread_id = WillRunWorkerTask(task);
this_worker->set_running_task_info(
SequenceToken(task.sequence_token_id), task.shutdown_behavior);
- tracked_objects::TrackedTime start_time =
- tracked_objects::ThreadData::NowForStartOfRun(task.birth_tally);
-
+ tracked_objects::ThreadData::PrepareForStartOfRun(task.birth_tally);
+ tracked_objects::TaskStopwatch stopwatch;
+ stopwatch.Start();
task.task.Run();
+ stopwatch.Stop();
- tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(task,
- start_time, tracked_objects::ThreadData::NowForEndOfRun());
+ tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(
+ task, stopwatch);
// Make sure our task is erased outside the lock for the
// same reason we do this with delete_these_oustide_lock.
std::vector<Closure>* delete_these_outside_lock) {
lock_.AssertAcquired();
-#if !defined(OS_NACL)
- UMA_HISTOGRAM_COUNTS_100("SequencedWorkerPool.TaskCount",
- static_cast<int>(pending_tasks_.size()));
-#endif
-
// Find the next task with a sequence token that's not currently in use.
// If the token is in use, that means another thread is running something
// in that sequence, and we can't run it without going out-of-order.
break;
}
- // Track the number of tasks we had to skip over to see if we should be
- // making this more efficient. If this number ever becomes large or is
- // frequently "some", we should consider the optimization above.
-#if !defined(OS_NACL)
- UMA_HISTOGRAM_COUNTS_100("SequencedWorkerPool.UnrunnableTaskCount",
- unrunnable_tasks);
-#endif
return status;
}