Commit 813c7189 authored by Pavel Vainerman's avatar Pavel Vainerman

(Modbus): исправил баг приводивший к deadlock. Заодно перевёл

MBExchange на использование rwmutex.
parent bae39000
#!/bin/sh #!/bin/sh
./uniset-start.sh -f "./uniset-admin --confile test.xml --`basename $0 .sh` $1 $2 $3 $4 $5" ./uniset2-start.sh -f "./uniset2-admin --confile test.xml --`basename $0 .sh` $1 $2 $3 $4"
exit $? exit $?
...@@ -2463,7 +2463,6 @@ void MBExchange::sysCommand( const UniSetTypes::SystemMessage *sm ) ...@@ -2463,7 +2463,6 @@ void MBExchange::sysCommand( const UniSetTypes::SystemMessage *sm )
if( !force ) if( !force )
{ {
uniset_mutex_lock l(pollMutex,2000);
force = true; force = true;
poll(); poll();
force = false; force = false;
...@@ -2634,7 +2633,7 @@ void MBExchange::poll() ...@@ -2634,7 +2633,7 @@ void MBExchange::poll()
if( !mb ) if( !mb )
{ {
{ {
uniset_mutex_lock l(pollMutex, 300); uniset_rwmutex_wrlock l(pollMutex);
pollActivated = false; pollActivated = false;
mb = initMB(false); mb = initMB(false);
if( !mb ) if( !mb )
...@@ -2653,7 +2652,7 @@ void MBExchange::poll() ...@@ -2653,7 +2652,7 @@ void MBExchange::poll()
} }
{ {
uniset_mutex_lock l(pollMutex); uniset_rwmutex_wrlock l(pollMutex);
pollActivated = true; pollActivated = true;
ptTimeout.reset(); ptTimeout.reset();
} }
...@@ -2730,7 +2729,7 @@ void MBExchange::poll() ...@@ -2730,7 +2729,7 @@ void MBExchange::poll()
} }
{ {
uniset_mutex_lock l(pollMutex); uniset_rwmutex_wrlock l(pollMutex);
pollActivated = false; pollActivated = false;
} }
...@@ -2754,7 +2753,6 @@ void MBExchange::poll() ...@@ -2754,7 +2753,6 @@ void MBExchange::poll()
if( allNotRespond && ptReopen.checkTime() ) if( allNotRespond && ptReopen.checkTime() )
{ {
uniset_mutex_lock l(pollMutex, 300);
dwarn << myname << ": REOPEN timeout..(" << ptReopen.getInterval() << ")" << endl; dwarn << myname << ": REOPEN timeout..(" << ptReopen.getInterval() << ")" << endl;
mb = initMB(true); mb = initMB(true);
...@@ -2799,7 +2797,7 @@ void MBExchange::updateRespondSensors() ...@@ -2799,7 +2797,7 @@ void MBExchange::updateRespondSensors()
{ {
bool chanTimeout = false; bool chanTimeout = false;
{ {
uniset_mutex_lock l(pollMutex); uniset_rwmutex_rlock l(pollMutex);
chanTimeout = pollActivated && ptTimeout.checkTime(); chanTimeout = pollActivated && ptTimeout.checkTime();
} }
......
...@@ -232,7 +232,7 @@ class MBExchange: ...@@ -232,7 +232,7 @@ class MBExchange:
RTUDeviceMap rmap; RTUDeviceMap rmap;
InitList initRegList; /*!< список регистров для инициализации */ InitList initRegList; /*!< список регистров для инициализации */
UniSetTypes::uniset_mutex pollMutex; UniSetTypes::uniset_rwmutex pollMutex;
virtual ModbusClient* initMB( bool reopen=false )= 0; virtual ModbusClient* initMB( bool reopen=false )= 0;
......
...@@ -138,7 +138,7 @@ void MBTCPMaster::sysCommand( const UniSetTypes::SystemMessage *sm ) ...@@ -138,7 +138,7 @@ void MBTCPMaster::sysCommand( const UniSetTypes::SystemMessage *sm )
void MBTCPMaster::poll_thread() void MBTCPMaster::poll_thread()
{ {
{ {
uniset_mutex_lock l(pollMutex,300); uniset_rwmutex_wrlock l(pollMutex);
ptTimeout.reset(); ptTimeout.reset();
} }
......
...@@ -273,7 +273,7 @@ void MBTCPMultiMaster::sysCommand( const UniSetTypes::SystemMessage *sm ) ...@@ -273,7 +273,7 @@ void MBTCPMultiMaster::sysCommand( const UniSetTypes::SystemMessage *sm )
void MBTCPMultiMaster::poll_thread() void MBTCPMultiMaster::poll_thread()
{ {
{ {
uniset_mutex_lock l(pollMutex,300); uniset_rwmutex_wrlock l(pollMutex);
ptTimeout.reset(); ptTimeout.reset();
} }
......
...@@ -172,7 +172,7 @@ void RTUExchange::poll() ...@@ -172,7 +172,7 @@ void RTUExchange::poll()
if( !mb ) if( !mb )
{ {
{ {
uniset_mutex_lock l(pollMutex, 300); uniset_rwmutex_wrlock l(pollMutex);
pollActivated = false; pollActivated = false;
mb = initMB(false); mb = initMB(false);
if( !mb ) if( !mb )
...@@ -191,7 +191,7 @@ void RTUExchange::poll() ...@@ -191,7 +191,7 @@ void RTUExchange::poll()
} }
{ {
uniset_mutex_lock l(pollMutex,200); uniset_rwmutex_wrlock l(pollMutex);
pollActivated = true; pollActivated = true;
ptTimeout.reset(); ptTimeout.reset();
} }
...@@ -305,7 +305,6 @@ void RTUExchange::poll() ...@@ -305,7 +305,6 @@ void RTUExchange::poll()
if( allNotRespond && ptReopen.checkTime() ) if( allNotRespond && ptReopen.checkTime() )
{ {
uniset_mutex_lock l(pollMutex, 300);
dwarn << myname << ": REOPEN timeout..(" << ptReopen.getInterval() << ")" << endl; dwarn << myname << ": REOPEN timeout..(" << ptReopen.getInterval() << ")" << endl;
mb = initMB(true); mb = initMB(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment