ThreadPool takes a lot of arguments. We provide sane defaults with a builder. name: Used for debugging output and default names of the worker threads. Since thread names are limited to 16 characters on Linux, it's good to choose a short name here. Required. trace_metric_prefix: used to prefix the names of TraceMetric counters. When a task on a thread pool has an associated trace, the thread pool
| 111 | // Default: not set. |
| 112 | // |
| 113 | class ThreadPoolBuilder { |
| 114 | public: |
| 115 | explicit ThreadPoolBuilder(std::string name); |
| 116 | |
| 117 | // Note: We violate the style guide by returning mutable references here |
| 118 | // in order to provide traditional Builder pattern conveniences. |
| 119 | ThreadPoolBuilder& set_trace_metric_prefix(const std::string& prefix); |
| 120 | ThreadPoolBuilder& set_min_threads(int min_threads); |
| 121 | ThreadPoolBuilder& set_max_threads(int max_threads); |
| 122 | ThreadPoolBuilder& set_max_queue_size(int max_queue_size); |
| 123 | ThreadPoolBuilder& set_idle_timeout(const MonoDelta& idle_timeout); |
| 124 | ThreadPoolBuilder& set_queue_overload_threshold(const MonoDelta& threshold); |
| 125 | ThreadPoolBuilder& set_metrics(ThreadPoolMetrics metrics); |
| 126 | ThreadPoolBuilder& set_enable_scheduler(); |
| 127 | ThreadPoolBuilder& set_schedule_period_ms(uint32_t schedule_period_ms); |
| 128 | |
| 129 | // Instantiate a new ThreadPool with the existing builder arguments. |
| 130 | Status Build(std::unique_ptr<ThreadPool>* pool) const; |
| 131 | |
| 132 | private: |
| 133 | friend class ThreadPool; |
| 134 | const std::string name_; |
| 135 | std::string trace_metric_prefix_; |
| 136 | int min_threads_; |
| 137 | int max_threads_; |
| 138 | int max_queue_size_; |
| 139 | MonoDelta idle_timeout_; |
| 140 | MonoDelta queue_overload_threshold_; |
| 141 | ThreadPoolMetrics metrics_; |
| 142 | bool enable_scheduler_; |
| 143 | uint32_t schedule_period_ms_ = 100; |
| 144 | |
| 145 | DISALLOW_COPY_AND_ASSIGN(ThreadPoolBuilder); |
| 146 | }; |
| 147 | |
| 148 | // SchedulerThread for asynchronized delay task execution. |
| 149 | // |
no outgoing calls