]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/seastar/include/seastar/util/log-impl.hh
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / seastar / include / seastar / util / log-impl.hh
index 5dd79b0b0557a2aa99d853476710ea031db71e41..3baa80728d3c07ce8c246916dcdd6ce21eade657 100644 (file)
@@ -44,10 +44,10 @@ class log_buf {
     char* _end;
     char* _current;
     bool _own_buf;
-
+    bool _alloc_failure = false;
 private:
     void free_buffer() noexcept;
-    void realloc_buffer();
+    void realloc_buffer_and_append(char c) noexcept;
 
 public:
     // inserter_iterator is designed like std::back_insert_iterator:
@@ -72,14 +72,15 @@ public:
     public:
         explicit inserter_iterator(log_buf& buf) noexcept : _buf(&buf) { }
 
-        inserter_iterator& operator=(char c) {
+        inserter_iterator& operator=(char c) noexcept {
             if (__builtin_expect(_buf->_current == _buf->_end, false)) {
-                _buf->realloc_buffer();
+                _buf->realloc_buffer_and_append(c);
+                return *this;
             }
             *_buf->_current++ = c;
             return *this;
         }
-        inserter_iterator& operator*() {
+        inserter_iterator& operator*() noexcept {
             return *this;
         }
         inserter_iterator& operator++() noexcept {
@@ -100,12 +101,16 @@ public:
     /// allocated buffer. log_buf doesn't take ownership of the buffer.
     log_buf(char* external_buf, size_t size) noexcept;
     ~log_buf();
+    /// Clear the buffer, setting its position back to the start, but does not
+    /// free any buffers (after this called, size is zero, capacity is unchanged).
+    /// Any existing iterators are invalidated.
+    void clear() { _current = _begin; }
     /// Create an output iterator which allows writing into the buffer.
     inserter_iterator back_insert_begin() noexcept { return inserter_iterator(*this); }
     /// The amount of data written so far.
-    const size_t size() const noexcept { return _current - _begin; }
+    size_t size() const noexcept { return _current - _begin; }
     /// The size of the buffer.
-    const size_t capacity() const noexcept { return _end - _begin; }
+    size_t capacity() const noexcept { return _end - _begin; }
     /// Read only pointer to the buffer.
     /// Note that the buffer is not guaranteed to be null terminated. The writer
     /// has to ensure that, should it wish to.