| 465 | static pthread_once_t g_timer_thread_once = PTHREAD_ONCE_INIT; |
| 466 | static TimerThread* g_timer_thread = NULL; |
| 467 | static void init_global_timer_thread() { |
| 468 | g_timer_thread = new (std::nothrow) TimerThread; |
| 469 | if (g_timer_thread == NULL) { |
| 470 | LOG(FATAL) << "Fail to new g_timer_thread"; |
| 471 | return; |
| 472 | } |
| 473 | TimerThreadOptions options; |
| 474 | options.bvar_prefix = "bthread_timer"; |
| 475 | options.num_buckets = FLAGS_brpc_timer_num_buckets; |
| 476 | const int rc = g_timer_thread->start(&options); |
| 477 | if (rc != 0) { |
| 478 | LOG(FATAL) << "Fail to start timer_thread, " << berror(rc); |
| 479 | delete g_timer_thread; |
| 480 | g_timer_thread = NULL; |
| 481 | return; |
| 482 | } |
| 483 | } |
| 484 | TimerThread* get_or_create_global_timer_thread() { |
| 485 | pthread_once(&g_timer_thread_once, init_global_timer_thread); |
| 486 | return g_timer_thread; |