File tree Expand file tree Collapse file tree 1 file changed +5
-13
lines changed Expand file tree Collapse file tree 1 file changed +5
-13
lines changed Original file line number Diff line number Diff line change 2323#include < utility>
2424#include < vector>
2525
26+ #include " trpc/util/algorithm/power_of_two.h"
27+
2628namespace trpc {
2729
2830// / @brief Implementation of a thread-safe lock-free queue that supports multiple producers and multiple
@@ -54,21 +56,11 @@ class alignas(64) LockFreeQueue {
5456 return RT_OK;
5557 }
5658
57- bool size_is_power_of_2 = (size >= 2 ) && ((size & (size - 1 )) == 0 );
58- if (!size_is_power_of_2) {
59- uint64_t tmp = 1 ;
60- while (tmp <= size) {
61- tmp <<= 1 ;
62- }
63-
64- size = tmp;
65- }
66-
67- mask_ = size - 1 ;
68- capacity_ = size;
59+ capacity_ = RoundUpPowerOf2 (size);
60+ mask_ = capacity_ - 1 ;
6961
7062 elements_ = std::make_unique<Element[]>(capacity_);
71- for (size_t i = 0 ; i < size ; ++i) {
63+ for (size_t i = 0 ; i < capacity_ ; ++i) {
7264 elements_[i].sequence = i;
7365 }
7466
You can’t perform that action at this time.
0 commit comments