[sanity] fix (#37385)

Closes #37385

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37385 from ctiller:san 2d3c1b4a2c
PiperOrigin-RevId: 658680781
pull/37371/head^2
Craig Tiller 7 months ago committed by Copybara-Service
parent c8891a9542
commit bda6c3adf8
  1. 6
      src/core/util/latent_see.cc
  2. 3
      src/core/util/latent_see.h
  3. 24
      src/core/util/ring_buffer.h
  4. 7
      test/core/util/ring_buffer_test.cc

@ -21,13 +21,13 @@
#include <string>
#include <vector>
#include "src/core/lib/gprpp/sync.h"
#include "src/core/util/ring_buffer.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/util/ring_buffer.h"
namespace grpc_core {
namespace latent_see {

@ -126,8 +126,7 @@ class Log {
static std::atomic<Bin*> free_bins_;
struct Fragment {
Mutex mu;
grpc_core::RingBuffer<RecordedEvent, Log::kMaxEventsPerCpu> events
ABSL_GUARDED_BY(mu);
RingBuffer<RecordedEvent, Log::kMaxEventsPerCpu> events ABSL_GUARDED_BY(mu);
};
PerCpu<Fragment> fragments_{PerCpuOptions()};
};

@ -1,5 +1,19 @@
#ifndef GRPC_SRC_CORE_UTIL_RING_BUFFER_H_
#define GRPC_SRC_CORE_UTIL_RING_BUFFER_H_
// Copyright 2024 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef GRPC_SRC_CORE_UTIL_RING_BUFFER_H
#define GRPC_SRC_CORE_UTIL_RING_BUFFER_H
#include <grpc/support/port_platform.h>
@ -50,9 +64,9 @@ class RingBuffer {
T operator*() { return buffer_->data_[head_]; }
RingBufferIterator() : buffer_(nullptr), head_(0), size_(0) {};
RingBufferIterator() : buffer_(nullptr), head_(0), size_(0){};
RingBufferIterator(const RingBufferIterator& other) = default;
RingBufferIterator(const RingBuffer<T, kCapacity>* buffer)
explicit RingBufferIterator(const RingBuffer<T, kCapacity>* buffer)
: buffer_(buffer), head_(buffer->head_), size_(buffer->size_) {
if (!size_) {
buffer_ = nullptr;
@ -106,4 +120,4 @@ class RingBuffer {
} // namespace grpc_core
#endif // GRPC_SRC_CORE_UTIL_RING_BUFFER_H_
#endif // GRPC_SRC_CORE_UTIL_RING_BUFFER_H

@ -16,10 +16,11 @@
//
//
#include <grpc/support/port_platform.h>
#include "src/core/util/ring_buffer.h"
#include "gtest/gtest.h"
#include "src/core/util/ring_buffer.h"
#include <grpc/support/port_platform.h>
namespace grpc_core {
@ -29,7 +30,7 @@ TEST(RingBufferTest, BufferAppendPopTest) {
RingBuffer<int, kBufferCapacity> buffer;
EXPECT_FALSE(buffer.PopIfNotEmpty().has_value());
for (int i = 0; i < (3 * kBufferCapacity)/2; ++i) {
for (int i = 0; i < (3 * kBufferCapacity) / 2; ++i) {
buffer.Append(i);
}
// Pop half of the elements. Elements in [kBufferCapacity / 2,

Loading…
Cancel
Save