diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-18 20:43:39 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-19 10:23:12 +0100 |
commit | d893498e5738b9d37bd07bdedb4709ae46750fbd (patch) | |
tree | 87efbbcb41b80d11b0ee2e1691045fab373b406f | |
parent | fb9a71bd6a1e7dba39a894440ecfa540e10d604f (diff) | |
download | serenity-d893498e5738b9d37bd07bdedb4709ae46750fbd.zip |
Kernel: Use fallible KBuffer API in PerformanceEventBuffer
-rw-r--r-- | Kernel/PerformanceEventBuffer.cpp | 4 | ||||
-rw-r--r-- | Kernel/PerformanceEventBuffer.h | 9 |
2 files changed, 9 insertions, 4 deletions
diff --git a/Kernel/PerformanceEventBuffer.cpp b/Kernel/PerformanceEventBuffer.cpp index 2a96bf22b5..51c35c051e 100644 --- a/Kernel/PerformanceEventBuffer.cpp +++ b/Kernel/PerformanceEventBuffer.cpp @@ -33,7 +33,7 @@ namespace Kernel { PerformanceEventBuffer::PerformanceEventBuffer() - : m_buffer(KBuffer::create_with_size(4 * MiB)) + : m_buffer(KBuffer::try_create_with_size(4 * MiB)) { } @@ -89,7 +89,7 @@ KResult PerformanceEventBuffer::append(int type, FlatPtr arg1, FlatPtr arg2) PerformanceEvent& PerformanceEventBuffer::at(size_t index) { ASSERT(index < capacity()); - auto* events = reinterpret_cast<PerformanceEvent*>(m_buffer.data()); + auto* events = reinterpret_cast<PerformanceEvent*>(m_buffer->data()); return events[index]; } diff --git a/Kernel/PerformanceEventBuffer.h b/Kernel/PerformanceEventBuffer.h index 25750baaa7..4d5ca2ed70 100644 --- a/Kernel/PerformanceEventBuffer.h +++ b/Kernel/PerformanceEventBuffer.h @@ -61,7 +61,12 @@ public: KResult append(int type, FlatPtr arg1, FlatPtr arg2); - size_t capacity() const { return m_buffer.size() / sizeof(PerformanceEvent); } + size_t capacity() const + { + if (!m_buffer) + return 0; + return m_buffer->size() / sizeof(PerformanceEvent); + } size_t count() const { return m_count; } const PerformanceEvent& at(size_t index) const { @@ -74,7 +79,7 @@ private: PerformanceEvent& at(size_t index); size_t m_count { 0 }; - KBuffer m_buffer; + OwnPtr<KBuffer> m_buffer; }; } |