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

Function get_or_new_task_control

src/bthread/bthread.cpp:98–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98inline TaskControl* get_or_new_task_control() {
99 butil::atomic<TaskControl*>* p = (butil::atomic<TaskControl*>*)&g_task_control;
100 TaskControl* c = p->load(butil::memory_order_consume);
101 if (c != NULL) {
102 return c;
103 }
104 BAIDU_SCOPED_LOCK(g_task_control_mutex);
105 c = p->load(butil::memory_order_consume);
106 if (c != NULL) {
107 return c;
108 }
109 c = new (std::nothrow) TaskControl;
110 if (NULL == c) {
111 return NULL;
112 }
113 int concurrency = FLAGS_bthread_min_concurrency > 0 ?
114 FLAGS_bthread_min_concurrency :
115 FLAGS_bthread_concurrency;
116 if (c->init(concurrency) != 0) {
117 LOG(ERROR) << "Fail to init g_task_control";
118 delete c;
119 return NULL;
120 }
121 p->store(c, butil::memory_order_release);
122 return c;
123}
124
125#ifdef BRPC_BTHREAD_TRACER
126BAIDU_THREAD_LOCAL TaskMeta* pthread_fake_meta = NULL;

Callers 3

start_from_non_workerFunction · 0.85
bthread_timer_addFunction · 0.85

Calls 3

loadMethod · 0.45
initMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected