From 2dcf8d3e7ff987c7eb24a4a73159806f78e46bc1 Mon Sep 17 00:00:00 2001 From: nolan-veed <88709630+nolan-veed@users.noreply.github.com> Date: Wed, 27 Dec 2023 14:10:40 +0000 Subject: [PATCH] In Context, hold pools not factories. --- src/internal_modules/roc_core/buffer.h | 2 +- .../roc_core/buffer_factory.h | 8 ++++---- src/internal_modules/roc_node/context.cpp | 19 ++++++++++--------- src/internal_modules/roc_node/context.h | 18 +++++++++--------- .../roc_packet/packet_factory.cpp | 4 ++-- .../roc_packet/packet_factory.h | 6 +++--- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/internal_modules/roc_core/buffer.h b/src/internal_modules/roc_core/buffer.h index c2f11044f..fd7962f73 100644 --- a/src/internal_modules/roc_core/buffer.h +++ b/src/internal_modules/roc_core/buffer.h @@ -15,7 +15,7 @@ #include "roc_core/align_ops.h" #include "roc_core/macro_helpers.h" #include "roc_core/ref_counted.h" -#include "roc_core/slab_pool.h" +#include "roc_core/ipool.h" #include "roc_core/stddefs.h" namespace roc { diff --git a/src/internal_modules/roc_core/buffer_factory.h b/src/internal_modules/roc_core/buffer_factory.h index ee50bc973..0d99afd0e 100644 --- a/src/internal_modules/roc_core/buffer_factory.h +++ b/src/internal_modules/roc_core/buffer_factory.h @@ -14,9 +14,9 @@ #include "roc_core/allocation_policy.h" #include "roc_core/buffer.h" +#include "roc_core/ipool.h" #include "roc_core/noncopyable.h" #include "roc_core/shared_ptr.h" -#include "roc_core/slab_pool.h" namespace roc { namespace core { @@ -28,8 +28,8 @@ template class BufferFactory : public core::NonCopyable<> { public: //! Initialization. //! @p buffer_size defines number of elements in buffer. - BufferFactory(IArena& arena, size_t buffer_size) - : buffer_pool_("buffer_pool", arena, sizeof(Buffer) + sizeof(T) * buffer_size) + BufferFactory(IPool& pool, size_t buffer_size) + : buffer_pool_(pool) , buffer_size_(buffer_size) { } @@ -44,7 +44,7 @@ template class BufferFactory : public core::NonCopyable<> { } private: - SlabPool > buffer_pool_; + IPool& buffer_pool_; const size_t buffer_size_; }; diff --git a/src/internal_modules/roc_node/context.cpp b/src/internal_modules/roc_node/context.cpp index 2d9c3b024..11c53f5b0 100644 --- a/src/internal_modules/roc_node/context.cpp +++ b/src/internal_modules/roc_node/context.cpp @@ -15,10 +15,11 @@ namespace node { Context::Context(const ContextConfig& config, core::IArena& arena) : arena_(arena) - , packet_factory_(arena_) - , byte_buffer_factory_(arena_, config.max_packet_size) - , sample_buffer_factory_(arena_, config.max_frame_size / sizeof(audio::sample_t)) + , packet_pool_("packet_pool", arena_) + , byte_buffer_pool_("byte_buf_pool", arena_, sizeof(core::Buffer) + sizeof(uint8_t) * config.max_packet_size) + , sample_buffer_pool_("sample_buf_pool", arena_, sizeof(core::Buffer) + sizeof(audio::sample_t) * config.max_frame_size) , encoding_map_(arena_) + // TODO: , network_loop_(packet_factory_, byte_buffer_factory_, arena_) , control_loop_(network_loop_, arena_) { roc_log(LogDebug, "context: initializing"); @@ -36,16 +37,16 @@ core::IArena& Context::arena() { return arena_; } -packet::PacketFactory& Context::packet_factory() { - return packet_factory_; +core::IPool& Context::packet_pool() { + return packet_pool_; } -core::BufferFactory& Context::byte_buffer_factory() { - return byte_buffer_factory_; +core::IPool& Context::byte_buffer_pool() { + return byte_buffer_pool_; } -core::BufferFactory& Context::sample_buffer_factory() { - return sample_buffer_factory_; +core::IPool& Context::sample_buffer_pool() { + return sample_buffer_pool_; } rtp::EncodingMap& Context::encoding_map() { diff --git a/src/internal_modules/roc_node/context.h b/src/internal_modules/roc_node/context.h index 837734762..1278d5a40 100644 --- a/src/internal_modules/roc_node/context.h +++ b/src/internal_modules/roc_node/context.h @@ -55,14 +55,14 @@ class Context : public core::RefCounted { //! Get arena. core::IArena& arena(); - //! Get packet factory. - packet::PacketFactory& packet_factory(); + //! Get packet pool. + core::IPool& packet_pool(); - //! Get byte buffer factory. - core::BufferFactory& byte_buffer_factory(); + //! Get byte buffer pool. + core::IPool& byte_buffer_pool(); - //! Get sample buffer factory. - core::BufferFactory& sample_buffer_factory(); + //! Get sample buffer pool. + core::IPool& sample_buffer_pool(); //! Get encoding map. rtp::EncodingMap& encoding_map(); @@ -76,9 +76,9 @@ class Context : public core::RefCounted { private: core::IArena& arena_; - packet::PacketFactory packet_factory_; - core::BufferFactory byte_buffer_factory_; - core::BufferFactory sample_buffer_factory_; + core::SlabPool packet_pool_; + core::SlabPool > byte_buffer_pool_; + core::SlabPool > sample_buffer_pool_; rtp::EncodingMap encoding_map_; diff --git a/src/internal_modules/roc_packet/packet_factory.cpp b/src/internal_modules/roc_packet/packet_factory.cpp index cb0e3d74b..b080f9fcb 100644 --- a/src/internal_modules/roc_packet/packet_factory.cpp +++ b/src/internal_modules/roc_packet/packet_factory.cpp @@ -12,8 +12,8 @@ namespace roc { namespace packet { -PacketFactory::PacketFactory(core::IArena& arena) - : pool_("packet_pool", arena) { +PacketFactory::PacketFactory(core::IPool& pool) + : pool_(pool) { } core::SharedPtr PacketFactory::new_packet() { diff --git a/src/internal_modules/roc_packet/packet_factory.h b/src/internal_modules/roc_packet/packet_factory.h index 7c3f81bd4..96c5f16d1 100644 --- a/src/internal_modules/roc_packet/packet_factory.h +++ b/src/internal_modules/roc_packet/packet_factory.h @@ -15,7 +15,7 @@ #include "roc_core/allocation_policy.h" #include "roc_core/noncopyable.h" #include "roc_core/shared_ptr.h" -#include "roc_core/slab_pool.h" +#include "roc_core/ipool.h" #include "roc_packet/packet.h" namespace roc { @@ -25,13 +25,13 @@ namespace packet { class PacketFactory : public core::NonCopyable<> { public: //! Constructor. - PacketFactory(core::IArena& arena); + PacketFactory(core::IPool& pool); //! Create new packet; core::SharedPtr new_packet(); private: - core::SlabPool pool_; + core::IPool& pool_; }; } // namespace packet