Unify constant name style.
GitOrigin-RevId: 660f8aa17fa856c828e6c11ade6c497a82cb7612
This commit is contained in:
parent
32af19acfe
commit
afcf7197ae
@ -903,12 +903,12 @@ class RingBenchmark : public td::Benchmark {
|
||||
|
||||
void test_queue() {
|
||||
std::vector<td::thread> threads;
|
||||
constexpr size_t threads_n = 100;
|
||||
std::vector<td::MpscPollableQueue<int>> queues(threads_n);
|
||||
static constexpr size_t THREAD_COUNT = 100;
|
||||
std::vector<td::MpscPollableQueue<int>> queues(THREAD_COUNT);
|
||||
for (auto &q : queues) {
|
||||
q.init();
|
||||
}
|
||||
for (size_t i = 0; i < threads_n; i++) {
|
||||
for (size_t i = 0; i < THREAD_COUNT; i++) {
|
||||
threads.emplace_back([&q = queues[i]] {
|
||||
while (true) {
|
||||
auto got = q.reader_wait_nonblock();
|
||||
@ -923,7 +923,7 @@ void test_queue() {
|
||||
while (true) {
|
||||
td::usleep_for(100);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
queues[td::Random::fast(0, threads_n - 1)].writer_put(1);
|
||||
queues[td::Random::fast(0, THREAD_COUNT - 1)].writer_put(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,12 +109,12 @@ Result<size_t> BufferedFdBase<FdT>::flush_write() {
|
||||
write_->sync_with_writer();
|
||||
size_t result = 0;
|
||||
while (!write_->empty() && ::td::can_write(*this)) {
|
||||
constexpr size_t buf_size = 20;
|
||||
IoSlice buf[buf_size];
|
||||
constexpr size_t BUF_SIZE = 20;
|
||||
IoSlice buf[BUF_SIZE];
|
||||
|
||||
auto it = write_->clone();
|
||||
size_t buf_i;
|
||||
for (buf_i = 0; buf_i < buf_size; buf_i++) {
|
||||
for (buf_i = 0; buf_i < BUF_SIZE; buf_i++) {
|
||||
Slice slice = it.prepare_read();
|
||||
if (slice.empty()) {
|
||||
break;
|
||||
|
@ -34,30 +34,30 @@ class MemoryLog : public LogInterface {
|
||||
size_t slice_size = slice.size();
|
||||
CHECK(slice_size * 3 < buffer_size);
|
||||
size_t pad_size = ((slice_size + 15) & ~15) - slice_size;
|
||||
constexpr size_t magic_size = 16;
|
||||
uint32 total_size = static_cast<uint32>(slice_size + pad_size + magic_size);
|
||||
constexpr size_t MAGIC_SIZE = 16;
|
||||
uint32 total_size = static_cast<uint32>(slice_size + pad_size + MAGIC_SIZE);
|
||||
uint32 real_pos = pos_.fetch_add(total_size, std::memory_order_relaxed);
|
||||
CHECK((total_size & 15) == 0);
|
||||
|
||||
uint32 start_pos = real_pos & (buffer_size - 1);
|
||||
uint32 end_pos = start_pos + total_size;
|
||||
if (likely(end_pos <= buffer_size)) {
|
||||
std::memcpy(&buffer_[start_pos + magic_size], slice.data(), slice_size);
|
||||
std::memcpy(&buffer_[start_pos + magic_size + slice_size], " ", pad_size);
|
||||
std::memcpy(&buffer_[start_pos + MAGIC_SIZE], slice.data(), slice_size);
|
||||
std::memcpy(&buffer_[start_pos + MAGIC_SIZE + slice_size], " ", pad_size);
|
||||
} else {
|
||||
size_t first = buffer_size - start_pos - magic_size;
|
||||
size_t first = buffer_size - start_pos - MAGIC_SIZE;
|
||||
size_t second = slice_size - first;
|
||||
std::memcpy(&buffer_[start_pos + magic_size], slice.data(), first);
|
||||
std::memcpy(&buffer_[start_pos + MAGIC_SIZE], slice.data(), first);
|
||||
std::memcpy(&buffer_[0], slice.data() + first, second);
|
||||
std::memcpy(&buffer_[second], " ", pad_size);
|
||||
}
|
||||
|
||||
CHECK((start_pos & 15) == 0);
|
||||
CHECK(start_pos <= buffer_size - magic_size);
|
||||
CHECK(start_pos <= buffer_size - MAGIC_SIZE);
|
||||
buffer_[start_pos] = '\n';
|
||||
size_t printed = std::snprintf(&buffer_[start_pos + 1], magic_size - 1, "LOG:%08x: ", real_pos);
|
||||
CHECK(printed == magic_size - 2);
|
||||
buffer_[start_pos + magic_size - 1] = ' ';
|
||||
size_t printed = std::snprintf(&buffer_[start_pos + 1], MAGIC_SIZE - 1, "LOG:%08x: ", real_pos);
|
||||
CHECK(printed == MAGIC_SIZE - 2);
|
||||
buffer_[start_pos + MAGIC_SIZE - 1] = ' ';
|
||||
|
||||
if (log_level == VERBOSITY_NAME(FATAL)) {
|
||||
process_fatal_error(new_slice);
|
||||
|
@ -31,20 +31,20 @@ void Random::secure_bytes(MutableSlice dest) {
|
||||
}
|
||||
|
||||
void Random::secure_bytes(unsigned char *ptr, size_t size) {
|
||||
constexpr size_t buf_size = 512;
|
||||
constexpr size_t BUF_SIZE = 512;
|
||||
static TD_THREAD_LOCAL unsigned char *buf; // static zero-initialized
|
||||
static TD_THREAD_LOCAL size_t buf_pos;
|
||||
static TD_THREAD_LOCAL int64 generation;
|
||||
if (init_thread_local<unsigned char[]>(buf, buf_size)) {
|
||||
buf_pos = buf_size;
|
||||
if (init_thread_local<unsigned char[]>(buf, BUF_SIZE)) {
|
||||
buf_pos = BUF_SIZE;
|
||||
generation = 0;
|
||||
}
|
||||
if (generation != random_seed_generation.load(std::memory_order_relaxed)) {
|
||||
generation = random_seed_generation.load(std::memory_order_acquire);
|
||||
buf_pos = buf_size;
|
||||
buf_pos = BUF_SIZE;
|
||||
}
|
||||
|
||||
auto ready = min(size, buf_size - buf_pos);
|
||||
auto ready = min(size, BUF_SIZE - buf_pos);
|
||||
if (ready != 0) {
|
||||
std::memcpy(ptr, buf + buf_pos, ready);
|
||||
buf_pos += ready;
|
||||
@ -54,8 +54,8 @@ void Random::secure_bytes(unsigned char *ptr, size_t size) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (size < buf_size) {
|
||||
int err = RAND_bytes(buf, static_cast<int>(buf_size));
|
||||
if (size < BUF_SIZE) {
|
||||
int err = RAND_bytes(buf, static_cast<int>(BUF_SIZE));
|
||||
// TODO: it CAN fail
|
||||
LOG_IF(FATAL, err != 1);
|
||||
buf_pos = size;
|
||||
|
@ -218,11 +218,11 @@ class SocketFdImpl : private Iocp::Callback {
|
||||
return;
|
||||
}
|
||||
std::memset(&write_overlapped_, 0, sizeof(write_overlapped_));
|
||||
constexpr size_t buf_size = 20;
|
||||
WSABUF buf[buf_size];
|
||||
constexpr size_t BUF_SIZE = 20;
|
||||
WSABUF buf[BUF_SIZE];
|
||||
auto it = output_reader_.clone();
|
||||
size_t buf_i;
|
||||
for (buf_i = 0; buf_i < buf_size; buf_i++) {
|
||||
for (buf_i = 0; buf_i < BUF_SIZE; buf_i++) {
|
||||
auto src = it.prepare_read();
|
||||
if (src.empty()) {
|
||||
break;
|
||||
|
@ -229,7 +229,7 @@ template <template <class> class RawSet>
|
||||
static void test_speed() {
|
||||
Random::Xorshift128plus rnd(123);
|
||||
using Set = CheckedSetWithPosition<int, RawSet>;
|
||||
constexpr size_t total_size = 1 << 13;
|
||||
const size_t total_size = 1 << 13;
|
||||
std::vector<unique_ptr<Set>> sets(total_size);
|
||||
for (size_t i = 0; i < sets.size(); i++) {
|
||||
sets[i] = make_unique<Set>();
|
||||
|
Loading…
Reference in New Issue
Block a user