Referenced in task_group.cpp, must be extern. Caller of this function must hold the KeyTable
| 372 | // Referenced in task_group.cpp, must be extern. |
| 373 | // Caller of this function must hold the KeyTable |
| 374 | void return_keytable(bthread_keytable_pool_t* pool, KeyTable* kt) { |
| 375 | if (NULL == kt) { |
| 376 | return; |
| 377 | } |
| 378 | if (pool == NULL) { |
| 379 | delete kt; |
| 380 | return; |
| 381 | } |
| 382 | pthread_rwlock_rdlock(&pool->rwlock); |
| 383 | if (pool->destroyed) { |
| 384 | pthread_rwlock_unlock(&pool->rwlock); |
| 385 | delete kt; |
| 386 | return; |
| 387 | } |
| 388 | auto list = (butil::ThreadLocal<bthread::KeyTableList>*)pool->list; |
| 389 | list->get()->append(kt); |
| 390 | if (list->get()->get_length() > FLAGS_key_table_list_size) { |
| 391 | pthread_rwlock_unlock(&pool->rwlock); |
| 392 | pthread_rwlock_wrlock(&pool->rwlock); |
| 393 | if (!pool->destroyed) { |
| 394 | int out = list->get()->move_first_n_to_target( |
| 395 | (KeyTable**)(&pool->free_keytables), |
| 396 | FLAGS_key_table_list_size / 2); |
| 397 | pool->size += out; |
| 398 | } |
| 399 | } |
| 400 | pthread_rwlock_unlock(&pool->rwlock); |
| 401 | } |
| 402 | |
| 403 | static void cleanup_pthread(void* arg) { |
| 404 | KeyTable* kt = static_cast<KeyTable*>(arg); |