From c9182ac68c3ddc937fe32c4e9be4726cf2c5889f Mon Sep 17 00:00:00 2001 From: huanggang <16061206+ganghuang@user.noreply.gitee.com> Date: Thu, 17 Jul 2025 01:56:52 +0000 Subject: [PATCH 1/3] update services/common/ring_buffer/ring_buffer.h. Signed-off-by: huanggang <16061206+ganghuang@user.noreply.gitee.com> --- services/common/ring_buffer/ring_buffer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/common/ring_buffer/ring_buffer.h b/services/common/ring_buffer/ring_buffer.h index 165d8ffe..7f37fa38 100644 --- a/services/common/ring_buffer/ring_buffer.h +++ b/services/common/ring_buffer/ring_buffer.h @@ -52,6 +52,7 @@ private: std::condition_variable notFull_; std::condition_variable notEmpty_; std::mutex notifyMtx_; + std::mutex arrayMtx_; }; } // namespace Updater #endif // __RING_BUFFER_H__ \ No newline at end of file -- Gitee From f0bad5fcf2c83a1b4ef16295b22b876c2ffaf8c6 Mon Sep 17 00:00:00 2001 From: huanggang <16061206+ganghuang@user.noreply.gitee.com> Date: Thu, 17 Jul 2025 01:57:34 +0000 Subject: [PATCH 2/3] update services/common/ring_buffer/ring_buffer.cpp. Signed-off-by: huanggang <16061206+ganghuang@user.noreply.gitee.com> --- services/common/ring_buffer/ring_buffer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/common/ring_buffer/ring_buffer.cpp b/services/common/ring_buffer/ring_buffer.cpp index c7348b99..8b924d40 100644 --- a/services/common/ring_buffer/ring_buffer.cpp +++ b/services/common/ring_buffer/ring_buffer.cpp @@ -127,6 +127,7 @@ bool RingBuffer::Pop(uint8_t *buf, uint32_t maxLen, uint32_t &len) } } + uint32_t index = readIndex_ & (num_ - 1); if (memcpy_s(buf, maxLen, bufArray_[index], lenArray_[index]) != EOK) { LOG(ERROR) << "memcpy error, len:" << lenArray_[index]; -- Gitee From ad54a1e8fb130c86a9c3e30bfafa3f594a5189a2 Mon Sep 17 00:00:00 2001 From: huanggang <16061206+ganghuang@user.noreply.gitee.com> Date: Thu, 17 Jul 2025 02:07:53 +0000 Subject: [PATCH 3/3] update services/common/ring_buffer/ring_buffer.cpp. Signed-off-by: huanggang <16061206+ganghuang@user.noreply.gitee.com> --- services/common/ring_buffer/ring_buffer.cpp | 31 ++++++++++++--------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/services/common/ring_buffer/ring_buffer.cpp b/services/common/ring_buffer/ring_buffer.cpp index 8b924d40..9ec69a03 100644 --- a/services/common/ring_buffer/ring_buffer.cpp +++ b/services/common/ring_buffer/ring_buffer.cpp @@ -96,13 +96,16 @@ bool RingBuffer::Push(uint8_t *buf, uint32_t len) } } - uint32_t index = writeIndex_ & (num_ - 1); - if (memcpy_s(bufArray_[index], singleSize_, buf, len) != EOK) { - LOG(ERROR) << "memcpy error, len:" << len; - return false; + { + std::unique_lock arrayLock(arrayMtx_); + uint32_t index = writeIndex_ & (num_ - 1); + if (memcpy_s(bufArray_[index], singleSize_, buf, len) != EOK) { + LOG(ERROR) << "memcpy error, len:" << len; + return false; + } + lenArray_[index] = len; + writeIndex_ = (writeIndex_ + 1) & (2 * num_ - 1); // 2: logic buffer size } - lenArray_[index] = len; - writeIndex_ = (writeIndex_ + 1) & (2 * num_ - 1); // 2: logic buffer size std::unique_lock popLock(notifyMtx_); notEmpty_.notify_all(); @@ -127,14 +130,16 @@ bool RingBuffer::Pop(uint8_t *buf, uint32_t maxLen, uint32_t &len) } } - - uint32_t index = readIndex_ & (num_ - 1); - if (memcpy_s(buf, maxLen, bufArray_[index], lenArray_[index]) != EOK) { - LOG(ERROR) << "memcpy error, len:" << lenArray_[index]; - return false; + { + std::unique_lock arrayLock(arrayMtx_); + uint32_t index = readIndex_ & (num_ - 1); + if (memcpy_s(buf, maxLen, bufArray_[index], lenArray_[index]) != EOK) { + LOG(ERROR) << "memcpy error, len:" << lenArray_[index]; + return false; + } + len = lenArray_[index]; + readIndex_ = (readIndex_ + 1) & (2 * num_ - 1); // 2: logic buffer size } - len = lenArray_[index]; - readIndex_ = (readIndex_ + 1) & (2 * num_ - 1); // 2: logic buffer size std::unique_lock popLock(notifyMtx_); notFull_.notify_all(); -- Gitee