Index: components/arc/metrics/oom_kills_monitor.h |
diff --git a/components/arc/metrics/oom_kills_monitor.h b/components/arc/metrics/oom_kills_monitor.h |
index c6cf7995ae835043f084b1eb1d3aa3e34734be0a..f4e188445f0ff5737eebd115c822aabeb80fa0dc 100644 |
--- a/components/arc/metrics/oom_kills_monitor.h |
+++ b/components/arc/metrics/oom_kills_monitor.h |
@@ -5,33 +5,58 @@ |
#ifndef COMPONENTS_ARC_METRICS_OOM_KILLS_MONITOR_H_ |
#define COMPONENTS_ARC_METRICS_OOM_KILLS_MONITOR_H_ |
+#include <memory> |
+ |
#include "base/macros.h" |
#include "base/memory/ref_counted.h" |
-#include "base/threading/sequenced_worker_pool.h" |
+#include "base/synchronization/atomic_flag.h" |
+#include "base/threading/simple_thread.h" |
namespace arc { |
// Traces kernel OOM kill events and lowmemorykiller (if enabled) events. |
// |
// OomKillsMonitor listens to kernel messages for both OOM kills and |
-// lowmemorykiller kills, then reports to UMA. |
+// lowmemorykiller kills, then reports to UMA. It uses a non-joinable thread |
+// in order to avoid blocking shutdown. |
// |
// Note: There should be only one OomKillsMonitor instance globally at any given |
// time, otherwise UMA would receive duplicate events. |
-class OomKillsMonitor { |
+class OomKillsMonitor : public base::DelegateSimpleThread::Delegate { |
public: |
- OomKillsMonitor(); |
- ~OomKillsMonitor(); |
+ // A handle representing the OomKillsMonitor's lifetime (the monitor itself |
+ // can't be destroyed per being a non-joinable Thread). |
+ class Handle { |
+ public: |
+ // Constructs a handle that will flag |outer| as shutting down on |
+ // destruction. |
+ explicit Handle(OomKillsMonitor* outer); |
+ |
+ ~Handle(); |
+ |
+ private: |
+ OomKillsMonitor* const outer_; |
+ }; |
- void Start(); |
- void Stop(); |
+ // Instantiates the OomKillsMonitor instance and starts it. This must only |
+ // be invoked once per process. |
+ static Handle StartMonitoring(); |
private: |
- // Keeps a reference to worker_pool_ in case |this| is deleted in |
- // shutdown process while this thread returns from a blocking read. |
- static void Run(scoped_refptr<base::SequencedWorkerPool> worker_pool); |
+ OomKillsMonitor(); |
+ ~OomKillsMonitor() override; |
+ |
+ // Overridden from base::DelegateSimpleThread::Delegate: |
+ void Run() override; |
+ |
+ // A flag set when OomKillsMonitor is shutdown so that its thread can poll |
+ // it and attempt to wind down from that point (to avoid unecessary work, not |
+ // because it blocks shutdown). |
+ base::AtomicFlag is_shutting_down_; |
- scoped_refptr<base::SequencedWorkerPool> worker_pool_; |
+ // The underlying worker thread which is non-joinable to avoid blocking |
+ // shutdown. |
+ std::unique_ptr<base::DelegateSimpleThread> non_joinable_worker_thread_; |
DISALLOW_COPY_AND_ASSIGN(OomKillsMonitor); |
}; |