mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:17:35 +00:00
Kernel: Add DoubleBuffer::try_create() factory method for OOM hardening
We need to expose the ability for DoubleBuffer creation to expose failure, as DoubleBuffer depends on KBuffer, which also has to be able to expose failure during OOM. We will remove the non OOM API once all users have been converted.
This commit is contained in:
parent
b6200a3ed8
commit
f816abcbad
2 changed files with 24 additions and 9 deletions
|
@ -16,8 +16,8 @@ namespace Kernel {
|
|||
|
||||
class DoubleBuffer {
|
||||
public:
|
||||
[[nodiscard]] static OwnPtr<DoubleBuffer> try_create(size_t capacity = 65536);
|
||||
explicit DoubleBuffer(size_t capacity = 65536);
|
||||
|
||||
[[nodiscard]] KResultOr<size_t> write(const UserOrKernelBuffer&, size_t);
|
||||
[[nodiscard]] KResultOr<size_t> write(const u8* data, size_t size)
|
||||
{
|
||||
|
@ -47,6 +47,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
explicit DoubleBuffer(size_t capacity, NonnullOwnPtr<KBuffer> storage);
|
||||
void flip();
|
||||
void compute_lockfree_metadata();
|
||||
|
||||
|
@ -60,7 +61,7 @@ private:
|
|||
InnerBuffer m_buffer1;
|
||||
InnerBuffer m_buffer2;
|
||||
|
||||
KBuffer m_storage;
|
||||
NonnullOwnPtr<KBuffer> m_storage;
|
||||
Function<void()> m_unblock_callback;
|
||||
size_t m_capacity { 0 };
|
||||
size_t m_read_buffer_index { 0 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue