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

Method task_runner

src/bthread/task_group.cpp:351–481  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349#endif // BUTIL_USE_ASAN
350
351void TaskGroup::task_runner(intptr_t skip_remained) {
352 // NOTE: tls_task_group is volatile since tasks are moved around
353 // different groups.
354 TaskGroup* g = tls_task_group;
355#ifdef BRPC_BTHREAD_TRACER
356 TaskTracer::set_running_status(g->tid(), g->_cur_meta);
357#endif // BRPC_BTHREAD_TRACER
358
359 if (!skip_remained) {
360 while (g->_last_context_remained) {
361 RemainedFn fn = g->_last_context_remained;
362 g->_last_context_remained = NULL;
363 fn(g->_last_context_remained_arg);
364 g = BAIDU_GET_VOLATILE_THREAD_LOCAL(tls_task_group);
365 }
366
367#ifndef NDEBUG
368 --g->_sched_recursive_guard;
369#endif
370 }
371
372 do {
373 // A task can be stopped before it gets running, in which case
374 // we may skip user function, but that may confuse user:
375 // Most tasks have variables to remember running result of the task,
376 // which is often initialized to values indicating success. If an
377 // user function is never called, the variables will be unchanged
378 // however they'd better reflect failures because the task is stopped
379 // abnormally.
380
381 // Meta and identifier of the task is persistent in this run.
382 TaskMeta* const m = g->_cur_meta;
383
384 if (FLAGS_show_bthread_creation_in_vars) {
385 // NOTE: the thread triggering exposure of pending time may spend
386 // considerable time because a single bvar::LatencyRecorder
387 // contains many bvar.
388 g->_control->exposed_pending_time() <<
389 (butil::cpuwide_time_ns() - m->cpuwide_start_ns) / 1000L;
390 }
391
392 // Not catch exceptions except ExitException which is for implementing
393 // bthread_exit(). User code is intended to crash when an exception is
394 // not caught explicitly. This is consistent with other threading
395 // libraries.
396 void* thread_return;
397 try {
398 thread_return = m->fn(m->arg);
399 } catch (ExitException& e) {
400 thread_return = e.value();
401 }
402
403 if (m->attr.flags & BTHREAD_INHERIT_SPAN) {
404 if (g_end_bthread_span) {
405 g_end_bthread_span();
406 }
407 }
408

Callers

nothing calls this directly

Calls 9

cpuwide_time_nsFunction · 0.85
return_keytableFunction · 0.85
butex_wake_exceptFunction · 0.85
tidMethod · 0.80
WaitForTracingMethod · 0.80
set_statusMethod · 0.80
tagMethod · 0.80
set_remainedMethod · 0.80
valueMethod · 0.45

Tested by

no test coverage detected