MJY-HUST commented on code in PR #2768: URL: https://github.com/apache/brpc/pull/2768#discussion_r1769533953
########## src/bthread/key.cpp: ########## @@ -205,53 +214,130 @@ class BAIDU_CACHELINE_ALIGNMENT KeyTable { SubKeyTable* _subs[KEY_1STLEVEL_SIZE]; }; -struct KeyTableList { - KeyTableList() { - keytable = NULL; +class BAIDU_CACHELINE_ALIGNMENT KeyTableList { + public: + KeyTableList() : _head(NULL), _tail(NULL), _length(0) {} + + ~KeyTableList() { + bthread::TaskGroup* g = bthread::tls_task_group; + bthread::KeyTable* old_kt = bthread::tls_bls.keytable; + KeyTable* keytable = _head; + 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; } - ~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; - } + bthread::tls_bls.keytable = old_kt; + if (g) { + g->current_task()->local_storage.keytable = old_kt; + } + } + + void append(KeyTable* keytable) { + if (keytable == NULL) { + return; } - KeyTable* keytable; + if (_head == NULL) { + _head = _tail = keytable; + } else { + _tail->next = keytable; + _tail = keytable; + } + keytable->next = NULL; + _length++; + } + + KeyTable* remove_front() { + if (_head == NULL) { + return NULL; + } + KeyTable* temp = _head; + _head = _head->next; + _length--; + if (_head == NULL) { + _tail = NULL; + } + return temp; + } + + void move_first_n_to_target(KeyTable* target, uint32_t size) { + if (size < _length || _head == NULL) { Review Comment: 是的,已修改 -- 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