wwbmmm commented on code in PR #2645: URL: https://github.com/apache/brpc/pull/2645#discussion_r1632645911
########## src/bthread/key.cpp: ########## @@ -204,14 +205,57 @@ class BAIDU_CACHELINE_ALIGNMENT KeyTable { SubKeyTable* _subs[KEY_1STLEVEL_SIZE]; }; +class KeyTableList { +public: + KeyTableList() { + keytable = NULL; + } + ~KeyTableList() { + bthread::TaskGroup* g = bthread::tls_task_group; + bthread::KeyTable* old_kt = bthread::tls_bls.keytable; + while (keytable) { + bthread::KeyTable* kt = keytable; + keytable = kt->next; + bthread::tls_bls.keytable = kt; + if (g) { + g->current_task()->local_storage.keytable = kt; + } + delete kt; + if (old_kt == kt) { + old_kt = NULL; + } + g = bthread::tls_task_group; + } + bthread::tls_bls.keytable = old_kt; + if(g) { + g->current_task()->local_storage.keytable = old_kt; + } + } + KeyTable* keytable; Review Comment: class 类型不建议直接把成员暴露成public,要么改成struct,要么封装成getter/setter ########## src/bthread/key.cpp: ########## @@ -226,14 +270,16 @@ void return_keytable(bthread_keytable_pool_t* pool, KeyTable* kt) { delete kt; return; } - std::unique_lock<pthread_mutex_t> mu(pool->mutex); + pthread_rwlock_rdlock(&pool->rwlock); if (pool->destroyed) { - mu.unlock(); + pthread_rwlock_unlock(&pool->rwlock); delete kt; return; } - kt->next = (KeyTable*)pool->free_keytables; - pool->free_keytables = kt; + auto list = (butil::ThreadLocal<bthread::KeyTableList>*)pool->list; Review Comment: 全局free_keytables里的kt一旦被借走就永远还不回去free_keytables了吗?这样keytables的复用率会降低吧,如果线程数很多,可能会占用更多的内存 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org For additional commands, e-mail: dev-h...@brpc.apache.org