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

Function bthread_keytable_pool_destroy

src/bthread/key.cpp:454–491  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

452}
453
454int bthread_keytable_pool_destroy(bthread_keytable_pool_t* pool) {
455 if (pool == NULL) {
456 LOG(ERROR) << "Param[pool] is NULL";
457 return EINVAL;
458 }
459 bthread::KeyTable* saved_free_keytables = NULL;
460 pthread_rwlock_wrlock(&pool->rwlock);
461 pool->destroyed = 1;
462 pool->size = 0;
463 delete (butil::ThreadLocal<bthread::KeyTableList>*)pool->list;
464 saved_free_keytables = (bthread::KeyTable*)pool->free_keytables;
465 pool->list = NULL;
466 pool->free_keytables = NULL;
467 pthread_rwlock_unlock(&pool->rwlock);
468
469 // Cheat get/setspecific and destroy the keytables.
470 bthread::TaskGroup* g =
471 bthread::BAIDU_GET_VOLATILE_THREAD_LOCAL(tls_task_group);
472 bthread::KeyTable* old_kt = bthread::tls_bls.keytable;
473 while (saved_free_keytables) {
474 bthread::KeyTable* kt = saved_free_keytables;
475 saved_free_keytables = kt->next;
476 bthread::tls_bls.keytable = kt;
477 if (g) {
478 g->current_task()->local_storage.keytable = kt;
479 }
480 delete kt;
481 g = bthread::BAIDU_GET_VOLATILE_THREAD_LOCAL(tls_task_group);
482 }
483 bthread::tls_bls.keytable = old_kt;
484 if (g) {
485 g->current_task()->local_storage.keytable = old_kt;
486 }
487 // TODO: return_keytable may race with this function, we don't destroy
488 // the mutex right now.
489 // pthread_mutex_destroy(&pool->mutex);
490 return 0;
491}
492
493int bthread_keytable_pool_getstat(bthread_keytable_pool_t* pool,
494 bthread_keytable_pool_stat_t* stat) {

Callers 2

TESTFunction · 0.85
JoinMethod · 0.85

Calls 1

current_taskMethod · 0.80

Tested by 1

TESTFunction · 0.68