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

Method init

src/bthread/task_group.cpp:282–340  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280#endif // BUTIL_USE_ASAN
281
282int TaskGroup::init(size_t runqueue_capacity) {
283 if (_rq.init(runqueue_capacity) != 0) {
284 LOG(FATAL) << "Fail to init _rq";
285 return -1;
286 }
287 if (_remote_rq.init(runqueue_capacity / 2) != 0) {
288 LOG(FATAL) << "Fail to init _remote_rq";
289 return -1;
290 }
291
292#ifdef BUTIL_USE_ASAN
293 void* stack_addr = NULL;
294 size_t stack_size = 0;
295 if (0 != PthreadAttrGetStack(stack_addr, stack_size)) {
296 return -1;
297 }
298#endif // BUTIL_USE_ASAN
299
300 ContextualStack* stk = get_stack(STACK_TYPE_MAIN, NULL);
301 if (NULL == stk) {
302 LOG(FATAL) << "Fail to get main stack container";
303 return -1;
304 }
305 butil::ResourceId<TaskMeta> slot;
306 TaskMeta* m = butil::get_resource<TaskMeta>(&slot);
307 if (NULL == m) {
308 LOG(FATAL) << "Fail to get TaskMeta";
309 return -1;
310 }
311 m->sleep_failed = false;
312 m->stop = false;
313 m->interrupted = false;
314 m->about_to_quit = false;
315 m->fn = NULL;
316 m->arg = NULL;
317 m->local_storage = LOCAL_STORAGE_INIT;
318 m->cpuwide_start_ns = butil::cpuwide_time_ns();
319 m->stat = EMPTY_STAT;
320 m->attr = BTHREAD_ATTR_TASKGROUP;
321 m->tid = make_tid(*m->version_butex, slot);
322 m->set_stack(stk);
323
324#ifdef BUTIL_USE_ASAN
325 stk->storage.bottom = stack_addr;
326 stk->storage.stacksize = stack_size;
327 // No guard size required for ASan.
328#endif // BUTIL_USE_ASAN
329
330 _cur_meta = m;
331 _main_tid = m->tid;
332 _main_stack = stk;
333
334 CPUTimeStat cpu_time_stat;
335 cpu_time_stat.set_last_run_ns(m->cpuwide_start_ns, true);
336 _cpu_time_stat.store(cpu_time_stat);
337 _last_cpu_clock_ns = 0;
338
339 return 0;

Callers 15

InitMethod · 0.45
ResetCertificatesMethod · 0.45
InitializeMethod · 0.45
InitMethod · 0.45
ServersMethod · 0.45
RtmpContextMethod · 0.45
InitCommandHandlersFunction · 0.45
RunNamingServiceMethod · 0.45
RemoveBatchMethod · 0.45
GetNamingServiceThreadFunction · 0.45
InitMethod · 0.45

Calls 7

PthreadAttrGetStackFunction · 0.85
get_stackFunction · 0.85
cpuwide_time_nsFunction · 0.85
make_tidFunction · 0.85
set_stackMethod · 0.80
set_last_run_nsMethod · 0.80
storeMethod · 0.45

Tested by

no test coverage detected