1 // Copyright 2016 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROMIUMOS_WIDE_PROFILING_COMPAT_CROS_DETAIL_THREAD_H_ 6 #define CHROMIUMOS_WIDE_PROFILING_COMPAT_CROS_DETAIL_THREAD_H_ 7 8 #include "base/synchronization/waitable_event.h" 9 #include "base/threading/simple_thread.h" 10 11 namespace quipper { 12 13 class Thread : public quipper::compat::ThreadInterface, 14 public base::DelegateSimpleThread::Delegate { 15 public: Thread(const string & name_prefix)16 explicit Thread(const string& name_prefix) : thread_(this, name_prefix) {} 17 Start()18 void Start() override { thread_.Start(); } 19 Join()20 void Join() override { thread_.Join(); } 21 tid()22 pid_t tid() override { return thread_.tid(); } 23 24 protected: 25 void Run() override = 0; 26 27 private: 28 base::DelegateSimpleThread thread_; 29 }; 30 31 class Notification : public quipper::compat::NotificationInterface { 32 public: Notification()33 Notification() 34 : event_(true /* manual_reset */, false /* initially_signaled */) {} 35 Wait()36 void Wait() override { event_.Wait(); } 37 WaitWithTimeout(int timeout_ms)38 bool WaitWithTimeout(int timeout_ms) override { 39 return event_.TimedWait(base::TimeDelta::FromMilliseconds(timeout_ms)); 40 } 41 Notify()42 void Notify() override { event_.Signal(); } 43 44 private: 45 base::WaitableEvent event_; 46 }; 47 48 } // namespace quipper 49 50 #endif // CHROMIUMOS_WIDE_PROFILING_COMPAT_CROS_DETAIL_THREAD_H_ 51