Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / base / threading / sequenced_worker_pool.cc
index 4fc090d..4c37320 100644 (file)
@@ -32,6 +32,8 @@
 
 #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)
@@ -96,13 +98,13 @@ class SequencedWorkerPoolTaskRunner : public TaskRunner {
       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_;
 
@@ -149,19 +151,18 @@ class SequencedWorkerPoolSequencedTaskRunner : public SequencedTaskRunner {
       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_;
 
@@ -233,10 +234,10 @@ class SequencedWorkerPool::Worker : public SimpleThread {
   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) {
@@ -480,8 +481,7 @@ SequencedWorkerPool::Worker::Worker(
     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();
@@ -491,6 +491,10 @@ SequencedWorkerPool::Worker::~Worker() {
 }
 
 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_);
@@ -593,7 +597,8 @@ bool SequencedWorkerPool::Inner::PostTask(
     // 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();
@@ -726,9 +731,10 @@ void SequencedWorkerPool::Inner::ThreadLoop(Worker* this_worker) {
       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);
@@ -748,13 +754,14 @@ void SequencedWorkerPool::Inner::ThreadLoop(Worker* this_worker) {
           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.
@@ -896,11 +903,6 @@ SequencedWorkerPool::Inner::GetWorkStatus SequencedWorkerPool::Inner::GetWork(
     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.
@@ -981,13 +983,6 @@ SequencedWorkerPool::Inner::GetWorkStatus SequencedWorkerPool::Inner::GetWork(
     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;
 }