diff --git a/src/core/memory/MemoryPool.h b/src/core/memory/MemoryPool.h index c651ef3..c5da7ea 100644 --- a/src/core/memory/MemoryPool.h +++ b/src/core/memory/MemoryPool.h @@ -59,7 +59,35 @@ public: this->release(*b); delete b; }); - } + BlockPtr allocate(std::size_t requiredSize) + { + if (requiredSize > m_blockSize) { + return {}; + } + + std::size_t slot = 0; + { + std::lock_guard lk(m_mutex); + if (m_freeSlots.empty()) { + return {}; + } + slot = m_freeSlots.front(); + m_freeSlots.pop(); + m_inUse[slot] = true; + } + + auto* raw = new PoolBlock{ + m_storage.data() + slot * m_blockSize, + m_blockSize, + requiredSize, + slot, + }; + return BlockPtr(raw, [this](PoolBlock* b) { + if (!b) return; + this->release(*b); + delete b; + }); + void release(const PoolBlock& block) { diff --git a/src/device_bus/manager/DeviceBusManager.cpp b/src/device_bus/manager/DeviceBusManager.cpp index 09a5e02..997602f 100644 --- a/src/device_bus/manager/DeviceBusManager.cpp +++ b/src/device_bus/manager/DeviceBusManager.cpp @@ -36,6 +36,17 @@ void DeviceBusManager::setDirtyCallback(std::function cb) bool DeviceBusManager::initialize(const QJsonObject& rootConfig) { + // 初始化内存池、pipeline引擎、插件管理器、ingress适配器、egress路由器 + // 内存池是用来存储数据块的 + // pipeline引擎是用来处理数据流的 + // 插件管理器是用来管理插件的 + // ingress适配器是用来将数据推送到 ingress 队列的 + // egress路由器是用来将数据从 ingress 队列中取出并发送给设备的 + // 内存池大小为4096,每个数据块大小为4096 + // pipeline引擎队列大小为4096 + // 插件管理器插件数量为4096 + // ingress适配器队列大小为4096 + // egress路由器队列大小为4096 if (!m_memoryPool) { m_memoryPool = std::make_shared(4096, 4096); } diff --git a/src/message_bus/pipeline/PayloadRef.h b/src/message_bus/pipeline/PayloadRef.h index 167305f..1203e70 100644 --- a/src/message_bus/pipeline/PayloadRef.h +++ b/src/message_bus/pipeline/PayloadRef.h @@ -1,5 +1,5 @@ #pragma once - +// 功能 :定义有效载荷引用 包含数据块、偏移量、长度 #include #include #include diff --git a/src/message_bus/pipeline/PipelineContext.h b/src/message_bus/pipeline/PipelineContext.h index 63e299e..2301125 100644 --- a/src/message_bus/pipeline/PipelineContext.h +++ b/src/message_bus/pipeline/PipelineContext.h @@ -1,5 +1,6 @@ #pragma once +// 定义管道上下文 包含设备ID、端点、时间戳、协议提示、跟踪ID、有效载荷、有效载荷大小 #include #include diff --git a/src/message_bus/pipeline/PipelineEngine.cpp b/src/message_bus/pipeline/PipelineEngine.cpp index d0cdbb1..9c1ae96 100644 --- a/src/message_bus/pipeline/PipelineEngine.cpp +++ b/src/message_bus/pipeline/PipelineEngine.cpp @@ -67,6 +67,7 @@ void PipelineEngine::setPluginManager(std::shared_ptr #include #include