MCPcopy Create free account
hub / github.com/apache/brpc / schedule

Method schedule

src/bthread/timer_thread.cpp:188–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186}
187
188TimerThread::Bucket::ScheduleResult
189TimerThread::Bucket::schedule(void (*fn)(void*), void* arg,
190 const timespec& abstime) {
191 butil::ResourceId<Task> slot_id;
192 Task* task = butil::get_resource<Task>(&slot_id);
193 if (task == NULL) {
194 ScheduleResult result = { INVALID_TASK_ID, false };
195 return result;
196 }
197 task->next = NULL;
198 task->fn = fn;
199 task->arg = arg;
200 task->run_time = butil::timespec_to_microseconds(abstime);
201 uint32_t version = task->version.load(butil::memory_order_relaxed);
202 if (version == 0) { // skip 0.
203 task->version.fetch_add(2, butil::memory_order_relaxed);
204 version = 2;
205 }
206 const TaskId id = make_task_id(slot_id, version);
207 task->task_id = id;
208 bool earlier = false;
209 {
210 BAIDU_SCOPED_LOCK(_mutex);
211 task->next = _task_head;
212 _task_head = task;
213 if (task->run_time < _nearest_run_time) {
214 _nearest_run_time = task->run_time;
215 earlier = true;
216 }
217 }
218 ScheduleResult result = { id, earlier };
219 return result;
220}
221
222TimerThread::TaskId TimerThread::schedule(
223 void (*fn)(void*), void* arg, const timespec& abstime) {

Callers 4

wait_for_butexFunction · 0.45
_destroy_groupMethod · 0.45
bthread_timer_addFunction · 0.45
_add_sleep_eventMethod · 0.45

Calls 7

timespec_to_microsecondsFunction · 0.85
make_task_idFunction · 0.85
fmix64Function · 0.85
pthread_numeric_idFunction · 0.85
fetch_addMethod · 0.80
futex_wake_privateFunction · 0.70
loadMethod · 0.45

Tested by

no test coverage detected