Thin wrapper around boost::thread that can register itself with the singleton ThreadMgr (a private class implemented in thread.cc entirely, which tracks all live threads so that they may be monitored via the debug webpages). This class has a limited subset of boost::thread's API. Construction is almost the same, but clients must supply a category and a name for each thread so that they can be iden
| 48 | // |
| 49 | /// TODO: Consider allowing fragment IDs as category parameters. |
| 50 | class Thread { |
| 51 | public: |
| 52 | /// This static Create method pattern mimics that in the boost::thread constructors. |
| 53 | /// There is one static Create method for each number of arguments that the thread |
| 54 | /// function accepts. To extend the set of acceptable signatures, add |
| 55 | /// another static Create method with <class F, class A1.... class An>. |
| 56 | // |
| 57 | /// In general: |
| 58 | /// - category: string identifying the thread category to which this thread belongs, |
| 59 | /// used for organising threads together on the debug UI. |
| 60 | /// - name: name of this thread. Will be appended with "-<thread-id>" to ensure |
| 61 | /// uniqueness. |
| 62 | /// - F - a method type that supports operator(), and the instance passed to the |
| 63 | /// constructor is executed immediately in a separate thread. |
| 64 | /// - A1...An - argument types whose instances are passed to f(...) |
| 65 | /// - thread - unique_ptr<Thread>* to reset with the created Thread. |
| 66 | /// - fault_injection_eligible - If set to true, allow fault injection at this |
| 67 | /// callsite (see thread_creation_fault_injection). If set to false, fault |
| 68 | /// injection is diabled at this callsite. Thread creation sites that crash |
| 69 | /// Impala or abort startup must have this set to false. |
| 70 | template <class F> |
| 71 | static Status Create(const std::string& category, const std::string& name, |
| 72 | const F& f, std::unique_ptr<Thread>* thread, |
| 73 | bool fault_injection_eligible = false) { |
| 74 | return StartThread(category, name, f, thread, fault_injection_eligible); |
| 75 | } |
| 76 | |
| 77 | template <class F, class A1> |
| 78 | static Status Create(const std::string& category, const std::string& name, |
| 79 | const F& f, const A1& a1, std::unique_ptr<Thread>* thread, |
| 80 | bool fault_injection_eligible = false) { |
| 81 | return StartThread(category, name, boost::bind(f, a1), thread, |
| 82 | fault_injection_eligible); |
| 83 | } |
| 84 | |
| 85 | template <class F, class A1, class A2> |
| 86 | static Status Create(const std::string& category, const std::string& name, |
| 87 | const F& f, const A1& a1, const A2& a2, std::unique_ptr<Thread>* thread, |
| 88 | bool fault_injection_eligible = false) { |
| 89 | return StartThread(category, name, boost::bind(f, a1, a2), thread, |
| 90 | fault_injection_eligible); |
| 91 | } |
| 92 | |
| 93 | template <class F, class A1, class A2, class A3> |
| 94 | static Status Create(const std::string& category, const std::string& name, |
| 95 | const F& f, const A1& a1, const A2& a2, const A3& a3, |
| 96 | std::unique_ptr<Thread>* thread, bool fault_injection_eligible = false) { |
| 97 | return StartThread(category, name, boost::bind(f, a1, a2, a3), thread, |
| 98 | fault_injection_eligible); |
| 99 | } |
| 100 | |
| 101 | template <class F, class A1, class A2, class A3, class A4> |
| 102 | static Status Create(const std::string& category, const std::string& name, |
| 103 | const F& f, const A1& a1, const A2& a2, const A3& a3, const A4& a4, |
| 104 | std::unique_ptr<Thread>* thread, bool fault_injection_eligible = false) { |
| 105 | return StartThread(category, name, boost::bind(f, a1, a2, a3, a4), thread, |
| 106 | fault_injection_eligible); |
| 107 | } |
no outgoing calls