| 96 | } |
| 97 | |
| 98 | inline 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 |
| 126 | BAIDU_THREAD_LOCAL TaskMeta* pthread_fake_meta = NULL; |
no test coverage detected