From 570e812442a64360239f558ae4b55c0d204a5523 Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期五, 09 一月 2026 11:57:06 +0800
Subject: [PATCH] 1.继续完善通讯;
---
SourceCode/Bond/Servo/HsmsPassive.cpp | 23 +++++++++++++++++------
1 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/SourceCode/Bond/Servo/HsmsPassive.cpp b/SourceCode/Bond/Servo/HsmsPassive.cpp
index 6208112..20ae2db 100644
--- a/SourceCode/Bond/Servo/HsmsPassive.cpp
+++ b/SourceCode/Bond/Servo/HsmsPassive.cpp
@@ -525,26 +525,37 @@
void CHsmsPassive::setVariableValue(const char* pszName, __int64 value)
{
- auto v = getVariable(pszName);
- if (v != nullptr) {
+ // Protect variable list updates; multiple threads may set SVs.
+ Lock();
+ if (auto v = getVariable(pszName)) {
v->setValue(value);
}
+ Unlock();
}
void CHsmsPassive::setVariableValue(const char* pszName, const char* value)
{
- auto v = getVariable(pszName);
- if (v != nullptr) {
+ Lock();
+ if (auto v = getVariable(pszName)) {
v->setValue(value);
}
+ Unlock();
}
void CHsmsPassive::setVariableValue(const char* pszName, std::vector<SERVO::CVariable>& vars)
{
- auto v = getVariable(pszName);
- if (v != nullptr) {
+ Lock();
+ if (auto v = getVariable(pszName)) {
v->setValue(vars);
}
+ Unlock();
+}
+
+void CHsmsPassive::withVariableLock(const std::function<void()>& fn)
+{
+ Lock();
+ if (fn) fn();
+ Unlock();
}
static bool isValidFormat(const std::string& fmt)
--
Gitblit v1.9.3