1 // Copyright 2015 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_THREAD_H_ 6 #define CHROMIUMOS_WIDE_PROFILING_COMPAT_THREAD_H_ 7 8 namespace quipper { 9 namespace compat { 10 11 // The Thread implementation used by quipper implements this interface. 12 class ThreadInterface { 13 public: 14 // Constructor signature should match this: 15 // Thread(const string& name_prefix); 16 ~ThreadInterface()17 virtual ~ThreadInterface() {} 18 19 // Start the thread. 20 virtual void Start() = 0; 21 // quipper threads must be joined exactly once. 22 virtual void Join() = 0; 23 24 virtual pid_t tid() = 0; 25 26 protected: 27 // Thread body. Override this. 28 virtual void Run() = 0; 29 }; 30 31 // Synchronization tool that blocks waiting threads until notified to proceed by 32 // another. 33 class NotificationInterface { 34 public: 35 // Constructor signature should match this: 36 // Notification(); 37 ~NotificationInterface()38 virtual ~NotificationInterface() {} 39 40 // Wait for Notify() to be called. 41 virtual void Wait() = 0; 42 // Wait for up to |timeout_ms| for a notification. Returns true if the 43 // event was signaled. Returning false does not necessarily mean |timout_ms| 44 // has passed. 45 virtual bool WaitWithTimeout(int timeout_ms) = 0; 46 47 // Trigger the notification, and wake up any waiting threads. 48 virtual void Notify() = 0; 49 }; 50 51 } // namespace compat 52 } // namespace quipper 53 54 #include "detail/thread.h" 55 56 #endif // CHROMIUMOS_WIDE_PROFILING_COMPAT_THREAD_H_ 57