| 142 | } |
| 143 | |
| 144 | int TimerThread::start(const TimerThreadOptions* options_in) { |
| 145 | if (_started) { |
| 146 | return 0; |
| 147 | } |
| 148 | if (options_in) { |
| 149 | _options = *options_in; |
| 150 | } |
| 151 | if (_options.num_buckets == 0) { |
| 152 | LOG(ERROR) << "num_buckets can't be 0"; |
| 153 | return EINVAL; |
| 154 | } |
| 155 | if (_options.num_buckets > 1024) { |
| 156 | LOG(ERROR) << "num_buckets=" << _options.num_buckets << " is too big"; |
| 157 | return EINVAL; |
| 158 | } |
| 159 | _buckets = new (std::nothrow) Bucket[_options.num_buckets]; |
| 160 | if (NULL == _buckets) { |
| 161 | LOG(ERROR) << "Fail to new _buckets"; |
| 162 | return ENOMEM; |
| 163 | } |
| 164 | const int ret = pthread_create(&_thread, NULL, TimerThread::run_this, this); |
| 165 | if (ret) { |
| 166 | return ret; |
| 167 | } |
| 168 | _started = true; |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | TimerThread::Task* TimerThread::Bucket::consume_tasks() { |
| 173 | Task* head = NULL; |
no outgoing calls
no test coverage detected